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