diff options
| author | Ariel Costas Guerrero <ariel@costas.dev> | 2025-12-27 16:39:09 +0100 |
|---|---|---|
| committer | Ariel Costas Guerrero <ariel@costas.dev> | 2025-12-27 16:39:28 +0100 |
| commit | f81ff82f2a07f87f6eb4f43de49ede64215519e5 (patch) | |
| tree | 67b4f9ef1c94184e2e1a9878c6feed8dc30ebcb3 /src/frontend/app/hooks/usePlanQuery.ts | |
| parent | ef2df90ffb195edcddd701511dc5953c7baa63af (diff) | |
Refactor route planner to use new GraphQL backend
Diffstat (limited to 'src/frontend/app/hooks/usePlanQuery.ts')
| -rw-r--r-- | src/frontend/app/hooks/usePlanQuery.ts | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/frontend/app/hooks/usePlanQuery.ts b/src/frontend/app/hooks/usePlanQuery.ts new file mode 100644 index 0000000..103f5f4 --- /dev/null +++ b/src/frontend/app/hooks/usePlanQuery.ts @@ -0,0 +1,29 @@ +import { useQuery } from "@tanstack/react-query"; +import { fetchPlan } from "../api/planner"; + +export const usePlanQuery = ( + fromLat: number | undefined, + fromLon: number | undefined, + toLat: number | undefined, + toLon: number | undefined, + time?: Date, + arriveBy: boolean = false, + enabled: boolean = true +) => { + return useQuery({ + queryKey: [ + "plan", + fromLat, + fromLon, + toLat, + toLon, + time?.toISOString(), + arriveBy, + ], + queryFn: () => + fetchPlan(fromLat!, fromLon!, toLat!, toLon!, time, arriveBy), + enabled: !!(fromLat && fromLon && toLat && toLon) && enabled, + staleTime: 60000, // 1 minute + retry: false, + }); +}; |
