Path: blob/master/src/packages/frontend/editors/task-editor/headings.tsx
1691 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/*6Headings of the task list:78- Custom9- Due10- Changed11*/1213import { Row, Col } from "../../antd-bootstrap";14import { React } from "../../app-framework";15import { Icon, Gap } from "../../components";1617import { HEADINGS, HEADINGS_DIR } from "./headings-info";18import { TaskActions } from "./actions";19import { Headings as ColumnHeadings, HeadingsDir, Sort } from "./types";2021const NEXT_DIR = {22asc: "desc", // since @props.dir is defined, heading is currently selected23desc: "asc", // heading currently selected24undefined: "asc", // this heading is not selected, so make it selected and asc25} as const;2627interface HeadingProps {28actions: TaskActions;29heading: ColumnHeadings;30dir?: HeadingsDir;31}3233const Heading: React.FC<HeadingProps> = React.memo(34({ actions, heading, dir }) => {35return (36<a37onClick={() => actions.set_sort_column(heading, NEXT_DIR[`${dir}`])}38style={{ cursor: "pointer" }}39>40{heading}41{dir != null && (42<span>43<Gap />44{dir == "asc" ? (45<Icon name="caret-down" />46) : (47<Icon name="caret-up" />48)}49</span>50)}51</a>52);53}54);5556interface HeadingsProps {57actions: TaskActions;58sort: Sort;59}60export const Headings: React.FC<HeadingsProps> = React.memo(61({ actions, sort }) => {62function render_heading(heading, dir) {63return (64<Heading actions={actions} key={heading} heading={heading} dir={dir} />65);66}6768function render_headings() {69const column = sort?.get("column") ?? HEADINGS[0];70const dir = sort?.get("dir") ?? HEADINGS_DIR[0];71// NOTE: we use xs below so that the HEADING columns never wordwrap on72// skinny screens, since they are really important for being73// able to control the order. On the other hand, if they wrap,74// then they use a LOT of vertical space, which is at an extreme75// premium for task lists... See76// https://github.com/sagemathinc/cocalc/issues/430577// We hide the done column though since it overlaps and we can't78// sort by that.79return (80<Row style={{ borderBottom: "1px solid lightgray", marginLeft: "8px" }}>81<Col xs={1} style={{ color: "#666" }}>82Drag83</Col>84<Col xs={7} style={{ color: "#666" }}>85Description86</Col>87<Col xs={1}>88{render_heading(89HEADINGS[0],90column === HEADINGS[0] ? dir : undefined91)}92</Col>93<Col xs={1}>94{render_heading(95HEADINGS[1],96column === HEADINGS[1] ? dir : undefined97)}98</Col>99<Col xs={1}>100{render_heading(101HEADINGS[2],102column === HEADINGS[2] ? dir : undefined103)}104</Col>105<Col106xs={1}107style={{ color: "#666", textAlign: "center" }}108className={"visible-sm-inline visible-md-inline visible-lg-inline"}109>110Done111</Col>112</Row>113);114}115116return <div style={{ padding: "0 10px" }}>{render_headings()}</div>;117}118);119120121