From 9c0053cd70593bf6add0eab4dbb91a8479d56821 Mon Sep 17 00:00:00 2001 From: crupest Date: Fri, 16 Apr 2021 17:03:40 +0800 Subject: ... --- FrontEnd/src/app/views/home-v2/index.tsx | 47 ++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'FrontEnd/src/app/views/home-v2/index.tsx') diff --git a/FrontEnd/src/app/views/home-v2/index.tsx b/FrontEnd/src/app/views/home-v2/index.tsx index 75c51540..cb3c1428 100644 --- a/FrontEnd/src/app/views/home-v2/index.tsx +++ b/FrontEnd/src/app/views/home-v2/index.tsx @@ -8,6 +8,14 @@ import SearchInput from "../common/SearchInput"; import TimelineListView from "./TimelineListView"; import TimelineCreateDialog from "../home/TimelineCreateDialog"; +import { HttpTimelineInfo } from "@/http/timeline"; +import { getHttpHighlightClient } from "@/http/highlight"; + +const highlightTimelineMessageMap = { + loading: "home.loadingHighlightTimelines", + done: "home.loadedHighlightTimelines", + error: "home.errorHighlightTimelines", +} as const; const HomeV2: React.FC = () => { const history = useHistory(); @@ -20,11 +28,43 @@ const HomeV2: React.FC = () => { const [dialog, setDialog] = React.useState<"create" | null>(null); + const [highlightTimelineState, setHighlightTimelineState] = React.useState< + "loading" | "done" | "error" + >("loading"); + const [highlightTimelines, setHighlightTimelines] = React.useState< + HttpTimelineInfo[] | undefined + >(); + + React.useEffect(() => { + if (highlightTimelineState === "loading") { + let subscribe = true; + void getHttpHighlightClient() + .list() + .then( + (data) => { + if (subscribe) { + setHighlightTimelineState("done"); + setHighlightTimelines(data); + } + }, + () => { + if (subscribe) { + setHighlightTimelineState("error"); + setHighlightTimelines(undefined); + } + } + ); + return () => { + subscribe = false; + }; + } + }, [highlightTimelineState]); + return ( <> - + { /> - + {dialog === "create" && ( setDialog(null)} /> -- cgit v1.2.3