blob: 233c81bdf3faa5e44c4571e8abe412caa4d1ad81 (
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
151
152
153
154
155
156
157
158
159
160
161
|
import React from "react";
import clsx from "clsx";
import { Link } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { Modal, Button } from "react-bootstrap";
import { useAvatar } from "@/services/user";
import { TimelinePostInfo } from "@/services/timeline";
import BlobImage from "../common/BlobImage";
const TimelinePostDeleteConfirmDialog: React.FC<{
onClose: () => void;
onConfirm: () => void;
}> = ({ onClose, onConfirm }) => {
const { t } = useTranslation();
return (
<Modal onHide={onClose} show centered>
<Modal.Header>
<Modal.Title className="text-danger">
{t("timeline.post.deleteDialog.title")}
</Modal.Title>
</Modal.Header>
<Modal.Body>{t("timeline.post.deleteDialog.prompt")}</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={onClose}>
{t("operationDialog.cancel")}
</Button>
<Button
variant="danger"
onClick={() => {
onConfirm();
onClose();
}}
>
{t("operationDialog.confirm")}
</Button>
</Modal.Footer>
</Modal>
);
};
export interface TimelineItemProps {
post: TimelinePostInfo;
current?: boolean;
more?: {
isOpen: boolean;
toggle: () => void;
onDelete: () => void;
};
onClick?: () => void;
onResize?: () => void;
className?: string;
style?: React.CSSProperties;
}
const TimelineItem: React.FC<TimelineItemProps> = (props) => {
const { i18n } = useTranslation();
const current = props.current === true;
const { more, onResize } = props;
const avatar = useAvatar(props.post.author.username);
const [deleteDialog, setDeleteDialog] = React.useState<boolean>(false);
return (
<div
className={clsx(
"timeline-item position-relative",
current && "current",
props.className
)}
onClick={props.onClick}
style={props.style}
>
<div className="timeline-line-area-container">
<div className="timeline-line-area">
<div className="timeline-line-segment start"></div>
<div className="timeline-line-node-container">
<div className="timeline-line-node"></div>
</div>
<div className="timeline-line-segment end"></div>
{current && <div className="timeline-line-segment current-end" />}
</div>
</div>
<div className="timeline-item-card">
<div>
<span className="mr-2">
<small className="text-secondary white-space-no-wrap mr-2">
{props.post.time.toLocaleString(i18n.languages)}
</small>
<small className="text-dark">{props.post.author.nickname}</small>
</span>
{more != null ? (
<i
className="bi-chevron-down text-info icon-button"
onClick={(e) => {
more.toggle();
e.stopPropagation();
}}
/>
) : null}
</div>
<div className="timeline-content">
<Link
className="float-left m-2"
to={"/users/" + props.post.author.username}
>
<BlobImage
onLoad={onResize}
blob={avatar}
className="avatar rounded"
/>
</Link>
{(() => {
const { content } = props.post;
if (content.type === "text") {
return content.text;
} else {
return (
<BlobImage
onLoad={onResize}
blob={content.data}
className="timeline-content-image"
/>
);
}
})()}
</div>
{more != null && more.isOpen ? (
<div
className="position-absolute position-lt w-100 h-100 mask d-flex justify-content-center align-items-center"
onClick={more.toggle}
>
<i
className="bi-trash text-danger icon-button large"
onClick={(e) => {
setDeleteDialog(true);
e.stopPropagation();
}}
/>
</div>
) : null}
</div>
{deleteDialog && more != null ? (
<TimelinePostDeleteConfirmDialog
onClose={() => {
setDeleteDialog(false);
more.toggle();
}}
onConfirm={more.onDelete}
/>
) : null}
</div>
);
};
export default TimelineItem;
|