Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/editors/task-editor/editor.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
Top-level react component for task list
8
*/
9
10
import { Button } from "antd";
11
import { fromJS } from "immutable";
12
import { Col, Row } from "@cocalc/frontend/antd-bootstrap";
13
import { useEditorRedux } from "@cocalc/frontend/app-framework";
14
import { Loading } from "@cocalc/frontend/components";
15
import { Icon } from "@cocalc/frontend/components/icon";
16
import { TaskActions } from "./actions";
17
import { DescVisible } from "./desc-visible";
18
import { Find } from "./find";
19
import { HashtagBar } from "./hashtag-bar";
20
import { Headings } from "./headings";
21
import { HEADINGS, is_sortable } from "./headings-info";
22
import TaskList from "./list";
23
import { TaskState } from "./types";
24
25
interface Props {
26
actions: TaskActions;
27
path: string;
28
project_id: string;
29
desc;
30
read_only?: boolean;
31
}
32
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");
51
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}
112
style={{
113
fontSize: "40px",
114
textAlign: "center",
115
padding: "15px",
116
}}
117
>
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
}
145
146