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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
import * as React from "react";
import { useTranslation } from "react-i18next";
import classnames from "classnames";
import { HubConnectionState } from "@microsoft/signalr";
import { useIsSmallScreen } from "@/utilities/hooks";
import { timelineVisibilityTooltipTranslationMap } from "@/services/timeline";
import { useUser } from "@/services/user";
import { pushAlert } from "@/services/alert";
import { HttpTimelineInfo } from "@/http/timeline";
import { getHttpBookmarkClient } from "@/http/bookmark";
import UserAvatar from "@/views/common/user/UserAvatar";
import PopupMenu from "@/views/common/menu/PopupMenu";
import FullPageDialog from "@/views/common/dialog/FullPageDialog";
import Card from "@/views/common/Card";
import TimelineDeleteDialog from "./TimelineDeleteDialog";
import ConnectionStatusBadge from "./ConnectionStatusBadge";
import CollapseButton from "./CollapseButton";
import { TimelineMemberDialog } from "./TimelineMember";
import TimelinePropertyChangeDialog from "./TimelinePropertyChangeDialog";
import IconButton from "@/views/common/button/IconButton";
export interface TimelinePageCardProps {
timeline: HttpTimelineInfo;
connectionStatus: HubConnectionState;
className?: string;
onReload: () => void;
}
const TimelineCard: React.FC<TimelinePageCardProps> = (props) => {
const { timeline, connectionStatus, onReload, className } = props;
const { t } = useTranslation();
const [dialog, setDialog] = React.useState<
"member" | "property" | "delete" | null
>(null);
const [collapse, setCollapse] = React.useState(true);
const toggleCollapse = (): void => {
setCollapse((o) => !o);
};
const isSmallScreen = useIsSmallScreen();
const user = useUser();
const content = (
<>
<h3 className="cru-color-primary d-inline-block align-middle">
{timeline.title}
<small className="ms-3 cru-color-secondary">{timeline.nameV2}</small>
</h3>
<div>
<UserAvatar
username={timeline.owner.username}
className="cru-avatar small cru-round me-3"
/>
{timeline.owner.nickname}
<small className="ms-3 cru-color-secondary">
@{timeline.owner.username}
</small>
</div>
<p className="mb-0">{timeline.description}</p>
<small className="mt-1 d-block">
{t(timelineVisibilityTooltipTranslationMap[timeline.visibility])}
</small>
<div className="mt-2 cru-text-end">
{user != null ? (
<IconButton
icon={timeline.isBookmark ? "bookmark-fill" : "bookmark"}
className="me-3"
onClick={() => {
getHttpBookmarkClient()
[timeline.isBookmark ? "delete" : "post"](
user.username,
timeline.owner.username,
timeline.nameV2,
)
.then(onReload, () => {
pushAlert({
message: timeline.isBookmark
? "timeline.removeBookmarkFail"
: "timeline.addBookmarkFail",
type: "danger",
});
});
}}
/>
) : null}
<IconButton
icon="people"
className="me-3"
onClick={() => setDialog("member")}
/>
{timeline.manageable ? (
<PopupMenu
items={[
{
type: "button",
text: "timeline.manageItem.property",
onClick: () => setDialog("property"),
},
{ type: "divider" },
{
type: "button",
onClick: () => setDialog("delete"),
color: "danger",
text: "timeline.manageItem.delete",
},
]}
containerClassName="d-inline"
>
<IconButton icon="three-dots-vertical" />
</PopupMenu>
) : null}
</div>
</>
);
return (
<>
<Card className={classnames("p-2 cru-clearfix", className)}>
<div
className={classnames(
"cru-float-right d-flex align-items-center",
!collapse && "ms-3",
)}
>
<ConnectionStatusBadge status={connectionStatus} className="me-2" />
<CollapseButton collapse={collapse} onClick={toggleCollapse} />
</div>
{isSmallScreen ? (
<FullPageDialog
onBack={toggleCollapse}
show={!collapse}
contentContainerClassName="p-2"
>
{content}
</FullPageDialog>
) : (
<div style={{ display: collapse ? "none" : "inline" }}>{content}</div>
)}
</Card>
<TimelineMemberDialog
timeline={timeline}
onClose={() => setDialog(null)}
open={dialog === "member"}
onChange={onReload}
/>
<TimelinePropertyChangeDialog
timeline={timeline}
close={() => setDialog(null)}
open={dialog === "property"}
onChange={onReload}
/>
<TimelineDeleteDialog
timeline={timeline}
open={dialog === "delete"}
close={() => setDialog(null)}
/>
</>
);
};
export default TimelineCard;
|