From d7a216295c2b4dcd7e931c38edd25e1b7ef7a395 Mon Sep 17 00:00:00 2001
From: crupest <crupest@outlook.com>
Date: Tue, 15 Jun 2021 22:17:47 +0800
Subject: ...

---
 .../views/timeline-common/TimelinePageTemplate.tsx | 85 +++-------------------
 1 file changed, 11 insertions(+), 74 deletions(-)

(limited to 'FrontEnd/src/views/timeline-common/TimelinePageTemplate.tsx')

diff --git a/FrontEnd/src/views/timeline-common/TimelinePageTemplate.tsx b/FrontEnd/src/views/timeline-common/TimelinePageTemplate.tsx
index 9b9ebbc2..4a56346a 100644
--- a/FrontEnd/src/views/timeline-common/TimelinePageTemplate.tsx
+++ b/FrontEnd/src/views/timeline-common/TimelinePageTemplate.tsx
@@ -1,19 +1,15 @@
 import React from "react";
-import { useTranslation } from "react-i18next";
 import { Container } from "react-bootstrap";
 import { HubConnectionState } from "@microsoft/signalr";
 
-import { HttpNetworkError, HttpNotFoundError } from "@/http/common";
-import { getHttpTimelineClient, HttpTimelineInfo } from "@/http/timeline";
-
-import { getAlertHost } from "@/services/alert";
-
-import Timeline from "./Timeline";
-import TimelinePostEdit from "./TimelinePostEdit";
+import { HttpTimelineInfo } from "@/http/timeline";
 
 import useReverseScrollPositionRemember from "@/utilities/useReverseScrollPositionRemember";
+
 import { generatePalette, setPalette } from "@/palette";
 
+import Timeline from "./Timeline";
+
 export interface TimelinePageCardProps {
   timeline: HttpTimelineInfo;
   collapse: boolean;
@@ -34,11 +30,6 @@ export interface TimelinePageTemplateProps {
 const TimelinePageTemplate: React.FC<TimelinePageTemplateProps> = (props) => {
   const { timelineName, reloadKey, onReload, CardComponent } = props;
 
-  const { t } = useTranslation();
-
-  const [state, setState] = React.useState<
-    "loading" | "done" | "offline" | "notexist" | "error"
-  >("loading");
   const [timeline, setTimeline] = React.useState<HttpTimelineInfo | null>(null);
 
   const [connectionStatus, setConnectionStatus] =
@@ -46,53 +37,12 @@ const TimelinePageTemplate: React.FC<TimelinePageTemplateProps> = (props) => {
 
   useReverseScrollPositionRemember();
 
-  React.useEffect(() => {
-    setState("loading");
-    setTimeline(null);
-  }, [timelineName]);
-
-  React.useEffect(() => {
-    let subscribe = true;
-    void getHttpTimelineClient()
-      .getTimeline(timelineName)
-      .then(
-        (data) => {
-          if (subscribe) {
-            setState("done");
-            setTimeline(data);
-          }
-        },
-        (error) => {
-          if (subscribe) {
-            if (error instanceof HttpNetworkError) {
-              setState("offline");
-            } else if (error instanceof HttpNotFoundError) {
-              setState("notexist");
-            } else {
-              console.error(error);
-              setState("error");
-            }
-            setTimeline(null);
-          }
-        }
-      );
-    return () => {
-      subscribe = false;
-    };
-  }, [timelineName, reloadKey]);
-
   React.useEffect(() => {
     if (timeline != null && timeline.color != null) {
       return setPalette(generatePalette({ primary: timeline.color }));
     }
   }, [timeline]);
 
-  const [timelineReloadKey, setTimelineReloadKey] = React.useState<number>(0);
-
-  const reloadTimeline = (): void => {
-    setTimelineReloadKey((old) => old + 1);
-  };
-
   const cardCollapseLocalStorageKey = `timeline.${timelineName}.cardCollapse`;
 
   const [cardCollapse, setCardCollapse] = React.useState<boolean>(true);
@@ -126,26 +76,13 @@ const TimelinePageTemplate: React.FC<TimelinePageTemplateProps> = (props) => {
         />
       ) : null}
       <Container className="px-0">
-        {(() => {
-          if (state === "offline") {
-            // TODO: i18n
-            return <p className="text-danger">Offline!</p>;
-          } else if (state === "notexist") {
-            return <p className="text-danger">{t(props.notFoundI18nKey)}</p>;
-          } else if (state === "error") {
-            // TODO: i18n
-            return <p className="text-danger">Error!</p>;
-          } else {
-            return (
-              <Timeline
-                timelineName={timeline?.name}
-                reloadKey={timelineReloadKey}
-                onReload={reloadTimeline}
-                onConnectionStateChanged={setConnectionStatus}
-              />
-            );
-          }
-        })()}
+        <Timeline
+          timelineName={timelineName}
+          reloadKey={reloadKey}
+          onReload={onReload}
+          onTimelineLoaded={(t) => setTimeline(t)}
+          onConnectionStateChanged={setConnectionStatus}
+        />
       </Container>
     </>
   );
-- 
cgit v1.2.3

