Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/editors/task-editor/show-toggle.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
Toggle whether or not to show tasks (deleted, done)
8
*/
9
10
import { React, useRef } from "../../app-framework";
11
import { TaskActions } from "./actions";
12
import { Checkbox } from "antd";
13
import { capitalize } from "@cocalc/util/misc";
14
15
interface Props {
16
actions: TaskActions;
17
type: "done" | "deleted";
18
count: number;
19
show?: boolean;
20
}
21
22
export const ShowToggle: React.FC<Props> = React.memo(
23
({ actions, type, count, show }) => {
24
const last_call_ref = useRef<number>(0);
25
26
function toggle_state() {
27
// avoid accidental double clicks...
28
const now = Date.now();
29
if (now - last_call_ref.current <= 300) {
30
return;
31
}
32
last_call_ref.current = now;
33
34
if (show) {
35
if (type == "done") actions.stop_showing_done();
36
else if (type == "deleted") actions.stop_showing_deleted();
37
} else {
38
if (count === 0) {
39
// do nothing
40
return;
41
}
42
if (type == "done") actions.show_done();
43
else if (type == "deleted") actions.show_deleted();
44
}
45
}
46
47
if (actions == null) {
48
// no support for toggling (e.g., history view)
49
return null;
50
}
51
const color = count > 0 || show ? "#666" : "#999";
52
return (
53
<div onClick={toggle_state} style={{ margin: "5px 0 0 15px" }}>
54
<Checkbox
55
checked={show}
56
onClick={toggle_state}
57
style={{ fontWeight: 350, color }}
58
>
59
{capitalize(type)}
60
</Checkbox>
61
</div>
62
);
63
}
64
);
65
66