blob: a5b6d04aa551cee81ecb57483195393e46a6890b (
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
|
import React from "react";
import clsx from "clsx";
import { Link } from "react-router-dom";
import { TimelinePostInfo } from "@/services/timeline";
import BlobImage from "../common/BlobImage";
import UserAvatar from "../common/user/UserAvatar";
import TimelineLine from "./TimelineLine";
import TimelinePostDeleteConfirmDialog from "./TimelinePostDeleteConfirmDialog";
export interface TimelineItemProps {
post: TimelinePostInfo;
current?: boolean;
more?: {
isOpen: boolean;
toggle: () => void;
onDelete: () => void;
};
onClick?: () => void;
className?: string;
style?: React.CSSProperties;
}
const TimelineItem: React.FC<TimelineItemProps> = (props) => {
const current = props.current === true;
const { post, more } = props;
const [deleteDialog, setDeleteDialog] = React.useState<boolean>(false);
return (
<div
className={clsx("timeline-item", current && "current", props.className)}
onClick={props.onClick}
style={props.style}
>
<TimelineLine center="node" current={current} />
<div className="timeline-item-card">
{more != null ? (
<i
className="bi-chevron-down text-info icon-button float-right"
onClick={(e) => {
more.toggle();
e.stopPropagation();
}}
/>
) : null}
<div className="timeline-item-header">
<span className="mr-2">
<span>
<Link to={"/users/" + props.post.author.username}>
<UserAvatar
username={post.author.username}
className="timeline-avatar mr-1"
/>
</Link>
<small className="text-dark mr-2">{post.author.nickname}</small>
<small className="text-secondary white-space-no-wrap">
{post.time.toLocaleTimeString()}
</small>
</span>
</span>
</div>
<div className="timeline-content">
{(() => {
const { content } = post;
if (content.type === "text") {
return content.text;
} else {
return (
<BlobImage
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;
|