Path: blob/master/src/packages/frontend/editors/task-editor/task.tsx
1691 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/*6A single task7*/89import { CSSProperties } from "react";10import { Grid, Row, Col } from "../../antd-bootstrap";11import { MinToggle } from "./min-toggle";12import { Description } from "./desc";13import { Changed } from "./changed";14import { DueDate } from "./due";15import { DragHandle } from "./drag";16import { DoneCheckbox } from "./done";17import { header_part } from "./desc-rendering";18import { TaskMap } from "./types";19import { TaskActions } from "./actions";20import { avatar_fontcolor } from "@cocalc/frontend/account/avatar/font-color";21import {22CODE_FOCUSED_COLOR,23FOCUSED_COLOR,24} from "@cocalc/frontend/editors/slate/util";2526interface Props {27actions?: TaskActions;28project_id?: string;29path?: string;30task: TaskMap;31is_current: boolean;32editing_due_date: boolean;33editing_desc: boolean;34font_size: number;35sortable?: boolean;36read_only?: boolean;37selectedHashtags: Set<string>;38searchWords?: string[];39}4041export default function Task({42actions,43path,44project_id,45task,46is_current,47editing_due_date,48editing_desc,49font_size,50sortable,51read_only,52selectedHashtags,53searchWords,54}: Props) {55const style = {56margin: "2px 5px",57paddingTop: "5px",58background: "white",59borderRadius: "8px",60} as CSSProperties;61if (editing_desc) {62style.border = `2px solid ${CODE_FOCUSED_COLOR}`;63style.borderLeft = `10px solid ${CODE_FOCUSED_COLOR}`;64} else if (is_current) {65style.border = `2px solid ${FOCUSED_COLOR}`;66style.borderLeft = `10px solid ${FOCUSED_COLOR}`;67} else {68style.border = "2px solid #ddd";69style.borderTop = "2px solid #eeejj";70style.borderLeft = `10px solid #ddd`;71}72if (task.get("deleted")) {73style.background = "#d9534f";74style.color = "#fff";75} else if (task.get("done")) {76style.color = "#888";77}78if (font_size != null) {79style.fontSize = `${font_size}px`;80}8182const desc = task.get("desc") ?? "";83let min_toggle;84if (editing_desc) {85// while editing no min toggle86min_toggle = false;87} else {88// not editing, so maybe a min toggle...89min_toggle = header_part(desc) !== desc.trim();90}9192const color = task.get("color");93if (color) {94style.background = color;95style.color = avatar_fontcolor(color);96}9798return (99<Grid100style={style}101onClick={() => {102actions?.set_current_task(task.get("task_id"));103actions?.enable_key_handler();104}}105>106<Row>107<Col sm={1}>108{actions != null && (109<DragHandle sortable={sortable} id={task.get("task_id")} />110)}111{actions != null && (112<MinToggle113actions={actions}114task_id={task.get("task_id")}115hideBody={task.get("hideBody")}116has_body={min_toggle}117/>118)}119</Col>120<Col sm={8}>121<Description122actions={actions}123path={path}124project_id={project_id}125task_id={task.get("task_id")}126desc={task.get("desc") ?? ""}127color={color}128editing={editing_desc}129is_current={is_current}130isDeleted={task.get("deleted")}131font_size={font_size}132read_only={read_only}133selectedHashtags={selectedHashtags}134searchWords={searchWords}135hideBody={task.get("hideBody")}136/>137</Col>138<Col sm={1}>139{" "}140<span style={{ fontSize: "10pt", color: "#666" }}>141<DueDate142actions={actions}143read_only={read_only}144task_id={task.get("task_id")}145due_date={task.get("due_date")}146editing={editing_due_date}147is_done={!!task.get("done")}148/>149</span>150</Col>151<Col sm={1}>152<span style={{ fontSize: "10pt", color: "#666" }}>153<Changed last_edited={task.get("last_edited")} />154</span>155</Col>156<Col sm={1} style={{ textAlign: "center" }}>157<DoneCheckbox158actions={actions}159read_only={read_only}160done={!!task.get("done")}161task_id={task.get("task_id")}162/>163</Col>164</Row>165</Grid>166);167}168169170