fix and update

This commit is contained in:
lendry
2026-06-30 09:39:35 +03:00
parent 250976ca08
commit 4e98f6bfab
8 changed files with 192 additions and 110 deletions

View File

@@ -31,7 +31,7 @@ interface RealtimeContextValue {
const RealtimeContext = React.createContext<RealtimeContextValue | null>(null);
export function RealtimeProvider({ children }: { children: React.ReactNode }) {
const { user, token, isPinLocked, isLoading } = useAuth();
const { user, token, isPinLocked, isLoading, isApiReady } = useAuth();
const [unreadCount, setUnreadCount] = React.useState(0);
const [connected, setConnected] = React.useState(false);
const listenersRef = React.useRef(new Set<Listener>());
@@ -48,7 +48,7 @@ export function RealtimeProvider({ children }: { children: React.ReactNode }) {
}, []);
React.useEffect(() => {
if (!user || !token || isPinLocked || isLoading) {
if (!user || !token || isPinLocked || isLoading || !isApiReady) {
socketRef.current?.close();
socketRef.current = null;
setConnected(false);
@@ -121,7 +121,7 @@ export function RealtimeProvider({ children }: { children: React.ReactNode }) {
socketRef.current = null;
setConnected(false);
};
}, [emit, isLoading, isPinLocked, token, user]);
}, [emit, isApiReady, isLoading, isPinLocked, token, user]);
return (
<RealtimeContext.Provider value={{ unreadCount, setUnreadCount, subscribe, connected }}>