|
|
|
@ -69,36 +69,8 @@ export async function getMarriageProfile() { |
|
|
|
export function useMarriageProfileQuery<TData = MarriageProfileResponse>( |
|
|
|
options?: QueryOptions<MarriageProfileResponse, TData>, |
|
|
|
) { |
|
|
|
const queryClient = useQueryClient(); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
const handleInitialData = (e: Event) => { |
|
|
|
const customEvent = e as CustomEvent; |
|
|
|
const initial = getInitialMarriageProfile(); |
|
|
|
console.log("📥 [Profile Query] Received habib:marriage-initial-data event:", { |
|
|
|
detail: customEvent.detail, |
|
|
|
parsedInitial: initial, |
|
|
|
}); |
|
|
|
if (initial) { |
|
|
|
queryClient.setQueryData(marriageQueryKeys.profile(), (old: any) => { |
|
|
|
console.log("🔄 [Profile Query] Merging initialData into QueryCache. Old:", old, "New Initial:", initial); |
|
|
|
if (!old) return initial; |
|
|
|
return { |
|
|
|
...initial, |
|
|
|
...old, |
|
|
|
}; |
|
|
|
}); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
window.addEventListener("habib:marriage-initial-data", handleInitialData); |
|
|
|
return () => { |
|
|
|
window.removeEventListener("habib:marriage-initial-data", handleInitialData); |
|
|
|
}; |
|
|
|
}, [queryClient]); |
|
|
|
|
|
|
|
const query = useQuery({ |
|
|
|
staleTime: 0, // Prioritize fresh server data from /api/marriage/profile/main/ on mount
|
|
|
|
staleTime: 30 * 1000, |
|
|
|
refetchOnWindowFocus: false, |
|
|
|
initialData: getInitialMarriageProfile as any, |
|
|
|
initialDataUpdatedAt: 0, |
|
|
|
@ -107,5 +79,8 @@ export function useMarriageProfileQuery<TData = MarriageProfileResponse>( |
|
|
|
queryKey: marriageQueryKeys.profile(), |
|
|
|
}); |
|
|
|
|
|
|
|
return query; |
|
|
|
return { |
|
|
|
...query, |
|
|
|
isLiveServerFetched: query.dataUpdatedAt > 0, |
|
|
|
}; |
|
|
|
} |