diff options
author | crupest <crupest@outlook.com> | 2020-12-19 22:04:25 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-12-19 22:04:25 +0800 |
commit | 59b54e6e838b0b0f343ea917815f342b2987c417 (patch) | |
tree | efcfc46da2fd6219fc32315246a7c781a366925b /FrontEnd/src/app/views/home/TimelineBoard.tsx | |
parent | b1fcdac173457d2462836a8a749f3b2653be0e3a (diff) | |
download | timeline-59b54e6e838b0b0f343ea917815f342b2987c417.tar.gz timeline-59b54e6e838b0b0f343ea917815f342b2987c417.tar.bz2 timeline-59b54e6e838b0b0f343ea917815f342b2987c417.zip |
...
Diffstat (limited to 'FrontEnd/src/app/views/home/TimelineBoard.tsx')
-rw-r--r-- | FrontEnd/src/app/views/home/TimelineBoard.tsx | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/FrontEnd/src/app/views/home/TimelineBoard.tsx b/FrontEnd/src/app/views/home/TimelineBoard.tsx index c2a7e5fe..ae7783e6 100644 --- a/FrontEnd/src/app/views/home/TimelineBoard.tsx +++ b/FrontEnd/src/app/views/home/TimelineBoard.tsx @@ -8,14 +8,14 @@ import { TimelineInfo } from "@/services/timeline"; import TimelineLogo from "../common/TimelineLogo"; import UserTimelineLogo from "../common/UserTimelineLogo"; -export interface TimelineBoardProps { +interface TimelineBoardUIProps { title?: string; timelines: TimelineInfo[] | "offline" | "loading"; onReload: () => void; className?: string; } -const TimelineBoard: React.FC<TimelineBoardProps> = (props) => { +const TimelineBoardUI: React.FC<TimelineBoardUIProps> = (props) => { const { title, timelines, className } = props; return ( @@ -71,4 +71,50 @@ const TimelineBoard: React.FC<TimelineBoardProps> = (props) => { ); }; +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; |