From a40565ddae8785cb1000f28cfea7b127c1dcdf70 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 24 Dec 2020 17:14:06 +0800 Subject: ... --- FrontEnd/src/app/views/home/TimelineBoard.tsx | 89 ++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 16 deletions(-) (limited to 'FrontEnd/src') diff --git a/FrontEnd/src/app/views/home/TimelineBoard.tsx b/FrontEnd/src/app/views/home/TimelineBoard.tsx index ae7783e6..87ed98e1 100644 --- a/FrontEnd/src/app/views/home/TimelineBoard.tsx +++ b/FrontEnd/src/app/views/home/TimelineBoard.tsx @@ -7,20 +7,90 @@ import { Spinner } from "react-bootstrap"; import { TimelineInfo } from "@/services/timeline"; import TimelineLogo from "../common/TimelineLogo"; import UserTimelineLogo from "../common/UserTimelineLogo"; +import { HttpTimelineInfo } from "@/http/timeline"; + +interface TimelineBoardItemProps { + timeline: HttpTimelineInfo; + // If not null, will disable navigation on click. + actions?: { + onDelete: () => void; + onMove: (e: React.MouseEvent) => void; + }; +} + +const TimelineBoardItem: React.FC = ({ + timeline, + actions, +}) => { + const { name, title } = timeline; + const isPersonal = name.startsWith("@"); + const url = isPersonal + ? `/users/${timeline.owner.username}` + : `/timelines/${name}`; + + const content = ( + <> + {isPersonal ? ( + + ) : ( + + )} + {title} + {name} + + ); + + return actions == null ? ( + + {content} + + ) : ( +
{content}
+ ); +}; interface TimelineBoardUIProps { title?: string; timelines: TimelineInfo[] | "offline" | "loading"; onReload: () => void; className?: string; + editHandler?: { + onDelete: (timeline: string) => Promise; + }; } const TimelineBoardUI: React.FC = (props) => { - const { title, timelines, className } = props; + const { title, timelines, className, editHandler } = props; + + const editable = editHandler != null; + + const [editing, setEditing] = React.useState(false); return (
- {title != null &&

{title}

} +
+ {title != null &&

{title}

} + { + editable && + (editing ? ( +
{ + setEditing(false); + }} + > + Done +
+ ) : ( +
{ + setEditing(true); + }} + > + Edit +
+ )) // TODO: i18n + } +
{(() => { if (timelines === "loading") { return ( @@ -48,21 +118,8 @@ const TimelineBoardUI: React.FC = (props) => { ); } else { return timelines.map((timeline) => { - const { name, title } = timeline; - const isPersonal = name.startsWith("@"); - const url = isPersonal - ? `/users/${timeline.owner.username}` - : `/timelines/${name}`; return ( - - {isPersonal ? ( - - ) : ( - - )} - {title} - {name} - + ); }); } -- cgit v1.2.3