diff options
author | crupest <crupest@outlook.com> | 2021-04-04 22:49:06 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-04-04 22:49:06 +0800 |
commit | b8f829736e4ebe571ecc72d8c3157fe56668a469 (patch) | |
tree | 80d556eb5d7012a4826df6b237861c0eaab4598c /FrontEnd/src/app/views/timeline-common/Timeline.tsx | |
parent | 6b71f05f5fc4b8df6e16fc33f482ccfcc3d9bb0b (diff) | |
download | timeline-b8f829736e4ebe571ecc72d8c3157fe56668a469.tar.gz timeline-b8f829736e4ebe571ecc72d8c3157fe56668a469.tar.bz2 timeline-b8f829736e4ebe571ecc72d8c3157fe56668a469.zip |
...
Diffstat (limited to 'FrontEnd/src/app/views/timeline-common/Timeline.tsx')
-rw-r--r-- | FrontEnd/src/app/views/timeline-common/Timeline.tsx | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/FrontEnd/src/app/views/timeline-common/Timeline.tsx b/FrontEnd/src/app/views/timeline-common/Timeline.tsx index cbe58300..f2c38aeb 100644 --- a/FrontEnd/src/app/views/timeline-common/Timeline.tsx +++ b/FrontEnd/src/app/views/timeline-common/Timeline.tsx @@ -31,17 +31,14 @@ const Timeline: React.FC<TimelineProps> = (props) => { onLoad, } = props; - const [posts, setPosts] = React.useState< - | HttpTimelinePostInfo[] - | "loading" - | "offline" - | "notexist" - | "forbid" - | "error" + const [state, setState] = React.useState< + "loading" | "loaded" | "offline" | "notexist" | "forbid" | "error" >("loading"); + const [posts, setPosts] = React.useState<HttpTimelinePostInfo[]>([]); React.useEffect(() => { - setPosts("loading"); + setState("loading"); + setPosts([]); }, [timelineName]); React.useEffect(() => { @@ -51,18 +48,21 @@ const Timeline: React.FC<TimelineProps> = (props) => { .listPost(timelineName) .then( (data) => { - if (subscribe) setPosts(data); + if (subscribe) { + setState("loaded"); + setPosts(data); + } }, (error) => { if (error instanceof HttpNetworkError) { - setPosts("offline"); + setState("offline"); } else if (error instanceof HttpForbiddenError) { - setPosts("forbid"); + setState("forbid"); } else if (error instanceof HttpNotFoundError) { - setPosts("notexist"); + setState("notexist"); } else { console.error(error); - setPosts("error"); + setState("error"); } } ); @@ -78,7 +78,7 @@ const Timeline: React.FC<TimelineProps> = (props) => { } }, [posts, onLoad]); - switch (posts) { + switch (state) { case "loading": return ( <div> |