aboutsummaryrefslogtreecommitdiff
path: root/FrontEnd/src/views/timeline-common/Timeline.tsx
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-06-15 21:19:02 +0800
committercrupest <crupest@outlook.com>2021-06-15 21:19:02 +0800
commit1552c0086c396aa89e0ad965a6cbd6c3ea70cac4 (patch)
tree2347d15102711f8dc917dfd6e1888fc1527c5c64 /FrontEnd/src/views/timeline-common/Timeline.tsx
parentc442bec1342a16ddfdb8e103f9b238e4581639e2 (diff)
downloadtimeline-1552c0086c396aa89e0ad965a6cbd6c3ea70cac4.tar.gz
timeline-1552c0086c396aa89e0ad965a6cbd6c3ea70cac4.tar.bz2
timeline-1552c0086c396aa89e0ad965a6cbd6c3ea70cac4.zip
...
Diffstat (limited to 'FrontEnd/src/views/timeline-common/Timeline.tsx')
-rw-r--r--FrontEnd/src/views/timeline-common/Timeline.tsx39
1 files changed, 27 insertions, 12 deletions
diff --git a/FrontEnd/src/views/timeline-common/Timeline.tsx b/FrontEnd/src/views/timeline-common/Timeline.tsx
index 21daa5e2..90eba18f 100644
--- a/FrontEnd/src/views/timeline-common/Timeline.tsx
+++ b/FrontEnd/src/views/timeline-common/Timeline.tsx
@@ -6,7 +6,11 @@ import {
HttpNetworkError,
HttpNotFoundError,
} from "@/http/common";
-import { getHttpTimelineClient, HttpTimelinePostInfo } from "@/http/timeline";
+import {
+ getHttpTimelineClient,
+ HttpTimelineInfo,
+ HttpTimelinePostInfo,
+} from "@/http/timeline";
import { getTimelinePostUpdate$ } from "@/services/timeline";
@@ -15,6 +19,7 @@ import TimelineTop from "./TimelineTop";
import TimelineLoading from "./TimelineLoading";
import "./index.css";
+import TimelinePostEdit from "./TimelinePostEdit";
export interface TimelineProps {
className?: string;
@@ -31,10 +36,12 @@ const Timeline: React.FC<TimelineProps> = (props) => {
const [state, setState] = React.useState<
"loading" | "loaded" | "offline" | "notexist" | "forbid" | "error"
>("loading");
+ const [timeline, setTimeline] = React.useState<HttpTimelineInfo | null>(null);
const [posts, setPosts] = React.useState<HttpTimelinePostInfo[]>([]);
React.useEffect(() => {
setState("loading");
+ setTimeline(null);
setPosts([]);
}, [timelineName]);
@@ -73,16 +80,20 @@ const Timeline: React.FC<TimelineProps> = (props) => {
if (timelineName != null) {
let subscribe = true;
- void getHttpTimelineClient()
- .listPost(timelineName)
- .then(
- (data) => {
- if (subscribe) {
- setState("loaded");
- setPosts(data);
- }
- },
- (error) => {
+ const client = getHttpTimelineClient();
+ Promise.all([
+ client.getTimeline(timelineName),
+ client.listPost(timelineName),
+ ]).then(
+ ([t, p]) => {
+ if (subscribe) {
+ setTimeline(t);
+ setPosts(p);
+ setState("loaded");
+ }
+ },
+ (error) => {
+ if (subscribe) {
if (error instanceof HttpNetworkError) {
setState("offline");
} else if (error instanceof HttpForbiddenError) {
@@ -94,7 +105,8 @@ const Timeline: React.FC<TimelineProps> = (props) => {
setState("error");
}
}
- );
+ }
+ );
return () => {
subscribe = false;
@@ -137,6 +149,9 @@ const Timeline: React.FC<TimelineProps> = (props) => {
posts={posts}
onReload={onReload.current}
/>
+ {timeline?.postable && (
+ <TimelinePostEdit timeline={timeline} onPosted={onReload.current} />
+ )}
</>
);
}