update and fix messanger

This commit is contained in:
lendry
2026-06-26 00:16:17 +03:00
parent b0ea87e898
commit 4e78a81eb1
14 changed files with 898 additions and 125 deletions

View File

@@ -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 };
}