aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/app/hooks/usePlanQuery.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend/app/hooks/usePlanQuery.ts')
-rw-r--r--src/frontend/app/hooks/usePlanQuery.ts29
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,
+ });
+};