update and fix messanger
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { useAuth } from '@/components/id/auth-provider';
|
||||
import { apiFetch } from '@/lib/api';
|
||||
import { AVATAR_UPDATED_EVENT } from '@/lib/avatar-events';
|
||||
|
||||
interface AvatarAccessResponse {
|
||||
accessUrl: string;
|
||||
@@ -35,5 +36,17 @@ export function useAvatarUrl(userId: string | undefined, hasAvatar: boolean | un
|
||||
return () => window.clearInterval(timer);
|
||||
}, [hasAvatar, refresh]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!userId || !hasAvatar) return;
|
||||
function handleAvatarUpdated(event: Event) {
|
||||
const detail = (event as CustomEvent<{ userId?: string }>).detail;
|
||||
if (detail?.userId === userId) {
|
||||
void refresh();
|
||||
}
|
||||
}
|
||||
window.addEventListener(AVATAR_UPDATED_EVENT, handleAvatarUpdated);
|
||||
return () => window.removeEventListener(AVATAR_UPDATED_EVENT, handleAvatarUpdated);
|
||||
}, [hasAvatar, refresh, userId]);
|
||||
|
||||
return { avatarUrl, refreshAvatarUrl: refresh };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user