import React from "react"; import { useTranslation } from "react-i18next"; import { Spinner } from "react-bootstrap"; import { getAlertHost } from "@/services/alert"; import { HttpTimelineInfo } from "@/http/timeline"; import Timeline from "./Timeline"; import TimelinePostEdit from "./TimelinePostEdit"; export interface TimelineCardComponentProps { timeline: HttpTimelineInfo; operations: { onManage?: (item: TManageItems | "property") => void; onMember: () => void; }; collapse: boolean; toggleCollapse: () => void; className?: string; } export interface TimelinePageTemplateUIOperations { onManage?: (item: TManageItems | "property") => void; onMember: () => void; onBookmark?: () => void; onHighlight?: () => void; } export interface TimelinePageTemplateUIProps { timeline: | (HttpTimelineInfo & { operations: TimelinePageTemplateUIOperations; }) | "notexist" | "offline" | "loading" | "error"; notExistMessageI18nKey: string; CardComponent: React.ComponentType>; } export default function TimelinePageTemplateUI( props: TimelinePageTemplateUIProps ): React.ReactElement | null { const { timeline, CardComponent } = props; const { t } = useTranslation(); const [bottomSpaceHeight, setBottomSpaceHeight] = React.useState(0); const [timelineReloadKey, setTimelineReloadKey] = React.useState(0); const reloadTimeline = (): void => setTimelineReloadKey((old) => old + 1); 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 timelineName = typeof timeline === "object" ? 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 (timeline == "loading") { body = (
); } else if (timeline === "offline") { // TODO: i18n body =

Offline!

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

{t(props.notExistMessageI18nKey)}

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

Error!

; } else { const { operations } = timeline; body = ( <>
{timeline.postable ? ( <>
) : null} ); } return body; }