From b8f829736e4ebe571ecc72d8c3157fe56668a469 Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 4 Apr 2021 22:49:06 +0800 Subject: ... --- .../src/app/views/timeline-common/Timeline.tsx | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'FrontEnd/src/app/views/timeline-common/Timeline.tsx') 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 = (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([]); React.useEffect(() => { - setPosts("loading"); + setState("loading"); + setPosts([]); }, [timelineName]); React.useEffect(() => { @@ -51,18 +48,21 @@ const Timeline: React.FC = (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 = (props) => { } }, [posts, onLoad]); - switch (posts) { + switch (state) { case "loading": return (
-- cgit v1.2.3