From ea3d118d549f26694a5973db870f0122d6417179 Mon Sep 17 00:00:00 2001
From: Claeb101 <calebarulandu@gmail.com>
Date: Mon, 6 Mar 2023 11:36:03 -0500
Subject: [PATCH] transfer ui bug with cycle

---
 app/src/pages/demo.tsx | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/app/src/pages/demo.tsx b/app/src/pages/demo.tsx
index 3a76160..56041cc 100644
--- a/app/src/pages/demo.tsx
+++ b/app/src/pages/demo.tsx
@@ -28,6 +28,7 @@ const Demo: NextPage<any> = ({ officers }) => {
   const [input, setInput] = useState({
     phone: '',
   })
+  const focusSessionMsgInterval = useRef(null);
   const [sessions, setSessions] = useState([])
   const [loadingSummary, setLoadingSummary] = useState(false)
   const [focusSession, setFocusSession] = useState(null)
@@ -94,6 +95,7 @@ const Demo: NextPage<any> = ({ officers }) => {
   }
 
   const closePop = async () => {
+    clearInterval(focusSessionMsgInterval.current);
     setFocusSession(null)
   }
 
@@ -106,13 +108,7 @@ const Demo: NextPage<any> = ({ officers }) => {
       if (focusSession) {
         if (!focusSession.messages) {
           await fetcher();
-          const cycle = () => setTimeout(async () => {
-            if (focusSession) {
-              await fetcher()
-              cycle()
-            }
-          }, updateDelay)
-          cycle()
+          focusSessionMsgInterval.current = setInterval(fetcher, updateDelay)
         }
       }
     }