fix and update
This commit is contained in:
@@ -35,6 +35,7 @@ const RealtimeContext = React.createContext<RealtimeContextValue | null>(null);
|
||||
|
||||
export function RealtimeProvider({ children }: { children: React.ReactNode }) {
|
||||
const { user, token, isPinLocked, isLoading, isContentReady } = useAuth();
|
||||
const userId = user?.id;
|
||||
const [unreadCount, setUnreadCount] = React.useState(0);
|
||||
const [connected, setConnected] = React.useState(false);
|
||||
const listenersRef = React.useRef(new Set<Listener>());
|
||||
@@ -52,7 +53,7 @@ export function RealtimeProvider({ children }: { children: React.ReactNode }) {
|
||||
}, []);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!user || !token || isPinLocked || isLoading || !isContentReady) {
|
||||
if (!userId || !token || isPinLocked || isLoading || !isContentReady) {
|
||||
setUnreadCount(0);
|
||||
return;
|
||||
}
|
||||
@@ -68,10 +69,10 @@ export function RealtimeProvider({ children }: { children: React.ReactNode }) {
|
||||
cancelled = true;
|
||||
window.clearTimeout(timer);
|
||||
};
|
||||
}, [isContentReady, isLoading, isPinLocked, token, user]);
|
||||
}, [isContentReady, isLoading, isPinLocked, token, userId]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!user || !token || isPinLocked || isLoading || !isContentReady) {
|
||||
if (!userId || !token || isPinLocked || isLoading || !isContentReady) {
|
||||
socketRef.current?.close();
|
||||
socketRef.current = null;
|
||||
setConnected(false);
|
||||
@@ -149,7 +150,7 @@ export function RealtimeProvider({ children }: { children: React.ReactNode }) {
|
||||
socketRef.current = null;
|
||||
setConnected(false);
|
||||
};
|
||||
}, [emit, isContentReady, isLoading, isPinLocked, token, user]);
|
||||
}, [emit, isContentReady, isLoading, isPinLocked, token, userId]);
|
||||
|
||||
return (
|
||||
<RealtimeContext.Provider value={{ unreadCount, setUnreadCount, subscribe, connected }}>
|
||||
|
||||
Reference in New Issue
Block a user