import type { PondView } from '@dorfteich/shared'; import { useQuery } from '@tanstack/react-query'; import { apiGet } from '../lib/api'; /** * The current pond's id and name from its slug (issue #307). * * Shares the sidebar's query key, so the pond is fetched once. Returns * nothing for an unreadable or unknown slug — which is exactly why the * favicon swap is driven by this and not by the raw route parameter: a bad * slug must not leave a stale icon in the tab. */ export function usePondId(pondSlug: string | null): { pondId?: string; pondName?: string } { const pond = useQuery({ queryKey: ['pond', pondSlug], queryFn: () => apiGet(`/ponds/${pondSlug!}`), enabled: Boolean(pondSlug), }); return { pondId: pond.data?.id, pondName: pond.data?.name }; }