Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/editors/task-editor/find.tsx
1691 views
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
/*
7
Searching for tasks by full text search and done/deleted status.
8
*/
9
10
import { Input } from "antd";
11
import { CSSProperties } from "react";
12
13
import { useEffect, useRef } from "@cocalc/frontend/app-framework";
14
import { TaskActions } from "./actions";
15
import { EmptyTrash } from "./empty-trash";
16
import { ShowToggle } from "./show-toggle";
17
import { Counts, LocalViewStateMap } from "./types";
18
19
interface Props {
20
actions: TaskActions;
21
local_view_state: LocalViewStateMap;
22
counts?: Counts;
23
focus_find_box?: boolean;
24
style?: CSSProperties;
25
}
26
27
export function Find({
28
actions,
29
local_view_state,
30
counts,
31
focus_find_box,
32
style,
33
}: Props) {
34
const inputRef = useRef<any>(null);
35
useEffect(() => {
36
if (focus_find_box) {
37
inputRef.current?.focus();
38
}
39
}, [focus_find_box]);
40
41
return (
42
<div style={{ display: "flex", marginLeft: "5px", ...style }}>
43
<Input.Search
44
ref={inputRef}
45
allowClear
46
value={local_view_state.get("search") ?? ""}
47
placeholder={"Filter tasks..."}
48
onChange={(e) =>
49
actions.set_local_view_state({
50
search: e.target.value,
51
})
52
}
53
onBlur={() => actions.blur_find_box()}
54
onFocus={() => actions.disable_key_handler()}
55
onKeyDown={(evt) => {
56
if (evt.which === 27) {
57
actions.set_local_view_state({ search: "" });
58
inputRef.current?.blur();
59
actions.enable_key_handler();
60
return false;
61
}
62
}}
63
/>
64
<Toggle
65
type="done"
66
counts={counts}
67
local_view_state={local_view_state}
68
actions={actions}
69
/>
70
<Toggle
71
type="deleted"
72
counts={counts}
73
local_view_state={local_view_state}
74
actions={actions}
75
/>
76
</div>
77
);
78
}
79
80
function Toggle({ type, counts, local_view_state, actions }) {
81
if (counts == null) return null;
82
const count = counts.get(type);
83
const show = local_view_state.get(`show_${type}`);
84
return (
85
<div style={{ padding: "2px 5px", display: "flex" }}>
86
<ShowToggle actions={actions} type={type} show={show} count={count} />
87
{show && type === "deleted" && count > 0 && (
88
<EmptyTrash actions={actions} count={count} />
89
)}
90
</div>
91
);
92
}
93
94