'use client' import type { AdminMedia } from '@admin/types' import type { UseQueryResult } from '@tanstack/react-query' import { getMediaById } from '@admin/actions/media' import { useQuery } from '@tanstack/react-query' interface UseDashboardLogoOptions { initialData?: AdminMedia | null } // Kept off the ['media', 'detail', id] key: the sidebar hydrates before the settings page's // Suspense boundary, and a shared entry makes that boundary's MediaField hydrate with a // preview the server rendered as an empty state. export function useDashboardLogo( mediaId: string | null | undefined, options: UseDashboardLogoOptions = {} ): UseQueryResult { const initialData = options.initialData return useQuery({ queryKey: ['media', 'dashboard-logo', mediaId], queryFn: () => (mediaId ? getMediaById(mediaId) : null), enabled: !!mediaId, staleTime: Number.POSITIVE_INFINITY, gcTime: Number.POSITIVE_INFINITY, ...(initialData && initialData.id === mediaId ? { initialData } : {}) }) }