From e6ccc0174a86a0ade240e6551228598cd81f984b Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 1 Aug 2023 00:29:35 +0800 Subject: ... --- FrontEnd/src/pages/timeline/Timeline.tsx | 77 +++++++++++--------------------- 1 file changed, 25 insertions(+), 52 deletions(-) (limited to 'FrontEnd/src/pages/timeline/Timeline.tsx') diff --git a/FrontEnd/src/pages/timeline/Timeline.tsx b/FrontEnd/src/pages/timeline/Timeline.tsx index f93e1623..317d602e 100644 --- a/FrontEnd/src/pages/timeline/Timeline.tsx +++ b/FrontEnd/src/pages/timeline/Timeline.tsx @@ -1,4 +1,4 @@ -import * as React from "react"; +import { useState, useEffect } from "react"; import classnames from "classnames"; import { useScrollToBottom } from "@/utilities/hooks"; import { HubConnectionState } from "@microsoft/signalr"; @@ -14,56 +14,49 @@ import { HttpTimelinePostInfo, } from "@/http/timeline"; -import { useUser } from "@/services/user"; import { getTimelinePostUpdate$ } from "@/services/timeline"; -import TimelinePostListView from "./TimelinePostListView"; -import TimelineEmptyItem from "./TimelineEmptyItem"; -import TimelineLoading from "./TimelineLoading"; +import TimelinePostList from "./TimelinePostList"; import TimelinePostEdit from "./TimelinePostEdit"; -import TimelinePostEditNoLogin from "./TimelinePostEditNoLogin"; import TimelineCard from "./TimelineCard"; import "./Timeline.css"; export interface TimelineProps { className?: string; - style?: React.CSSProperties; timelineOwner: string; timelineName: string; } -const Timeline: React.FC = (props) => { - const { timelineOwner, timelineName, className, style } = props; +export function Timeline(props: TimelineProps) { + const { timelineOwner, timelineName, className } = props; - const user = useUser(); - - const [timeline, setTimeline] = React.useState(null); - const [posts, setPosts] = React.useState(null); - const [signalrState, setSignalrState] = React.useState( + const [timeline, setTimeline] = useState(null); + const [posts, setPosts] = useState(null); + const [signalrState, setSignalrState] = useState( HubConnectionState.Connecting, ); - const [error, setError] = React.useState< + const [error, setError] = useState< "offline" | "forbid" | "notfound" | "error" | null >(null); - const [currentPage, setCurrentPage] = React.useState(1); - const [totalPage, setTotalPage] = React.useState(0); + const [currentPage, setCurrentPage] = useState(1); + const [totalPage, setTotalPage] = useState(0); - const [timelineReloadKey, setTimelineReloadKey] = React.useState(0); - const [postsReloadKey, setPostsReloadKey] = React.useState(0); + const [timelineReloadKey, setTimelineReloadKey] = useState(0); + const [postsReloadKey, setPostsReloadKey] = useState(0); const updateTimeline = (): void => setTimelineReloadKey((o) => o + 1); const updatePosts = (): void => setPostsReloadKey((o) => o + 1); - React.useEffect(() => { + useEffect(() => { setTimeline(null); setPosts(null); setError(null); setSignalrState(HubConnectionState.Connecting); }, [timelineOwner, timelineName]); - React.useEffect(() => { + useEffect(() => { getHttpTimelineClient() .getTimeline(timelineOwner, timelineName) .then( @@ -85,7 +78,7 @@ const Timeline: React.FC = (props) => { ); }, [timelineOwner, timelineName, timelineReloadKey]); - React.useEffect(() => { + useEffect(() => { getHttpTimelineClient() .listPost(timelineOwner, timelineName, 1) .then( @@ -110,7 +103,7 @@ const Timeline: React.FC = (props) => { ); }, [timelineOwner, timelineName, postsReloadKey]); - React.useEffect(() => { + useEffect(() => { const timelinePostUpdate$ = getTimelinePostUpdate$( timelineOwner, timelineName, @@ -154,33 +147,16 @@ const Timeline: React.FC = (props) => { }, currentPage < totalPage); if (error === "offline") { - return ( -
- Offline. -
- ); + return
Offline.
; } else if (error === "notfound") { - return ( -
- Not exist. -
- ); + return
Not exist.
; } else if (error === "forbid") { - return ( -
- Forbid. -
- ); + return
Forbid.
; } else if (error === "error") { - return ( -
- Error. -
- ); + return
Error.
; } return ( <> - {timeline == null && posts == null && } {timeline && ( = (props) => { /> )} {posts && ( -
- - {timeline?.postable ? ( +
+ {timeline?.postable && ( - ) : user == null ? ( - - ) : null} - + )} +
)} ); -}; +} export default Timeline; -- cgit v1.2.3