From a3f8daad1706697c6106045f271b74fd241ddcb3 Mon Sep 17 00:00:00 2001
From: crupest <crupest@outlook.com>
Date: Mon, 17 May 2021 21:41:19 +0800
Subject: feat: Connection badge.

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

(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 65378563..7b56d129 100644
--- a/FrontEnd/src/app/views/timeline-common/Timeline.tsx
+++ b/FrontEnd/src/app/views/timeline-common/Timeline.tsx
@@ -24,7 +24,7 @@ export interface TimelineProps {
 }
 
 const Timeline: React.FC<TimelineProps> = (props) => {
-  const { timelineName, className, style, reloadKey, onReload } = props;
+  const { timelineName, className, style, reloadKey } = props;
 
   const [state, setState] =
     React.useState<
@@ -37,6 +37,12 @@ const Timeline: React.FC<TimelineProps> = (props) => {
     setPosts([]);
   }, [timelineName]);
 
+  const onReload = React.useRef<() => void>(props.onReload);
+
+  React.useEffect(() => {
+    onReload.current = props.onReload;
+  }, [props.onReload]);
+
   const onConnectionStateChanged =
     React.useRef<((state: HubConnectionState) => void) | null>(null);
 
@@ -50,7 +56,7 @@ const Timeline: React.FC<TimelineProps> = (props) => {
       const subscription = timelinePostUpdate$.subscribe(
         ({ update, state }) => {
           if (update) {
-            onReload();
+            onReload.current();
           }
           onConnectionStateChanged.current?.(state);
         }
@@ -59,7 +65,7 @@ const Timeline: React.FC<TimelineProps> = (props) => {
         subscription.unsubscribe();
       };
     }
-  }, [timelineName, state, onReload, onConnectionStateChanged]);
+  }, [timelineName, state]);
 
   React.useEffect(() => {
     if (timelineName != null) {
@@ -125,7 +131,10 @@ const Timeline: React.FC<TimelineProps> = (props) => {
       return (
         <>
           <TimelineTop height={40} />
-          <TimelinePagedPostListView posts={posts} onReload={onReload} />
+          <TimelinePagedPostListView
+            posts={posts}
+            onReload={onReload.current}
+          />
         </>
       );
   }
-- 
cgit v1.2.3

