diff --git a/frontend/src/context/NotificationProvider.js b/frontend/src/context/NotificationProvider.js index dc629a6..3309e88 100644 --- a/frontend/src/context/NotificationProvider.js +++ b/frontend/src/context/NotificationProvider.js @@ -10,6 +10,7 @@ import { AuthContext } from "./AuthContext"; const NotificationProvider = ({ children }) => { const { connected, on, off } = useContext(SSEContext); const { auth } = useContext(AuthContext); + const [hasConnected, setHasConnected] = React.useState(false); // Watch connection state for connection status toasts useEffect(() => { @@ -17,12 +18,14 @@ const NotificationProvider = ({ children }) => { toast.success("Connected to real-time updates", { toastId: "sse-connected", // Prevent duplicate toasts }); - } else { + setHasConnected(true); + } else if (hasConnected) { + // Only show reconnecting toast if we were previously connected toast.warning("Connection lost. Reconnecting...", { toastId: "sse-reconnecting", }); } - }, [connected]); + }, [connected, hasConnected]); useEffect(() => { if (!connected) return;