blob: 3591b6f993db611bb619002bdfd7fea1ce56f8c6 (
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
|
import React from "react";
import clsx from "clsx";
import {
Dropdown,
DropdownToggle,
DropdownMenu,
DropdownItem,
Button,
} from "reactstrap";
import { useTranslation } from "react-i18next";
import { fromEvent } from "rxjs";
import { useAvatar } from "../data/user";
import { timelineVisibilityTooltipTranslationMap } from "../data/timeline";
import { TimelineCardComponentProps } from "./TimelinePageTemplateUI";
import BlobImage from "../common/BlobImage";
export type OrdinaryTimelineManageItem = "delete";
export type TimelineInfoCardProps = TimelineCardComponentProps<
OrdinaryTimelineManageItem
>;
const TimelineInfoCard: React.FC<TimelineInfoCardProps> = (props) => {
const { onHeight, onManage } = props;
const { t } = useTranslation();
const avatar = useAvatar(props.timeline.owner.username);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const containerRef = React.useRef<HTMLDivElement>(null!);
const notifyHeight = React.useCallback((): void => {
if (onHeight) {
onHeight(containerRef.current.getBoundingClientRect().height);
}
}, [onHeight]);
React.useEffect(() => {
const subscription = fromEvent(window, "resize").subscribe(notifyHeight);
return () => subscription.unsubscribe();
});
const [manageDropdownOpen, setManageDropdownOpen] = React.useState<boolean>(
false
);
const toggleManageDropdown = React.useCallback(
(): void => setManageDropdownOpen((old) => !old),
[]
);
return (
<div
ref={containerRef}
className={clsx("rounded border p-2 bg-light", props.className)}
onTransitionEnd={notifyHeight}
>
<h3 className="text-primary mx-3 d-inline-block align-middle">
{props.timeline.name}
</h3>
<div className="d-inline-block align-middle">
<BlobImage
blob={avatar}
onLoad={notifyHeight}
className="avatar small rounded-circle"
/>
{props.timeline.owner.nickname}
<small className="ml-3 text-secondary">
@{props.timeline.owner.username}
</small>
</div>
<p className="mb-0">{props.timeline.description}</p>
<small className="mt-1 d-block">
{t(timelineVisibilityTooltipTranslationMap[props.timeline.visibility])}
</small>
<div className="text-right mt-2">
{onManage != null ? (
<Dropdown isOpen={manageDropdownOpen} toggle={toggleManageDropdown}>
<DropdownToggle outline color="primary">
{t("timeline.manage")}
</DropdownToggle>
<DropdownMenu>
<DropdownItem onClick={() => onManage("property")}>
{t("timeline.manageItem.property")}
</DropdownItem>
<DropdownItem onClick={props.onMember}>
{t("timeline.manageItem.member")}
</DropdownItem>
<DropdownItem divider />
<DropdownItem
className="text-danger"
onClick={() => onManage("delete")}
>
{t("timeline.manageItem.delete")}
</DropdownItem>
</DropdownMenu>
</Dropdown>
) : (
<Button color="primary" outline onClick={props.onMember}>
{t("timeline.memberButton")}
</Button>
)}
</div>
</div>
);
};
export default TimelineInfoCard;
|