Path: blob/master/src/packages/frontend/editors/task-editor/show-toggle.tsx
1691 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/*6Toggle whether or not to show tasks (deleted, done)7*/89import { React, useRef } from "../../app-framework";10import { TaskActions } from "./actions";11import { Checkbox } from "antd";12import { capitalize } from "@cocalc/util/misc";1314interface Props {15actions: TaskActions;16type: "done" | "deleted";17count: number;18show?: boolean;19}2021export const ShowToggle: React.FC<Props> = React.memo(22({ actions, type, count, show }) => {23const last_call_ref = useRef<number>(0);2425function toggle_state() {26// avoid accidental double clicks...27const now = Date.now();28if (now - last_call_ref.current <= 300) {29return;30}31last_call_ref.current = now;3233if (show) {34if (type == "done") actions.stop_showing_done();35else if (type == "deleted") actions.stop_showing_deleted();36} else {37if (count === 0) {38// do nothing39return;40}41if (type == "done") actions.show_done();42else if (type == "deleted") actions.show_deleted();43}44}4546if (actions == null) {47// no support for toggling (e.g., history view)48return null;49}50const color = count > 0 || show ? "#666" : "#999";51return (52<div onClick={toggle_state} style={{ margin: "5px 0 0 15px" }}>53<Checkbox54checked={show}55onClick={toggle_state}56style={{ fontWeight: 350, color }}57>58{capitalize(type)}59</Checkbox>60</div>61);62}63);646566