From b924991afd38c89d1dfbfaa288ca9906128bb267 Mon Sep 17 00:00:00 2001 From: Domingo Dirutigliano Date: Sun, 6 Jul 2025 17:42:59 +0200 Subject: [PATCH] fix websocket connection --- frontend/src/App.tsx | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index d346485..12b4260 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -21,7 +21,25 @@ function App() { const [reqError, setReqError] = useState() const [error, setError] = useState() const [loadinBtn, setLoadingBtn] = useState(false); - + const queryClient = useQueryClient() + + useEffect(()=>{ + socketio.auth = { token: localStorage.getItem("access_token") } + socketio.connect() + getStatus() + socketio.on("update", (data) => { + queryClient.invalidateQueries({ queryKey: data }) + }) + socketio.on("connect_error", (err) => { + errorNotify("Socket.Io connection failed! ",`Error message: [${err.message}]`) + getStatus() + }); + return () => { + socketio.off("update") + socketio.off("connect_error") + socketio.disconnect() + } +},[]) const getStatus = () =>{ getstatus().then( res =>{ @@ -140,26 +158,6 @@ function App() { const PageRouting = ({ getStatus }:{ getStatus:()=>void }) => { - const queryClient = useQueryClient() - - useEffect(()=>{ - socketio.auth = { token: localStorage.getItem("access_token") } - socketio.connect() - getStatus() - socketio.on("update", (data) => { - queryClient.invalidateQueries({ queryKey: data }) - }) - socketio.on("connect_error", (err) => { - errorNotify("Socket.Io connection failed! ",`Error message: [${err.message}]`) - getStatus() - }); - return () => { - socketio.off("update") - socketio.off("connect_error") - socketio.disconnect() - } -},[]) - return }> } >