import React from "react"; import { useTranslation } from "react-i18next"; import { Spinner } from "react-bootstrap"; import { getAlertHost } from "@/services/alert"; import { TimelineInfo, TimelinePostInfo } from "@/services/timeline"; import Timeline 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 TimelinePageTemplateUIOperations { onDeletePost: (post: TimelinePostInfo) => void; onManage?: (item: TManageItems | "property") => void; onMember: () => void; onBookmark?: () => void; onHighlight?: () => void; onPost?: TimelinePostSendCallback; } export interface TimelinePageTemplateUIProps { 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 { timeline, 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 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 == null) { body = (
); } else if (timeline === "offline") { // TODO: i18n body =

Offline!

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

{t(props.notExistMessageI18nKey)}

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