Path: blob/master/src/packages/frontend/editors/task-editor/desc-rendered.tsx
1691 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/*6Rendered view of the description of a single task7*/89import { React } from "../../app-framework";10import MostlyStaticMarkdown from "@cocalc/frontend/editors/slate/mostly-static-markdown";11import { header_part } from "./desc-rendering";12import { TaskActions } from "./actions";13import { MAX_HEIGHT } from "./constants";1415interface Props {16actions?: TaskActions;17task_id: string;18desc: string;19read_only?: boolean;20selectedHashtags?: Set<string>;21searchWords?: string[];22is_current?: boolean;23hideBody?: boolean;24}2526export const DescriptionRendered: React.FC<Props> = React.memo(27({28actions,29task_id,30desc,31read_only,32selectedHashtags,33searchWords,34is_current,35hideBody,36}) => {37function render_content() {38let value = desc;39if (!value.trim()) {40return <span style={{ color: "#666" }}>Description...</span>;41}42let show_more_link: boolean;43if (hideBody) {44let header = header_part(value);45show_more_link =46!!is_current && actions != null && header.trim() != value.trim();47value = header;48} else {49show_more_link = false;50}51return (52<>53<MostlyStaticMarkdown54value={value}55searchWords={searchWords}56onChange={57actions != null58? (value) => {59actions.set_desc(task_id, value, true);60}61: undefined62}63selectedHashtags={selectedHashtags}64toggleHashtag={65selectedHashtags != null && actions != null66? (tag) =>67actions.set_hashtag_state(68tag,69selectedHashtags.has(tag) ? undefined : 1,70)71: undefined72}73/>74{show_more_link && (75<a onClick={() => actions?.toggleHideBody(task_id)}>Show more...</a>76)}77</>78);79}8081function on_click(e) {82const data = e.target != null ? e.target.dataset : undefined;83if (data == null) {84return;85}86if (data.checkbox != null) {87e.stopPropagation();88actions?.toggle_desc_checkbox(89task_id,90parseInt(data.index),91data.checkbox === "true",92);93} else if (data.hashtag != null) {94let new_state;95e.stopPropagation();96const state = { undefined: undefined, "1": 1, "-1": -1 }[data.state]; // do not use eval -- safer97if (state === 1 || state === -1) {98// for now negation doesn't go through clicking99new_state = undefined;100} else {101new_state = 1;102}103actions?.set_hashtag_state(data.hashtag, new_state);104}105}106107return (108<div109style={{ paddingTop: "5px", maxHeight: MAX_HEIGHT, overflow: "auto" }}110onClick={!read_only && actions != null ? on_click : undefined}111className="cocalc-task-description"112>113{render_content()}114</div>115);116},117);118119120