fix and update

This commit is contained in:
lendry
2026-07-01 23:27:48 +03:00
parent 2b88e028c6
commit bcdfbc3861
36 changed files with 1504 additions and 320 deletions

View File

@@ -11,10 +11,11 @@ import {
fetchFamilyPresence,
getAccessToken
} from '@/lib/api';
import { resolveFamilyGroupId } from '@/lib/selected-family-storage';
export function useSelectedFamily(enabled = true) {
const { user, token, isPinLocked, isLoading, isContentReady } = useAuth();
const { selectedGroupId, setSelectedGroupId } = useFamilyOverlay();
const { selectedGroupId, setSelectedGroupId, isSelectionHydrated } = useFamilyOverlay();
const userId = user?.id;
const [groups, setGroups] = useState<FamilyGroup[]>([]);
const [group, setGroup] = useState<FamilyGroup | null>(null);
@@ -33,6 +34,8 @@ export function useSelectedFamily(enabled = true) {
return;
}
let pendingHydration = false;
try {
const groupsResponse = await fetchFamilyGroups(userId, accessToken);
const list = groupsResponse.groups ?? [];
@@ -46,8 +49,11 @@ export function useSelectedFamily(enabled = true) {
return;
}
const effectiveId =
selectedGroupId && list.some((item) => item.id === selectedGroupId) ? selectedGroupId : list[0]!.id;
const effectiveId = resolveFamilyGroupId(list, selectedGroupId, isSelectionHydrated);
if (!effectiveId) {
pendingHydration = !isSelectionHydrated;
return;
}
if (effectiveId !== selectedGroupId) {
setSelectedGroupId(effectiveId);
@@ -63,9 +69,11 @@ export function useSelectedFamily(enabled = true) {
} catch {
// Фоновая ошибка не должна сбрасывать уже показанную семью в сайдбаре.
} finally {
setLoading(false);
if (!pendingHydration) {
setLoading(false);
}
}
}, [enabled, isContentReady, isLoading, isPinLocked, selectedGroupId, setSelectedGroupId, token, userId]);
}, [enabled, isContentReady, isLoading, isPinLocked, isSelectionHydrated, selectedGroupId, setSelectedGroupId, token, userId]);
useEffect(() => {
if (!enabled || !userId || !token || isPinLocked || isLoading || !isContentReady) {
@@ -78,7 +86,7 @@ export function useSelectedFamily(enabled = true) {
}
setLoading(!hasLoadedRef.current);
void refresh();
}, [enabled, isContentReady, isLoading, isPinLocked, refresh, token, userId]);
}, [enabled, isContentReady, isLoading, isPinLocked, isSelectionHydrated, refresh, token, userId]);
useEffect(() => {
const accessToken = getAccessToken() ?? token?.trim() ?? null;