Skip to content

Commit fddee81

Browse files
committed
make search also work for tasks
1 parent 1789a18 commit fddee81

File tree

10 files changed

+280
-156
lines changed

10 files changed

+280
-156
lines changed

src/packages/frontend/editors/task-editor/actions.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ import {
3434
TaskMap,
3535
TaskState,
3636
} from "./types";
37-
import { TaskStore } from "./store";
3837
import { SyncDB } from "@cocalc/sync/editor/db";
3938
import { webapp_client } from "../../webapp-client";
40-
import type { Actions as TaskFrameActions } from "@cocalc/frontend/frame-editors/task-editor/actions";
39+
import type {
40+
Actions as TaskFrameActions,
41+
Store as TaskStore,
42+
} from "@cocalc/frontend/frame-editors/task-editor/actions";
4143
import Fragment from "@cocalc/frontend/misc/fragment-id";
4244

4345
const LAST_EDITED_THRESH_S = 30;
@@ -48,7 +50,7 @@ export class TaskActions extends Actions<TaskState> {
4850
private project_id: string;
4951
private path: string;
5052
private truePath: string;
51-
private store: TaskStore;
53+
public store: TaskStore;
5254
_update_visible: Function;
5355
private is_closed: boolean = false;
5456
private key_handler?: (any) => void;
@@ -663,7 +665,6 @@ export class TaskActions extends Actions<TaskState> {
663665
}
664666

665667
public blur_find_box(): void {
666-
this.enable_key_handler();
667668
this.setFrameData({ focus_find_box: false });
668669
}
669670

src/packages/frontend/editors/task-editor/editor.tsx

Lines changed: 106 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ Top-level react component for task list
99

1010
import { Button } from "antd";
1111
import { fromJS } from "immutable";
12-
1312
import { Col, Row } from "@cocalc/frontend/antd-bootstrap";
14-
import { React, useEditorRedux } from "@cocalc/frontend/app-framework";
13+
import { useEditorRedux } from "@cocalc/frontend/app-framework";
1514
import { Loading } from "@cocalc/frontend/components";
1615
import { Icon } from "@cocalc/frontend/components/icon";
1716
import { TaskActions } from "./actions";
@@ -31,111 +30,115 @@ interface Props {
3130
read_only?: boolean;
3231
}
3332

34-
export const TaskEditor: React.FC<Props> = React.memo(
35-
({ actions, path, project_id, desc, read_only }) => {
36-
const useEditor = useEditorRedux<TaskState>({ project_id, path });
37-
const tasks = useEditor("tasks");
38-
const visible = desc.get("data-visible");
39-
const local_task_state = desc.get("data-local_task_state") ?? fromJS({});
40-
const local_view_state = desc.get("data-local_view_state") ?? fromJS({});
41-
const hashtags = desc.get("data-hashtags");
42-
const current_task_id = desc.get("data-current_task_id");
43-
const counts = desc.get("data-counts");
44-
const search_terms = desc.get("data-search_terms");
45-
const search_desc = desc.get("data-search_desc");
46-
const focus_find_box = desc.get("data-focus_find_box");
33+
export function TaskEditor({
34+
actions,
35+
path,
36+
project_id,
37+
desc,
38+
read_only,
39+
}: Props) {
40+
const useEditor = useEditorRedux<TaskState>({ project_id, path });
41+
const tasks = useEditor("tasks");
42+
const visible = desc.get("data-visible");
43+
const local_task_state = desc.get("data-local_task_state") ?? fromJS({});
44+
const local_view_state = desc.get("data-local_view_state") ?? fromJS({});
45+
const hashtags = desc.get("data-hashtags");
46+
const current_task_id = desc.get("data-current_task_id");
47+
const counts = desc.get("data-counts");
48+
const search_terms = desc.get("data-search_terms");
49+
const search_desc = desc.get("data-search_desc");
50+
const focus_find_box = desc.get("data-focus_find_box");
4751

48-
if (tasks == null || visible == null) {
49-
return (
50-
<div
52+
if (tasks == null || visible == null) {
53+
return (
54+
<div
55+
style={{
56+
fontSize: "40px",
57+
textAlign: "center",
58+
padding: "15px",
59+
color: "#999",
60+
}}
61+
>
62+
<Loading />
63+
</div>
64+
);
65+
}
66+
67+
return (
68+
<div className={"smc-vfill"}>
69+
<Row>
70+
<Col md={7} style={{ display: "flex", marginTop: "5px" }}>
71+
<Button
72+
style={{ marginLeft: "5px" }}
73+
onClick={() => {
74+
actions.new_task();
75+
}}
76+
>
77+
<Icon name="plus-circle" /> New Task
78+
</Button>
79+
<Find
80+
style={{ flex: 1 }}
81+
actions={actions}
82+
local_view_state={local_view_state}
83+
counts={counts}
84+
focus_find_box={focus_find_box}
85+
/>
86+
</Col>
87+
<Col md={5}>
88+
<DescVisible
89+
num_visible={visible?.size}
90+
num_tasks={tasks?.size}
91+
local_view_state={local_view_state}
92+
search_desc={search_desc}
93+
/>
94+
</Col>
95+
</Row>
96+
<Row>
97+
<Col md={12}>
98+
{hashtags != null && (
99+
<HashtagBar
100+
actions={actions}
101+
hashtags={hashtags}
102+
selected_hashtags={local_view_state.get("selected_hashtags")}
103+
/>
104+
)}
105+
</Col>
106+
</Row>
107+
<Headings actions={actions} sort={local_view_state.get("sort")} />
108+
<div style={{ paddingTop: "5px" }} />
109+
{visible.size == 0 ? (
110+
<a
111+
onClick={actions.new_task}
51112
style={{
52113
fontSize: "40px",
53114
textAlign: "center",
54115
padding: "15px",
55-
color: "#999",
56116
}}
57117
>
58-
<Loading />
59-
</div>
60-
);
61-
}
62-
63-
return (
64-
<div className={"smc-vfill"}>
65-
<Row>
66-
<Col md={7} style={{ display: "flex", marginTop: "5px" }}>
67-
<Button
68-
style={{ marginLeft: "5px" }}
69-
onClick={() => {
70-
actions.new_task();
71-
}}
72-
>
73-
<Icon name="plus-circle" /> New Task
74-
</Button>
75-
<Find
76-
style={{ flex: 1 }}
77-
actions={actions}
78-
local_view_state={local_view_state}
79-
counts={counts}
80-
focus_find_box={focus_find_box}
81-
/>
82-
</Col>
83-
<Col md={5}>
84-
<DescVisible
85-
num_visible={visible?.size}
86-
num_tasks={tasks?.size}
87-
local_view_state={local_view_state}
88-
search_desc={search_desc}
89-
/>
90-
</Col>
91-
</Row>
92-
<Row>
93-
<Col md={12}>
94-
{hashtags != null && (
95-
<HashtagBar
96-
actions={actions}
97-
hashtags={hashtags}
98-
selected_hashtags={local_view_state.get("selected_hashtags")}
99-
/>
100-
)}
101-
</Col>
102-
</Row>
103-
<Headings actions={actions} sort={local_view_state.get("sort")} />
104-
<div style={{ paddingTop: "5px" }} />
105-
{visible.size == 0 ? (
106-
<a
107-
onClick={actions.new_task}
108-
style={{
109-
fontSize: "40px",
110-
textAlign: "center",
111-
padding: "15px",
112-
}}
113-
>
114-
Create a task...
115-
</a>
116-
) : (
117-
<TaskList
118-
actions={actions}
119-
path={path}
120-
project_id={project_id}
121-
tasks={tasks}
122-
visible={visible}
123-
current_task_id={current_task_id}
124-
local_task_state={local_task_state}
125-
scrollState={(local_view_state as any).get("scrollState")?.toJS?.()}
126-
font_size={desc.get("font_size")}
127-
sortable={
128-
!read_only &&
129-
is_sortable(
130-
local_view_state.getIn(["sort", "column"]) ?? HEADINGS[0]
131-
)
132-
}
133-
read_only={read_only}
134-
selected_hashtags={local_view_state.get("selected_hashtags")}
135-
search_terms={search_terms}
136-
/>
137-
)}
138-
</div>
139-
);
140-
}
141-
);
118+
Create a task...
119+
</a>
120+
) : (
121+
<TaskList
122+
actions={actions}
123+
path={path}
124+
project_id={project_id}
125+
tasks={tasks}
126+
visible={visible}
127+
current_task_id={current_task_id}
128+
local_task_state={local_task_state}
129+
scrollState={(local_view_state as any).get("scrollState")?.toJS?.()}
130+
font_size={desc.get("font_size")}
131+
sortable={
132+
!read_only &&
133+
is_sortable(
134+
local_view_state.getIn(["sort", "column"]) ?? HEADINGS[0],
135+
)
136+
}
137+
read_only={read_only}
138+
selected_hashtags={local_view_state.get("selected_hashtags")}
139+
search_terms={search_terms}
140+
/>
141+
)}
142+
</div>
143+
);
144+
}

src/packages/frontend/editors/task-editor/find.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function Find({
4444
ref={inputRef}
4545
allowClear
4646
value={local_view_state.get("search") ?? ""}
47-
placeholder={"Search for tasks..."}
47+
placeholder={"Filter tasks..."}
4848
onChange={(e) =>
4949
actions.set_local_view_state({
5050
search: e.target.value,
@@ -56,6 +56,7 @@ export function Find({
5656
if (evt.which === 27) {
5757
actions.set_local_view_state({ search: "" });
5858
inputRef.current?.blur();
59+
actions.enable_key_handler();
5960
return false;
6061
}
6162
}}

src/packages/frontend/editors/task-editor/store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
*/
55

66
import { Store } from "../../app-framework";
7-
import { TaskState } from "./types";
7+
import type { TaskState } from "./types";
88

99
export class TaskStore extends Store<TaskState> {}

src/packages/frontend/editors/task-editor/task.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ export default function Task({
9999
return (
100100
<Grid
101101
style={style}
102-
onClick={() => actions?.set_current_task(task.get("task_id"))}
102+
onClick={() => {
103+
actions?.set_current_task(task.get("task_id"));
104+
actions?.enable_key_handler();
105+
}}
103106
>
104107
<Row>
105108
<Col sm={1}>

src/packages/frontend/frame-editors/chat-editor/search.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@ function Preview({ id, content }) {
1717
);
1818
}
1919

20-
export const search = createSearchEditor({ Preview });
20+
export const search = createSearchEditor({
21+
Preview,
22+
updateField: "messages",
23+
title: "Chatroom",
24+
});

0 commit comments

Comments
 (0)