blob: 0d0951ee77eb8e450bc83d6134ad0f3247861f7c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
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<TManageItems> {
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<TManageItems> {
timeline: TimelineInfo;
posts?: TimelinePostInfoEx[] | "forbid";
operations: {
onManage?: (item: TManageItems | "property") => void;
onMember: () => void;
onBookmark?: () => void;
onHighlight?: () => void;
onPost?: TimelinePostSendCallback;
};
}
export interface TimelinePageTemplateUIProps<TManageItems> {
data?: TimelinePageTemplateData<TManageItems> | I18nText;
syncStatus: TimelineSyncStatus;
CardComponent: React.ComponentType<TimelineCardComponentProps<TManageItems>>;
}
export default function TimelinePageTemplateUI<TManageItems>(
props: TimelinePageTemplateUIProps<TManageItems>
): React.ReactElement | null {
const { data, syncStatus, CardComponent } = props;
const { t } = useTranslation();
const [bottomSpaceHeight, setBottomSpaceHeight] = React.useState<number>(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<HTMLDivElement | null>(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<boolean>(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 = <p className="text-danger">{convertI18nText(data, t)}</p>;
} else {
const posts = data?.posts;
body = (
<>
{data != null ? (
<CardComponent
className="timeline-template-card"
timeline={data.timeline}
operations={data.operations}
syncStatus={syncStatus}
collapse={cardCollapse}
toggleCollapse={toggleCardCollapse}
/>
) : null}
{posts != null ? (
posts === "forbid" ? (
<div>{t("timeline.messageCantSee")}</div>
) : (
<div
className="timeline-container"
style={{ minHeight: `calc(100vh - ${56 + bottomSpaceHeight}px)` }}
>
<Timeline containerRef={timelineRef} posts={posts} />
</div>
)
) : (
<div className="full-viewport-center-child">
<Spinner variant="primary" animation="grow" />
</div>
)}
{data != null && data.operations.onPost != null ? (
<>
<div
style={{ height: bottomSpaceHeight }}
className="flex-fix-length"
/>
<TimelinePostEdit
className="fixed-bottom"
onPost={data.operations.onPost}
onHeightChange={onPostEditHeightChange}
timelineUniqueId={data.timeline.uniqueId}
/>
</>
) : null}
</>
);
}
return body;
}
|