From a5deeea162433c52a3b07c20b34831522ee01acb Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 19 Jan 2021 16:20:42 +0800 Subject: ... --- .../timeline-common/TimelinePageTemplateUI.tsx | 88 ++++++++++++---------- 1 file changed, 50 insertions(+), 38 deletions(-) (limited to 'FrontEnd/src/app/views/timeline-common/TimelinePageTemplateUI.tsx') diff --git a/FrontEnd/src/app/views/timeline-common/TimelinePageTemplateUI.tsx b/FrontEnd/src/app/views/timeline-common/TimelinePageTemplateUI.tsx index 0d0951ee..815906d3 100644 --- a/FrontEnd/src/app/views/timeline-common/TimelinePageTemplateUI.tsx +++ b/FrontEnd/src/app/views/timeline-common/TimelinePageTemplateUI.tsx @@ -3,10 +3,9 @@ import { useTranslation } from "react-i18next"; import { Spinner } from "react-bootstrap"; import { getAlertHost } from "@/services/alert"; -import { I18nText, convertI18nText } from "@/common"; -import { TimelineInfo } from "@/services/timeline"; +import { TimelineInfo, TimelinePostInfo } from "@/services/timeline"; -import Timeline, { TimelinePostInfoEx } from "./Timeline"; +import Timeline from "./Timeline"; import TimelinePostEdit, { TimelinePostSendCallback } from "./TimelinePostEdit"; import { TimelineSyncStatus } from "./SyncStatusBadge"; @@ -24,28 +23,32 @@ export interface TimelineCardComponentProps { className?: string; } -export interface TimelinePageTemplateData { - timeline: TimelineInfo; - posts?: TimelinePostInfoEx[] | "forbid"; - operations: { - onManage?: (item: TManageItems | "property") => void; - onMember: () => void; - onBookmark?: () => void; - onHighlight?: () => void; - onPost?: TimelinePostSendCallback; - }; +export interface TimelinePageTemplateUIOperations { + onDeletePost: (post: TimelinePostInfo) => void; + onManage?: (item: TManageItems | "property") => void; + onMember: () => void; + onBookmark?: () => void; + onHighlight?: () => void; + onPost?: TimelinePostSendCallback; } export interface TimelinePageTemplateUIProps { - data?: TimelinePageTemplateData | I18nText; + timeline?: + | (TimelineInfo & { + operations: TimelinePageTemplateUIOperations; + posts?: TimelinePostInfo[] | "forbid"; + }) + | "notexist" + | "offline"; syncStatus: TimelineSyncStatus; + notExistMessageI18nKey: string; CardComponent: React.ComponentType>; } export default function TimelinePageTemplateUI( props: TimelinePageTemplateUIProps ): React.ReactElement | null { - const { data, syncStatus, CardComponent } = props; + const { timeline, syncStatus, CardComponent } = props; const { t } = useTranslation(); @@ -66,10 +69,7 @@ export default function TimelinePageTemplateUI( } }, []); - const timelineRef = React.useRef(null); - - const timelineName: string | null = - typeof data === "object" && "timeline" in data ? data.timeline.name : null; + const timelineName = typeof timeline === "object" ? timeline.name : null; const cardCollapseLocalStorageKey = timelineName != null ? `timeline.${timelineName}.cardCollapse` : null; @@ -96,32 +96,44 @@ export default function TimelinePageTemplateUI( let body: React.ReactElement; - if (data != null && (typeof data === "string" || "type" in data)) { - body =

{convertI18nText(data, t)}

; + if (timeline == null) { + body = ( +
+ +
+ ); + } else if (timeline === "offline") { + // TODO: i18n + body =

Offline!

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

{t(props.notExistMessageI18nKey)}

; } else { - const posts = data?.posts; - + const { operations, posts } = timeline; body = ( <> - {data != null ? ( - - ) : null} + {posts != null ? ( posts === "forbid" ? (
{t("timeline.messageCantSee")}
) : (
- +
) ) : ( @@ -129,7 +141,7 @@ export default function TimelinePageTemplateUI( )} - {data != null && data.operations.onPost != null ? ( + {operations.onPost != null ? ( <>
( /> ) : null} -- cgit v1.2.3