fix and update
This commit is contained in:
@@ -13,7 +13,7 @@ import {
|
||||
} from '@/lib/api';
|
||||
|
||||
export function useSelectedFamily(enabled = true) {
|
||||
const { user, token, isPinLocked, isLoading } = useAuth();
|
||||
const { user, token, isPinLocked, isLoading, isApiReady } = useAuth();
|
||||
const { selectedGroupId, setSelectedGroupId } = useFamilyOverlay();
|
||||
const [groups, setGroups] = useState<FamilyGroup[]>([]);
|
||||
const [group, setGroup] = useState<FamilyGroup | null>(null);
|
||||
@@ -22,7 +22,7 @@ export function useSelectedFamily(enabled = true) {
|
||||
|
||||
const refresh = useCallback(async () => {
|
||||
const accessToken = getAccessToken() ?? token?.trim() ?? null;
|
||||
if (!enabled || !user || !accessToken || isPinLocked || isLoading) {
|
||||
if (!enabled || !user || !accessToken || isPinLocked || isLoading || !isApiReady) {
|
||||
setGroups([]);
|
||||
setGroup(null);
|
||||
setPresenceMembers([]);
|
||||
@@ -62,7 +62,7 @@ export function useSelectedFamily(enabled = true) {
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [enabled, isLoading, isPinLocked, selectedGroupId, setSelectedGroupId, token, user]);
|
||||
}, [enabled, isApiReady, isLoading, isPinLocked, selectedGroupId, setSelectedGroupId, token, user]);
|
||||
|
||||
useEffect(() => {
|
||||
setLoading(true);
|
||||
@@ -71,10 +71,10 @@ export function useSelectedFamily(enabled = true) {
|
||||
|
||||
useEffect(() => {
|
||||
const accessToken = getAccessToken() ?? token?.trim() ?? null;
|
||||
if (!enabled || !accessToken || isPinLocked || isLoading || !group) return;
|
||||
if (!enabled || !accessToken || isPinLocked || isLoading || !isApiReady || !group) return;
|
||||
const timer = window.setInterval(() => void refresh(), 25_000);
|
||||
return () => window.clearInterval(timer);
|
||||
}, [enabled, group, isLoading, isPinLocked, refresh, token]);
|
||||
}, [enabled, group, isApiReady, isLoading, isPinLocked, refresh, token]);
|
||||
|
||||
const presenceByUserId = useMemo(
|
||||
() => new Map(presenceMembers.map((member) => [member.userId, member])),
|
||||
|
||||
Reference in New Issue
Block a user