import React from "react"; import clsx from "clsx"; import { Link } from "react-router-dom"; import { Trans } from "react-i18next"; 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.PointerEvent) => 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}
{actions != null ? (
) : null} ); return actions == null ? ( {content} ) : (
{content}
); }; export 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, editHandler } = props; const editable = editHandler != null; const [editing, setEditing] = React.useState(false); return (
{title != null &&

{title}

} { editable && (editing ? (
{ setEditing(false); }} > Done
) : (
{ setEditing(true); }} > Edit
)) // TODO: i18n }
{(() => { if (timelines === "loading") { return (
); } else if (timelines === "offline") { return ( ); } else { return timelines.map((timeline) => { return ( { //TODO: Implement this. }, onMove: () => { //TODO: Implement this. }, } : undefined } /> ); }); } })()}
); }; export interface TimelineBoardProps { title?: string; className?: string; load: () => Promise; editHandler?: { onDelete: (timeline: string) => Promise; }; } const TimelineBoard: React.FC = ({ className, title, load, editHandler, }) => { const [timelines, setTimelines] = React.useState< TimelineInfo[] | "offline" | "loading" >("loading"); React.useEffect(() => { let subscribe = true; if (timelines === "loading") { void load().then( (timelines) => { if (subscribe) { setTimelines(timelines); } }, () => { setTimelines("offline"); } ); } return () => { subscribe = false; }; }, [load, timelines]); return ( { setTimelines("loading"); }} editHandler={editHandler} /> ); }; export default TimelineBoard;