import React from "react"; 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 Timeline, { TimelinePostInfoEx } from "./Timeline"; import TimelinePostEdit, { TimelinePostSendCallback } from "./TimelinePostEdit"; import { TimelineSyncStatus } from "./SyncStatusBadge"; export interface TimelineCardComponentProps { timeline: TimelineInfo; syncStatus: TimelineSyncStatus; operations: { onManage?: (item: TManageItems | "property") => void; onMember: () => void; onBookmark?: () => void; onHighlight?: () => void; }; collapse: boolean; toggleCollapse: () => void; 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 TimelinePageTemplateUIProps { data?: TimelinePageTemplateData | I18nText; syncStatus: TimelineSyncStatus; CardComponent: React.ComponentType>; } export default function TimelinePageTemplateUI( props: TimelinePageTemplateUIProps ): React.ReactElement | null { const { data, syncStatus, CardComponent } = props; const { t } = useTranslation(); const [bottomSpaceHeight, setBottomSpaceHeight] = React.useState(0); const onPostEditHeightChange = React.useCallback((height: number): void => { setBottomSpaceHeight(height); if (height === 0) { const alertHost = getAlertHost(); if (alertHost != null) { alertHost.style.removeProperty("margin-bottom"); } } else { const alertHost = getAlertHost(); if (alertHost != null) { alertHost.style.marginBottom = `${height}px`; } } }, []); const timelineRef = React.useRef(null); const timelineName: string | null = typeof data === "object" && "timeline" in data ? data.timeline.name : null; const cardCollapseLocalStorageKey = timelineName != null ? `timeline.${timelineName}.cardCollapse` : null; const [cardCollapse, setCardCollapse] = React.useState(true); React.useEffect(() => { if (cardCollapseLocalStorageKey != null) { const savedCollapse = window.localStorage.getItem(cardCollapseLocalStorageKey) === "true"; setCardCollapse(savedCollapse); } }, [cardCollapseLocalStorageKey]); const toggleCardCollapse = (): void => { const newState = !cardCollapse; setCardCollapse(newState); if (cardCollapseLocalStorageKey != null) { window.localStorage.setItem( cardCollapseLocalStorageKey, newState.toString() ); } }; let body: React.ReactElement; if (data != null && (typeof data === "string" || "type" in data)) { body =

{convertI18nText(data, t)}

; } else { const posts = data?.posts; body = ( <> {data != null ? ( ) : null} {posts != null ? ( posts === "forbid" ? (
{t("timeline.messageCantSee")}
) : (
) ) : (
)} {data != null && data.operations.onPost != null ? ( <>
) : null} ); } return body; }