From 04737cd734eda58eca5da59d5a6a35c0dc1e9364 Mon Sep 17 00:00:00 2001
From: crupest <crupest@outlook.com>
Date: Sun, 16 May 2021 19:56:05 +0800
Subject: fix: Enhance logic of signalr.

---
 FrontEnd/src/app/views/timeline-common/Timeline.tsx | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

(limited to 'FrontEnd/src/app/views/timeline-common/Timeline.tsx')

diff --git a/FrontEnd/src/app/views/timeline-common/Timeline.tsx b/FrontEnd/src/app/views/timeline-common/Timeline.tsx
index 32d0bdd5..8bdf4d3b 100644
--- a/FrontEnd/src/app/views/timeline-common/Timeline.tsx
+++ b/FrontEnd/src/app/views/timeline-common/Timeline.tsx
@@ -7,6 +7,8 @@ import {
 } from "@/http/common";
 import { getHttpTimelineClient, HttpTimelinePostInfo } from "@/http/timeline";
 
+import { getTimelinePostUpdate$ } from "@/services/timeline";
+
 import TimelinePagedPostListView from "./TimelinePagedPostListView";
 import TimelineTop from "./TimelineTop";
 import TimelineLoading from "./TimelineLoading";
@@ -33,6 +35,18 @@ const Timeline: React.FC<TimelineProps> = (props) => {
     setPosts([]);
   }, [timelineName]);
 
+  React.useEffect(() => {
+    if (timelineName != null && state === "loaded") {
+      const timelinePostUpdate$ = getTimelinePostUpdate$(timelineName);
+      const subscription = timelinePostUpdate$.subscribe(() => {
+        onReload();
+      });
+      return () => {
+        subscription.unsubscribe();
+      };
+    }
+  }, [timelineName, state, onReload]);
+
   React.useEffect(() => {
     if (timelineName != null) {
       let subscribe = true;
-- 
cgit v1.2.3

