Path: blob/master/src/packages/frontend/editors/task-editor/desc.tsx
1691 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/*6Task description:78- displays description as markdown9- allows for changing it10*/1112import { Button, Popconfirm, Tooltip } from "antd";13import { React } from "../../app-framework";14import { Icon } from "../../components";15import { DescriptionRendered } from "./desc-rendered";16import DescriptionEditor from "./desc-editor";17import { TaskActions } from "./actions";1819interface Props {20actions?: TaskActions;21path?: string;22project_id?: string;23task_id: string;24desc: string;25color?: string;26editing: boolean;27is_current: boolean;28font_size: number;29read_only?: boolean;30selectedHashtags: Set<string>;31searchWords?: string[];32hideBody?: boolean;33isDeleted?: boolean;34}3536export const Description: React.FC<Props> = React.memo(37({38actions,39path,40project_id,41task_id,42desc,43color,44editing,45is_current,46font_size,47read_only,48selectedHashtags,49searchWords,50hideBody,51isDeleted,52}) => {53function edit() {54actions?.edit_desc(task_id);55}5657function render_editor() {58if (!editing || actions == null || project_id == null || path == null) {59return;60}61return (62<div style={{ marginBottom: "5px" }}>63<DescriptionEditor64actions={actions}65task_id={task_id}66desc={desc}67color={color}68font_size={font_size}69/>70</div>71);72}7374function render_desc() {75if (editing) {76return <></>;77}78return (79<div onDoubleClick={edit} style={{ fontSize: font_size }}>80<DescriptionRendered81actions={actions}82task_id={task_id}83desc={desc}84read_only={read_only}85selectedHashtags={selectedHashtags}86searchWords={searchWords}87is_current={is_current}88hideBody={hideBody}89/>90</div>91);92}9394function render_edit_button() {95if (!is_current || editing) {96return;97}98if (isDeleted)99return (100<Button101size="small"102key="delete"103disabled={read_only}104onClick={() => actions?.undelete_task(task_id)}105>106<Icon name="trash" /> Undelete107</Button>108);109110return (111<Button.Group>112<Tooltip title="Edit this task (double click or enter key)">113<Button size="small" type="link" onClick={edit}>114<Icon name={"edit"} /> Edit115</Button>116</Tooltip>117<Popconfirm118title="Delete Task?"119onConfirm={() => actions?.delete_task(task_id)}120>121<Button size="small" type="link" key="delete" disabled={read_only}>122<Icon name="trash" /> Delete123</Button>124</Popconfirm>125</Button.Group>126);127}128129if (read_only || actions == null) {130return render_desc();131}132return (133<div>134{render_editor()}135<div136style={{137position: "absolute",138right: "25px",139bottom: "-10px",140background: "white",141zIndex: 1,142}}143>144{render_edit_button()}145</div>146{render_desc()}147</div>148);149},150);151152153