Browse Source

refactor(ui): optimize flutter loading signal and profile data freshness

Update client components to signal readiness to the Flutter wrapper
immediately upon mounting, rather than waiting for data hydration.
Additionally, adjust profile query settings to prioritize fresh
server-side data.

- Force `useHabibWebReady(true)` in all client-side route components
- Set `staleTime` to 0 in `useMarriageProfileQuery` to ensure fresh
  data on mount
- Simplify `queryClient.setQueryData` logic in profile hook
master
mortezaei 2 weeks ago
parent
commit
3df506ec7a
  1. 5
      src/app/candidate-contact/candidate-contact-client.tsx
  2. 5
      src/app/new-match/new-match-client.tsx
  3. 5
      src/app/questions-list/questions-list-client.tsx
  4. 5
      src/app/request-accepted/request-accepted-client.tsx
  5. 5
      src/app/request-sent/request-sent-client.tsx
  6. 5
      src/app/terms/page.tsx
  7. 9
      src/hooks/marriage/use-profile-main.ts

5
src/app/candidate-contact/candidate-contact-client.tsx

@ -63,9 +63,8 @@ export default function CandidateContactClient() {
} }
}, [profile, router, locale]); }, [profile, router, locale]);
// Signal Flutter to lift its loading cover once profile is available or query finished.
const isVisuallyReady = Boolean(profile) || isFetched;
useHabibWebReady(isVisuallyReady);
// Signal Flutter to lift its loading cover immediately on mount
useHabibWebReady(true);
const isRedirecting = useMemo(() => { const isRedirecting = useMemo(() => {
if (!profile) return false; if (!profile) return false;

5
src/app/new-match/new-match-client.tsx

@ -611,9 +611,8 @@ export default function NewMatchClient() {
} }
}, [profile, locale, router, isLoading, isFetched, isError]); }, [profile, locale, router, isLoading, isFetched, isError]);
// Signal Flutter to lift its loading cover only once match summary is populated in DOM or query finished.
const isVisuallyReady = Boolean(profile?.match_summary) || isFetched || isError;
useHabibWebReady(isVisuallyReady);
// Signal Flutter to lift its loading cover immediately on mount
useHabibWebReady(true);
const handleOpenProfile = async () => { const handleOpenProfile = async () => {
// If profile has not yet completed its initial server fetch or is in flight: // If profile has not yet completed its initial server fetch or is in flight:

5
src/app/questions-list/questions-list-client.tsx

@ -136,9 +136,8 @@ export default function QuestionsListClient() {
void fetchGeoCountryCode(); void fetchGeoCountryCode();
}, []); }, []);
// Signal Flutter to lift its loading cover once the profile is available or query finished.
const isVisuallyReady = Boolean(profile) || isProfileFetched;
useHabibWebReady(isVisuallyReady);
// Signal Flutter to lift its loading cover immediately on mount
useHabibWebReady(true);
const startMatchMutation = useStartMarriageMatchMutation({ const startMatchMutation = useStartMarriageMatchMutation({
onSuccess: () => { onSuccess: () => {

5
src/app/request-accepted/request-accepted-client.tsx

@ -267,9 +267,8 @@ export default function RequestAcceptedClient() {
} }
}, [profile, isFetched, router, locale, noContactReportedSuccess]); }, [profile, isFetched, router, locale, noContactReportedSuccess]);
// Signal Flutter to lift its loading cover only once profile is populated in DOM or query finished.
const isVisuallyReady = Boolean(profile) || isFetched;
useHabibWebReady(isVisuallyReady);
// Signal Flutter to lift its loading cover immediately on mount
useHabibWebReady(true);
const handleOpenProfile = async () => { const handleOpenProfile = async () => {
if (!isFetched || isFetching) { if (!isFetched || isFetching) {

5
src/app/request-sent/request-sent-client.tsx

@ -57,9 +57,8 @@ export default function RequestSentClient() {
} }
}, [profile, isFetched, locale, router]); }, [profile, isFetched, locale, router]);
// Signal Flutter to lift its loading cover only once profile is populated in DOM or query finished.
const isVisuallyReady = Boolean(profile) || isFetched;
useHabibWebReady(isVisuallyReady);
// Signal Flutter to lift its loading cover immediately on mount
useHabibWebReady(true);
const isRedirecting = useMemo(() => { const isRedirecting = useMemo(() => {
if (!profile) return false; if (!profile) return false;

5
src/app/terms/page.tsx

@ -18,9 +18,8 @@ export default function TermsRoute() {
const router = useRouter(); const router = useRouter();
const { locale, dictionary: t } = useI18n(); const { locale, dictionary: t } = useI18n();
// Signal Flutter to lift its loading cover once profile or fallback is ready.
const isVisuallyReady = Boolean(profile) || !isLoading || isError;
useHabibWebReady(isVisuallyReady);
// Signal Flutter to lift its loading cover immediately on mount
useHabibWebReady(true);
useEffect(() => { useEffect(() => {
if (!isLoading && profile) { if (!isLoading && profile) {

9
src/hooks/marriage/use-profile-main.ts

@ -77,10 +77,8 @@ export function useMarriageProfileQuery<TData = MarriageProfileResponse>(
queryClient.setQueryData(marriageQueryKeys.profile(), (old: any) => { queryClient.setQueryData(marriageQueryKeys.profile(), (old: any) => {
if (!old) return initial; if (!old) return initial;
return { return {
...old,
...initial, ...initial,
active_case: initial.active_case ?? old.active_case,
match_summary: initial.match_summary ?? old.match_summary,
...old,
}; };
}); });
} }
@ -93,12 +91,9 @@ export function useMarriageProfileQuery<TData = MarriageProfileResponse>(
}, [queryClient]); }, [queryClient]);
const query = useQuery({ const query = useQuery({
staleTime: 5 * 60 * 1000,
staleTime: 0, // Prioritize fresh server data from /api/marriage/profile/main/ on mount
refetchOnWindowFocus: false, refetchOnWindowFocus: false,
initialData: getInitialMarriageProfile as any, initialData: getInitialMarriageProfile as any,
// Native-injected initialData is a snapshot from app-launch time and can be
// incomplete (e.g. missing active_case). Marking it stale forces a fresh
// fetch on mount instead of trusting it for the whole staleTime window.
initialDataUpdatedAt: 0, initialDataUpdatedAt: 0,
...options, ...options,
queryFn: getMarriageProfile, queryFn: getMarriageProfile,

Loading…
Cancel
Save