import { useEffect, useState } from 'react'; import { usePlaybasis } from '../PlaybasisProvider'; import { usePoints } from './usePoints'; import { useQuests } from './useQuests'; import { useRewards } from './useRewards'; import { useBadges } from './useBadges'; /** * Validates and aggregates all SDK data hooks. * Use this to ensure the "App" has all necessary data loaded. */ export function useQwikApp() { const { client, playerId } = usePlaybasis(); const { balances, refresh: refreshPoints, loading: loadingPoints } = usePoints(); const { quests, loading: loadingQuests } = useQuests(); const { rewards, loading: loadingRewards } = useRewards(); const { badges, loading: loadingBadges } = useBadges(); const [isReady, setIsReady] = useState(false); // Check if critical data is loaded const isLoading = loadingPoints || loadingQuests || loadingRewards || loadingBadges; useEffect(() => { if (!isLoading && playerId) { setIsReady(true); } }, [isLoading, playerId]); const refreshAll = async () => { await Promise.all([ refreshPoints(), // Add other refresh methods if exposed by hooks ]); }; return { isReady, isLoading, refreshAll, data: { balances, quests, rewards, badges, }, }; }