From 1e2f5c3d05e8718926032ab347996fcf0c5eddc2 Mon Sep 17 00:00:00 2001 From: Amalesh Arivanan Date: Fri, 8 May 2026 15:00:41 +0530 Subject: [PATCH 1/4] Changing the Timer logic --- src/components/Timer/Timer.jsx | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/components/Timer/Timer.jsx b/src/components/Timer/Timer.jsx index 1af28c5442..b54be36c5f 100644 --- a/src/components/Timer/Timer.jsx +++ b/src/components/Timer/Timer.jsx @@ -36,6 +36,7 @@ function Timer({ authUser, darkMode, isPopout }) { * to CLOSED, and the user will be notified to refresh the page to reconnect to the server. * */ const [customReadyState, setCustomReadyState] = useState(ReadyState.CONNECTING); + const [wsKey, setWsKey] = useState(0); const WSoptions = { share: false, protocols: localStorage.getItem(config.tokenKey), @@ -59,9 +60,18 @@ function Timer({ authUser, darkMode, isPopout }) { * } */ - const { sendMessage, sendJsonMessage, lastJsonMessage, getWebSocket } = useWebSocket( + /*const { sendMessage, sendJsonMessage, lastJsonMessage, getWebSocket } = useWebSocket( ENDPOINTS.TIMER_SERVICE, WSoptions, + );*/ + + const { sendMessage, sendJsonMessage, lastJsonMessage, getWebSocket } = useWebSocket( + ENDPOINTS.TIMER_SERVICE, + { + ...WSoptions, + // This makes the hook treat wsKey changes as a full reconnect + queryParams: { reconnect: wsKey }, + }, ); // This is the contract between server and client @@ -228,8 +238,15 @@ function Timer({ authUser, darkMode, isPopout }) { ); const handleRefreshTimer = useCallback(() => { - window.location.reload(); - }, []); + // Close the existing socket gracefully, then remount by bumping the key + try { + getWebSocket()?.close(); + } catch (e) { + // ignore if socket is already gone + } + setCustomReadyState(ReadyState.CONNECTING); + setWsKey(k => k + 1); + }, [getWebSocket]); // Initialize session ID on component mount useEffect(() => { From 77acf39c8f01f000f1ac14e8f951866f70d0467a Mon Sep 17 00:00:00 2001 From: Amalesh Arivanan Date: Fri, 8 May 2026 15:13:36 +0530 Subject: [PATCH 2/4] Changing the Timer logic --- src/components/Timer/Timer.jsx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/components/Timer/Timer.jsx b/src/components/Timer/Timer.jsx index b54be36c5f..634e43ce2e 100644 --- a/src/components/Timer/Timer.jsx +++ b/src/components/Timer/Timer.jsx @@ -60,16 +60,10 @@ function Timer({ authUser, darkMode, isPopout }) { * } */ - /*const { sendMessage, sendJsonMessage, lastJsonMessage, getWebSocket } = useWebSocket( - ENDPOINTS.TIMER_SERVICE, - WSoptions, - );*/ - const { sendMessage, sendJsonMessage, lastJsonMessage, getWebSocket } = useWebSocket( ENDPOINTS.TIMER_SERVICE, { ...WSoptions, - // This makes the hook treat wsKey changes as a full reconnect queryParams: { reconnect: wsKey }, }, ); From 30e4910aab5563fc3bcfd8461d60b673931a67af Mon Sep 17 00:00:00 2001 From: Amalesh Arivanan Date: Fri, 8 May 2026 15:30:05 +0530 Subject: [PATCH 3/4] Changed the refresh logic for the disconnected timer --- src/components/Timer/Timer.jsx | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/components/Timer/Timer.jsx b/src/components/Timer/Timer.jsx index 634e43ce2e..77f75d3462 100644 --- a/src/components/Timer/Timer.jsx +++ b/src/components/Timer/Timer.jsx @@ -232,13 +232,9 @@ function Timer({ authUser, darkMode, isPopout }) { ); const handleRefreshTimer = useCallback(() => { - // Close the existing socket gracefully, then remount by bumping the key - try { - getWebSocket()?.close(); - } catch (e) { - // ignore if socket is already gone - } + getWebSocket()?.close(); setCustomReadyState(ReadyState.CONNECTING); + setMessage(defaultMessage); setWsKey(k => k + 1); }, [getWebSocket]); @@ -662,10 +658,10 @@ function Timer({ authUser, darkMode, isPopout }) { }, [weekEndModal]); useEffect(() => { - if (!isInitialJsonMessageReceived) return; + if (customReadyState !== ReadyState.OPEN) return; // only request when connected sendGetTimer(); - }, [isInitialJsonMessageReceived, viewingUserId]); + }, [customReadyState, viewingUserId, wsKey]); // Enhanced cleanup when viewing user changes useEffect(() => { From a353e6bb1cf7d9cafb93263bf6fbd4394bfbf3ee Mon Sep 17 00:00:00 2001 From: Amalesh Arivanan Date: Fri, 8 May 2026 15:35:37 +0530 Subject: [PATCH 4/4] Improved code quality --- src/components/Timer/Timer.jsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/Timer/Timer.jsx b/src/components/Timer/Timer.jsx index 77f75d3462..d443333a38 100644 --- a/src/components/Timer/Timer.jsx +++ b/src/components/Timer/Timer.jsx @@ -300,8 +300,6 @@ function Timer({ authUser, darkMode, isPopout }) { () => viewingUserId && !ALLOWED_ROLES_TO_INTERACT.includes(authUser?.role), [viewingUserId, authUser], ); - // control whether to send GET_TIMER message to avoid message overriding - const isInitialJsonMessageReceived = useMemo(() => !!lastJsonMessage, [lastJsonMessage]); // Modify the sendStop function to track submitted time const wsJsonMessageHandler = useMemo(() => {