From 2300b6ed25600c7c1f01ef44f7390e82119644a8 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 15 Apr 2021 16:30:24 +0800 Subject: ... --- .../views/timeline-common/TimelinePageTemplate.tsx | 116 ++++++++++----------- 1 file changed, 56 insertions(+), 60 deletions(-) (limited to 'FrontEnd/src/app/views/timeline-common/TimelinePageTemplate.tsx') diff --git a/FrontEnd/src/app/views/timeline-common/TimelinePageTemplate.tsx b/FrontEnd/src/app/views/timeline-common/TimelinePageTemplate.tsx index 5cde014b..5b6dfa9c 100644 --- a/FrontEnd/src/app/views/timeline-common/TimelinePageTemplate.tsx +++ b/FrontEnd/src/app/views/timeline-common/TimelinePageTemplate.tsx @@ -1,6 +1,6 @@ import React from "react"; import { useTranslation } from "react-i18next"; -import { Container, Spinner } from "react-bootstrap"; +import { Container } from "react-bootstrap"; import { HttpNetworkError, HttpNotFoundError } from "@/http/common"; import { getHttpTimelineClient, HttpTimelineInfo } from "@/http/timeline"; @@ -33,14 +33,16 @@ const TimelinePageTemplate: React.FC = (props) => { const { t } = useTranslation(); - const [timeline, setTimeline] = React.useState< - HttpTimelineInfo | "loading" | "offline" | "notexist" | "error" + const [state, setState] = React.useState< + "loading" | "done" | "offline" | "notexist" | "error" >("loading"); + const [timeline, setTimeline] = React.useState(null); useReverseScrollPositionRemember(); React.useEffect(() => { - setTimeline("loading"); + setState("loading"); + setTimeline(null); }, [timelineName]); React.useEffect(() => { @@ -50,19 +52,21 @@ const TimelinePageTemplate: React.FC = (props) => { .then( (data) => { if (subscribe) { + setState("done"); setTimeline(data); } }, (error) => { if (subscribe) { if (error instanceof HttpNetworkError) { - setTimeline("offline"); + setState("offline"); } else if (error instanceof HttpNotFoundError) { - setTimeline("notexist"); + setState("notexist"); } else { console.error(error); - setTimeline("error"); + setState("error"); } + setTimeline(null); } } ); @@ -71,10 +75,6 @@ const TimelinePageTemplate: React.FC = (props) => { }; }, [timelineName, reloadKey]); - const scrollToBottom = React.useCallback(() => { - window.scrollTo(0, document.body.scrollHeight); - }, []); - const [bottomSpaceHeight, setBottomSpaceHeight] = React.useState(0); const [timelineReloadKey, setTimelineReloadKey] = React.useState(0); @@ -116,25 +116,9 @@ const TimelinePageTemplate: React.FC = (props) => { ); }; - let body: React.ReactElement; - - if (timeline == "loading") { - body = ( -
- -
- ); - } else if (timeline === "offline") { - // TODO: i18n - body =

Offline!

; - } else if (timeline === "notexist") { - body =

{t(props.notFoundI18nKey)}

; - } else if (timeline === "error") { - // TODO: i18n - body =

Error!

; - } else { - body = ( - <> + return ( + <> + {timeline != null ? ( = (props) => { toggleCollapse={toggleCardCollapse} onReload={onReload} /> - - + {(() => { + if (state === "offline") { + // TODO: i18n + return

Offline!

; + } else if (state === "notexist") { + return

{t(props.notFoundI18nKey)}

; + } else if (state === "error") { + // TODO: i18n + return

Error!

; + } else { + return ( + + ); + } + })()} +
+ {timeline != null && timeline.postable ? ( + <> +
- - {timeline.postable ? ( - <> -
- - - ) : null} - - ); - } - return body; + + + ) : null} + + ); }; export default TimelinePageTemplate; -- cgit v1.2.3