fix and update
This commit is contained in:
@@ -27,7 +27,7 @@ function formatTime(value: string) {
|
||||
|
||||
export function NotificationBell() {
|
||||
const router = useRouter();
|
||||
const { token, isPinLocked, isLoading } = useAuth();
|
||||
const { token, isPinLocked, isLoading, isApiReady } = useAuth();
|
||||
const { showToast } = useToast();
|
||||
const { unreadCount, setUnreadCount, subscribe } = useRealtime();
|
||||
const [open, setOpen] = useState(false);
|
||||
@@ -36,7 +36,7 @@ export function NotificationBell() {
|
||||
const [respondingId, setRespondingId] = useState<string | null>(null);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
if (!token || isPinLocked || isLoading) return;
|
||||
if (!token || isPinLocked || isLoading || !isApiReady) return;
|
||||
setLoading(true);
|
||||
try {
|
||||
const [list, count] = await Promise.all([fetchNotifications(token), fetchUnreadNotificationCount(token)]);
|
||||
@@ -48,7 +48,7 @@ export function NotificationBell() {
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [isLoading, isPinLocked, setUnreadCount, showToast, token]);
|
||||
}, [isApiReady, isLoading, isPinLocked, setUnreadCount, showToast, token]);
|
||||
|
||||
useEffect(() => {
|
||||
void load();
|
||||
|
||||
@@ -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 }}>
|
||||
|
||||
Reference in New Issue
Block a user