import { BrandingView } from '@dorfteich/shared'; import { useQuery, useQueryClient } from '@tanstack/react-query'; import { apiGet } from '../lib/api'; export const BRANDING_KEY = ['branding']; /** * The instance branding in force (issue #306). * * Public, so the login screen carries it too — an operator's logo IS visible * to anonymous visitors, which the admin screen says out loud. */ export function useBranding(): BrandingView | undefined { return useQuery({ queryKey: BRANDING_KEY, queryFn: () => apiGet('/branding'), // Branding changes are rare and the manager invalidates the key itself. staleTime: 5 * 60 * 1000, }).data; } /** URL of a logo variant, with the content hash so a replaced logo is never * served from cache. */ export function logoUrl(variant: 'light' | 'dark', hash: string): string { return `/api/v1/branding/logo?variant=${variant}&v=${hash}`; } export function useInvalidateBranding(): () => Promise { const queryClient = useQueryClient(); return async () => { await queryClient.invalidateQueries({ queryKey: BRANDING_KEY }); }; }