Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/editors/task-editor/desc.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
Task description:
8
9
- displays description as markdown
10
- allows for changing it
11
*/
12
13
import { Button, Popconfirm, Tooltip } from "antd";
14
import { React } from "../../app-framework";
15
import { Icon } from "../../components";
16
import { DescriptionRendered } from "./desc-rendered";
17
import DescriptionEditor from "./desc-editor";
18
import { TaskActions } from "./actions";
19
20
interface Props {
21
actions?: TaskActions;
22
path?: string;
23
project_id?: string;
24
task_id: string;
25
desc: string;
26
color?: string;
27
editing: boolean;
28
is_current: boolean;
29
font_size: number;
30
read_only?: boolean;
31
selectedHashtags: Set<string>;
32
searchWords?: string[];
33
hideBody?: boolean;
34
isDeleted?: boolean;
35
}
36
37
export const Description: React.FC<Props> = React.memo(
38
({
39
actions,
40
path,
41
project_id,
42
task_id,
43
desc,
44
color,
45
editing,
46
is_current,
47
font_size,
48
read_only,
49
selectedHashtags,
50
searchWords,
51
hideBody,
52
isDeleted,
53
}) => {
54
function edit() {
55
actions?.edit_desc(task_id);
56
}
57
58
function render_editor() {
59
if (!editing || actions == null || project_id == null || path == null) {
60
return;
61
}
62
return (
63
<div style={{ marginBottom: "5px" }}>
64
<DescriptionEditor
65
actions={actions}
66
task_id={task_id}
67
desc={desc}
68
color={color}
69
font_size={font_size}
70
/>
71
</div>
72
);
73
}
74
75
function render_desc() {
76
if (editing) {
77
return <></>;
78
}
79
return (
80
<div onDoubleClick={edit} style={{ fontSize: font_size }}>
81
<DescriptionRendered
82
actions={actions}
83
task_id={task_id}
84
desc={desc}
85
read_only={read_only}
86
selectedHashtags={selectedHashtags}
87
searchWords={searchWords}
88
is_current={is_current}
89
hideBody={hideBody}
90
/>
91
</div>
92
);
93
}
94
95
function render_edit_button() {
96
if (!is_current || editing) {
97
return;
98
}
99
if (isDeleted)
100
return (
101
<Button
102
size="small"
103
key="delete"
104
disabled={read_only}
105
onClick={() => actions?.undelete_task(task_id)}
106
>
107
<Icon name="trash" /> Undelete
108
</Button>
109
);
110
111
return (
112
<Button.Group>
113
<Tooltip title="Edit this task (double click or enter key)">
114
<Button size="small" type="link" onClick={edit}>
115
<Icon name={"edit"} /> Edit
116
</Button>
117
</Tooltip>
118
<Popconfirm
119
title="Delete Task?"
120
onConfirm={() => actions?.delete_task(task_id)}
121
>
122
<Button size="small" type="link" key="delete" disabled={read_only}>
123
<Icon name="trash" /> Delete
124
</Button>
125
</Popconfirm>
126
</Button.Group>
127
);
128
}
129
130
if (read_only || actions == null) {
131
return render_desc();
132
}
133
return (
134
<div>
135
{render_editor()}
136
<div
137
style={{
138
position: "absolute",
139
right: "25px",
140
bottom: "-10px",
141
background: "white",
142
zIndex: 1,
143
}}
144
>
145
{render_edit_button()}
146
</div>
147
{render_desc()}
148
</div>
149
);
150
},
151
);
152
153