fix and update

This commit is contained in:
lendry
2026-06-29 21:22:20 +03:00
parent 7233e8b70a
commit 8369abb023
7 changed files with 98 additions and 23 deletions

View File

@@ -11,11 +11,11 @@ interface AvatarAccessResponse {
}
export function useAvatarUrl(userId: string | undefined, hasAvatar: boolean | undefined, token: string | null) {
const { isPinLocked } = useAuth();
const { isPinLocked, isLoading } = useAuth();
const [avatarUrl, setAvatarUrl] = useState<string | null>(null);
const refresh = useCallback(async () => {
if (!userId || !token || !hasAvatar || isPinLocked) {
if (!userId || !token || !hasAvatar || isPinLocked || isLoading) {
setAvatarUrl(null);
return;
}
@@ -25,7 +25,7 @@ export function useAvatarUrl(userId: string | undefined, hasAvatar: boolean | un
} catch {
setAvatarUrl(null);
}
}, [hasAvatar, isPinLocked, token, userId]);
}, [hasAvatar, isLoading, isPinLocked, token, userId]);
useEffect(() => {
void refresh();

View File

@@ -1,6 +1,7 @@
'use client';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useAuth } from '@/components/id/auth-provider';
import { ChatMessage, ChatRoom, fetchUserE2EPublicKey, setUserE2EPublicKey } from '@/lib/api';
import { ensureE2EKeyPair } from '@/lib/e2e-crypto';
import {
@@ -51,6 +52,7 @@ export function useE2EChat(options: {
userId?: string;
token?: string | null;
}) {
const { isLoading } = useAuth();
const isE2E = options.room?.type === 'E2E';
const peerUserId = useMemo(
() => resolveChatPeerUserId(options.room, options.userId),
@@ -63,7 +65,7 @@ export function useE2EChat(options: {
const [e2eErrors, setE2eErrors] = useState<Record<string, string>>({});
useEffect(() => {
if (!options.userId || !options.token) return;
if (!options.userId || !options.token || isLoading) return;
void (async () => {
try {
const { publicKey } = await ensureE2EKeyPair(options.userId!);
@@ -72,7 +74,7 @@ export function useE2EChat(options: {
// фоновая инициализация E2E
}
})();
}, [options.token, options.userId]);
}, [isLoading, options.token, options.userId]);
useEffect(() => {
if (!isE2E || !peerUserId || !options.token) {

View File

@@ -12,7 +12,7 @@ import {
} from '@/lib/api';
export function useSelectedFamily(enabled = true) {
const { user, token, isPinLocked } = useAuth();
const { user, token, isPinLocked, isLoading } = useAuth();
const { selectedGroupId, setSelectedGroupId } = useFamilyOverlay();
const [groups, setGroups] = useState<FamilyGroup[]>([]);
const [group, setGroup] = useState<FamilyGroup | null>(null);
@@ -20,7 +20,7 @@ export function useSelectedFamily(enabled = true) {
const [loading, setLoading] = useState(true);
const refresh = useCallback(async () => {
if (!enabled || !user || !token || isPinLocked) {
if (!enabled || !user || !token || isPinLocked || isLoading) {
setGroups([]);
setGroup(null);
setPresenceMembers([]);
@@ -60,7 +60,7 @@ export function useSelectedFamily(enabled = true) {
} finally {
setLoading(false);
}
}, [enabled, isPinLocked, selectedGroupId, setSelectedGroupId, token, user]);
}, [enabled, isLoading, isPinLocked, selectedGroupId, setSelectedGroupId, token, user]);
useEffect(() => {
setLoading(true);
@@ -68,10 +68,10 @@ export function useSelectedFamily(enabled = true) {
}, [refresh]);
useEffect(() => {
if (!enabled || !token || isPinLocked || !group) return;
if (!enabled || !token || isPinLocked || isLoading || !group) return;
const timer = window.setInterval(() => void refresh(), 25_000);
return () => window.clearInterval(timer);
}, [enabled, group, isPinLocked, refresh, token]);
}, [enabled, group, isLoading, isPinLocked, refresh, token]);
const presenceByUserId = useMemo(
() => new Map(presenceMembers.map((member) => [member.userId, member])),