fix and update

This commit is contained in:
lendry
2026-06-29 22:51:25 +03:00
parent 885b07d76b
commit 57cb58347b
30 changed files with 799 additions and 187 deletions

View File

@@ -8,7 +8,8 @@ import {
FamilyPresenceMember,
fetchFamilyGroup,
fetchFamilyGroups,
fetchFamilyPresence
fetchFamilyPresence,
getAccessToken
} from '@/lib/api';
export function useSelectedFamily(enabled = true) {
@@ -20,7 +21,8 @@ export function useSelectedFamily(enabled = true) {
const [loading, setLoading] = useState(true);
const refresh = useCallback(async () => {
if (!enabled || !user || !token || isPinLocked || isLoading) {
const accessToken = getAccessToken() ?? token?.trim() ?? null;
if (!enabled || !user || !accessToken || isPinLocked || isLoading) {
setGroups([]);
setGroup(null);
setPresenceMembers([]);
@@ -29,7 +31,7 @@ export function useSelectedFamily(enabled = true) {
}
try {
const groupsResponse = await fetchFamilyGroups(user.id, token);
const groupsResponse = await fetchFamilyGroups(user.id, accessToken);
const list = groupsResponse.groups ?? [];
setGroups(list);
@@ -48,8 +50,8 @@ export function useSelectedFamily(enabled = true) {
}
const [groupResponse, presenceResponse] = await Promise.all([
fetchFamilyGroup(effectiveId, token),
fetchFamilyPresence(effectiveId, token)
fetchFamilyGroup(effectiveId, accessToken),
fetchFamilyPresence(effectiveId, accessToken)
]);
setGroup(groupResponse);
setPresenceMembers(presenceResponse.members ?? []);
@@ -68,7 +70,8 @@ export function useSelectedFamily(enabled = true) {
}, [refresh]);
useEffect(() => {
if (!enabled || !token || isPinLocked || isLoading || !group) return;
const accessToken = getAccessToken() ?? token?.trim() ?? null;
if (!enabled || !accessToken || isPinLocked || isLoading || !group) return;
const timer = window.setInterval(() => void refresh(), 25_000);
return () => window.clearInterval(timer);
}, [enabled, group, isLoading, isPinLocked, refresh, token]);