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"; interface TimelineBoardUIProps { title?: string; timelines: TimelineInfo[] | "offline" | "loading"; onReload: () => void; className?: string; } const TimelineBoardUI: React.FC = (props) => { const { title, timelines, className } = props; return (
{title != null &&

{title}

} {(() => { if (timelines === "loading") { return (
); } else if (timelines === "offline") { return (
0 { props.onReload(); e.preventDefault(); }} > 1 2
); } 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} ); }); } })()}
); }; export interface TimelineBoardProps { title?: string; className?: string; load: () => Promise; } const TimelineBoard: React.FC = ({ className, title, load, }) => { 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"); }} /> ); }; export default TimelineBoard;