29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
|
|
import { useQuery } from "@tanstack/react-query";
|
||
|
|
import { CAMBASE } from "../../../utils/config";
|
||
|
|
|
||
|
|
const fetchEntrySightings = async (cameraFeedID: string) => {
|
||
|
|
const response = await fetch(`${CAMBASE}/EntrySightingCreator${cameraFeedID}-list-proto-sightings`);
|
||
|
|
if (!response.ok) throw new Error("Cannot reach sighing entry endpoint");
|
||
|
|
return response.json();
|
||
|
|
};
|
||
|
|
|
||
|
|
const fetchExitSightings = async (cameraFeedID: string) => {
|
||
|
|
const response = await fetch(`${CAMBASE}/ExitSightingCreator${cameraFeedID}-list-proto-sightings`);
|
||
|
|
if (!response.ok) throw new Error("Cannot reach sighing exit endpoint");
|
||
|
|
return response.json();
|
||
|
|
};
|
||
|
|
|
||
|
|
export const useSightingEntryAndExit = (cameraFeedID: string) => {
|
||
|
|
const entryQuery = useQuery({
|
||
|
|
queryKey: ["Entry Sightings", cameraFeedID],
|
||
|
|
queryFn: () => fetchEntrySightings(cameraFeedID),
|
||
|
|
});
|
||
|
|
|
||
|
|
const exitQuery = useQuery({
|
||
|
|
queryKey: ["Exit Sightings", cameraFeedID],
|
||
|
|
queryFn: () => fetchExitSightings(cameraFeedID),
|
||
|
|
});
|
||
|
|
|
||
|
|
return { entryQuery, exitQuery };
|
||
|
|
};
|