blob: ae7783e65c006f32ef5077536cfeb8ca260da766 (
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
|
import React from "react";
import clsx from "clsx";
import { Link } from "react-router-dom";
import { Trans } from "react-i18next";
import { Spinner } from "react-bootstrap";
import { TimelineInfo } from "@/services/timeline";
import TimelineLogo from "../common/TimelineLogo";
import UserTimelineLogo from "../common/UserTimelineLogo";
interface TimelineBoardUIProps {
title?: string;
timelines: TimelineInfo[] | "offline" | "loading";
onReload: () => void;
className?: string;
}
const TimelineBoardUI: React.FC<TimelineBoardUIProps> = (props) => {
const { title, timelines, className } = props;
return (
<div className={clsx("timeline-board", className)}>
{title != null && <h3 className="text-center">{title}</h3>}
{(() => {
if (timelines === "loading") {
return (
<div className="d-flex flex-grow-1 justify-content-center align-items-center">
<Spinner variant="primary" animation="border" />
</div>
);
} else if (timelines === "offline") {
return (
<div className="d-flex flex-grow-1 justify-content-center align-items-center">
<Trans i18nKey="loadFailReload" parent="div">
0
<a
href="#"
onClick={(e) => {
props.onReload();
e.preventDefault();
}}
>
1
</a>
2
</Trans>
</div>
);
} else {
return timelines.map((timeline) => {
const { name, title } = timeline;
const isPersonal = name.startsWith("@");
const url = isPersonal
? `/users/${timeline.owner.username}`
: `/timelines/${name}`;
return (
<Link key={name} to={url} className="timeline-board-item">
{isPersonal ? (
<UserTimelineLogo className="icon" />
) : (
<TimelineLogo className="icon" />
)}
{title}
<small className="ml-2 text-secondary">{name}</small>
</Link>
);
});
}
})()}
</div>
);
};
export interface TimelineBoardProps {
title?: string;
className?: string;
load: () => Promise<TimelineInfo[]>;
}
const TimelineBoard: React.FC<TimelineBoardProps> = ({
className,
title,
load,
}) => {
const [timelines, setTimelines] = React.useState<
TimelineInfo[] | "offline" | "loading"
>("loading");
React.useEffect(() => {
let subscribe = true;
if (timelines === "loading") {
void load().then(
(timelines) => {
if (subscribe) {
setTimelines(timelines);
}
},
() => {
setTimelines("offline");
}
);
}
return () => {
subscribe = false;
};
}, [load, timelines]);
return (
<TimelineBoardUI
title={title}
className={className}
timelines={timelines}
onReload={() => {
setTimelines("loading");
}}
/>
);
};
export default TimelineBoard;
|