From 753deacec6b8a7aeaa27a4bb5442d0d35f0a1e1a Mon Sep 17 00:00:00 2001 From: bohdanprog Date: Wed, 24 Apr 2024 14:00:45 +0200 Subject: [PATCH] add get track data with enabled option --- src/frontend/hooks/server/track.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/frontend/hooks/server/track.ts b/src/frontend/hooks/server/track.ts index 39c8c451f..1df112c8b 100644 --- a/src/frontend/hooks/server/track.ts +++ b/src/frontend/hooks/server/track.ts @@ -2,6 +2,7 @@ import { useQueryClient, useMutation, useSuspenseQuery, + useQuery, } from '@tanstack/react-query'; import {useProject} from './projects'; import {TrackValue} from '@mapeo/schema'; @@ -33,6 +34,19 @@ export function useTracksQuery() { }); } +export function useTrackWithEnableOptionQuery(docId?: string) { + const project = useProject(); + return useQuery({ + queryKey: [TRACK_KEY], + enabled: !!docId, + queryFn: async () => { + if (!docId) return; + if (!project) throw new Error('Project instance does not exist'); + return project.track.getByDocId(docId); + }, + }); +} + export function useTrackQuery(docId: string) { const project = useProject(); return useSuspenseQuery({