diff options
author | crupest <crupest@outlook.com> | 2021-04-15 16:30:24 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-04-15 16:30:24 +0800 |
commit | 3bfc6012eb2b66ce33e85440e24a595c677dd842 (patch) | |
tree | 9dfda1935d59641deaf76464cf16f3f520e26b1c /FrontEnd/src/app/views/timeline-common/Timeline.tsx | |
parent | 7bd88329608cf3b88784be87e5b501a04e0b342a (diff) | |
download | timeline-3bfc6012eb2b66ce33e85440e24a595c677dd842.tar.gz timeline-3bfc6012eb2b66ce33e85440e24a595c677dd842.tar.bz2 timeline-3bfc6012eb2b66ce33e85440e24a595c677dd842.zip |
...
Diffstat (limited to 'FrontEnd/src/app/views/timeline-common/Timeline.tsx')
-rw-r--r-- | FrontEnd/src/app/views/timeline-common/Timeline.tsx | 77 |
1 files changed, 31 insertions, 46 deletions
diff --git a/FrontEnd/src/app/views/timeline-common/Timeline.tsx b/FrontEnd/src/app/views/timeline-common/Timeline.tsx index 60fbc45c..72d38ffd 100644 --- a/FrontEnd/src/app/views/timeline-common/Timeline.tsx +++ b/FrontEnd/src/app/views/timeline-common/Timeline.tsx @@ -9,18 +9,18 @@ import { getHttpTimelineClient, HttpTimelinePostInfo } from "@/http/timeline"; import TimelinePagedPostListView from "./TimelinePagedPostListView"; import TimelineTop from "./TimelineTop"; +import TimelineLoading from "./TimelineLoading"; export interface TimelineProps { className?: string; style?: React.CSSProperties; - timelineName: string; + timelineName?: string; reloadKey: number; onReload: () => void; - onLoad?: () => void; } const Timeline: React.FC<TimelineProps> = (props) => { - const { timelineName, className, style, reloadKey, onReload, onLoad } = props; + const { timelineName, className, style, reloadKey, onReload } = props; const [state, setState] = React.useState< "loading" | "loaded" | "offline" | "notexist" | "forbid" | "error" @@ -33,56 +33,41 @@ const Timeline: React.FC<TimelineProps> = (props) => { }, [timelineName]); React.useEffect(() => { - let subscribe = true; + if (timelineName != null) { + let subscribe = true; - void getHttpTimelineClient() - .listPost(timelineName) - .then( - (data) => { - if (subscribe) { - setState("loaded"); - setPosts(data); + void getHttpTimelineClient() + .listPost(timelineName) + .then( + (data) => { + if (subscribe) { + setState("loaded"); + setPosts(data); + } + }, + (error) => { + if (error instanceof HttpNetworkError) { + setState("offline"); + } else if (error instanceof HttpForbiddenError) { + setState("forbid"); + } else if (error instanceof HttpNotFoundError) { + setState("notexist"); + } else { + console.error(error); + setState("error"); + } } - }, - (error) => { - if (error instanceof HttpNetworkError) { - setState("offline"); - } else if (error instanceof HttpForbiddenError) { - setState("forbid"); - } else if (error instanceof HttpNotFoundError) { - setState("notexist"); - } else { - console.error(error); - setState("error"); - } - } - ); + ); - return () => { - subscribe = false; - }; - }, [timelineName, reloadKey]); - - React.useEffect(() => { - if (state === "loaded") { - onLoad?.(); + return () => { + subscribe = false; + }; } - }, [state, onLoad]); + }, [timelineName, reloadKey]); switch (state) { case "loading": - return ( - <> - <TimelineTop - className="timeline-top-loading-enter" - height={100} - lineProps={{ - center: "loading", - startSegmentLength: 56, - }} - /> - </> - ); + return <TimelineLoading />; case "offline": return ( <div className={className} style={style}> |