aboutsummaryrefslogtreecommitdiff
path: root/FrontEnd/src/views/timeline-common/TimelinePageTemplate.tsx
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-06-15 22:17:47 +0800
committercrupest <crupest@outlook.com>2021-06-15 22:17:47 +0800
commitd7a216295c2b4dcd7e931c38edd25e1b7ef7a395 (patch)
tree52f48b7ea15ba5e3a96298e51633292487e75795 /FrontEnd/src/views/timeline-common/TimelinePageTemplate.tsx
parentc94784c9693648c2376d1aeaeae379ddc0036a32 (diff)
downloadtimeline-d7a216295c2b4dcd7e931c38edd25e1b7ef7a395.tar.gz
timeline-d7a216295c2b4dcd7e931c38edd25e1b7ef7a395.tar.bz2
timeline-d7a216295c2b4dcd7e931c38edd25e1b7ef7a395.zip
...
Diffstat (limited to 'FrontEnd/src/views/timeline-common/TimelinePageTemplate.tsx')
-rw-r--r--FrontEnd/src/views/timeline-common/TimelinePageTemplate.tsx85
1 files changed, 11 insertions, 74 deletions
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] =
@@ -47,52 +38,11 @@ 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>
</>
);