-address fixes and changes per feedback from Matt and Brad
This commit is contained in:
@@ -8,7 +8,7 @@ const camBase = import.meta.env.MODE !== "development" ? CAM_BASE : "";
|
||||
|
||||
const getAllBlackboardData = async () => {
|
||||
const response = await fetch(`${camBase}/api/blackboard`, {
|
||||
signal: AbortSignal.timeout(500),
|
||||
signal: AbortSignal.timeout(300000),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to fetch blackboard data");
|
||||
|
||||
@@ -8,7 +8,7 @@ const fetchCameraSideConfig = async ({ queryKey }: { queryKey: string[] }) => {
|
||||
const [, cameraSide] = queryKey;
|
||||
const fetchUrl = `${base_url}/fetch-config?id=${cameraSide}`;
|
||||
const response = await fetch(fetchUrl, {
|
||||
signal: AbortSignal.timeout(500),
|
||||
signal: AbortSignal.timeout(300000),
|
||||
});
|
||||
if (!response.ok) throw new Error("cannot react cameraSide ");
|
||||
return response.json();
|
||||
|
||||
@@ -7,7 +7,7 @@ const camBase = import.meta.env.MODE !== "development" ? CAM_BASE : "";
|
||||
|
||||
const getWiFiSettings = async () => {
|
||||
const response = await fetch(`${camBase}/api/fetch-config?id=ModemAndWifiManager-wifi`, {
|
||||
signal: AbortSignal.timeout(500),
|
||||
signal: AbortSignal.timeout(300000),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error("Cannot fetch Wifi settings");
|
||||
@@ -29,7 +29,7 @@ const updateWifiSettings = async (wifiConfig: WifiConfig) => {
|
||||
|
||||
const getModemSettings = async () => {
|
||||
const response = await fetch(`${camBase}/api/fetch-config?id=ModemAndWifiManager-modem`, {
|
||||
signal: AbortSignal.timeout(500),
|
||||
signal: AbortSignal.timeout(300000),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error("Cannot fetch modem settings");
|
||||
|
||||
@@ -4,12 +4,35 @@ import type { zoomConfig, ZoomInOptions } from "../types/types";
|
||||
import { toast } from "sonner";
|
||||
import { useEffect } from "react";
|
||||
|
||||
const getCameraMode = async (options: { camera: string }) => {
|
||||
const response = await fetch(`${CAM_BASE}/api/fetch-config?id=Ip${options.camera}`);
|
||||
if (!response.ok) throw new Error("Cannot get camera mode");
|
||||
return response.json();
|
||||
};
|
||||
|
||||
const updateCameraMode = async (options: { camera: string; mode: string }) => {
|
||||
const dayNightPayload = {
|
||||
id: options.camera,
|
||||
fields: [
|
||||
{
|
||||
property: "propDayNightMode",
|
||||
value: options.mode,
|
||||
},
|
||||
],
|
||||
};
|
||||
const response = await fetch(`${CAM_BASE}/Ip${options.camera}-command?dayNightMode=${options.mode}`, {
|
||||
method: "post",
|
||||
body: JSON.stringify(dayNightPayload),
|
||||
});
|
||||
if (!response.ok) throw new Error("cannot update camera mode");
|
||||
return response.json();
|
||||
};
|
||||
|
||||
async function zoomIn(options: ZoomInOptions) {
|
||||
console.log(options);
|
||||
const response = await fetch(
|
||||
`${CAM_BASE}/Ip${options.camera}-command?magnification=${options.multiplierText?.toLowerCase()}`,
|
||||
{
|
||||
signal: AbortSignal.timeout(500),
|
||||
signal: AbortSignal.timeout(300000),
|
||||
}
|
||||
);
|
||||
if (!response.ok) {
|
||||
@@ -22,7 +45,7 @@ async function zoomIn(options: ZoomInOptions) {
|
||||
async function fetchZoomInConfig({ queryKey }: QueryFunctionContext<[string, zoomConfig]>) {
|
||||
const [, { camera }] = queryKey;
|
||||
const response = await fetch(`${CAM_BASE}/api/fetch-config?id=Ip${camera}`, {
|
||||
signal: AbortSignal.timeout(500),
|
||||
signal: AbortSignal.timeout(300000),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error("Cannot get camera zoom settings");
|
||||
@@ -34,11 +57,6 @@ export const useCameraZoom = (options: zoomConfig) => {
|
||||
const mutation = useMutation({
|
||||
mutationKey: ["zoomIn"],
|
||||
mutationFn: (options: ZoomInOptions) => zoomIn(options),
|
||||
onError: (err) => {
|
||||
toast.error(`Failed to update zoom settings: ${err.message}`, {
|
||||
id: "zoom",
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
const query = useQuery({
|
||||
@@ -52,3 +70,20 @@ export const useCameraZoom = (options: zoomConfig) => {
|
||||
|
||||
return { mutation, query };
|
||||
};
|
||||
|
||||
export const useCameraMode = (option: { camera: string }) => {
|
||||
const cameraModeQuery = useQuery({
|
||||
queryKey: ["getCameraMode"],
|
||||
queryFn: () => getCameraMode(option),
|
||||
});
|
||||
|
||||
const cameraModeMutation = useMutation({
|
||||
mutationKey: ["updateCameraMode"],
|
||||
mutationFn: updateCameraMode,
|
||||
});
|
||||
|
||||
return {
|
||||
cameraModeQuery,
|
||||
cameraModeMutation,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ const apiUrl = CAM_BASE;
|
||||
// const fetch_url = `http://100.82.205.44/Colour-preview`;
|
||||
async function fetchSnapshot(cameraSide: string) {
|
||||
const response = await fetch(`${apiUrl}/${cameraSide}-preview`, {
|
||||
signal: AbortSignal.timeout(500),
|
||||
signal: AbortSignal.timeout(300000),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error("Cannot reach endpoint");
|
||||
|
||||
@@ -8,7 +8,7 @@ import { toast } from "sonner";
|
||||
async function fetchNPEDDetails() {
|
||||
const fetchUrl = `${CAM_BASE}/api/fetch-config?id=NPED`;
|
||||
const response = await fetch(fetchUrl, {
|
||||
signal: AbortSignal.timeout(500),
|
||||
signal: AbortSignal.timeout(300000),
|
||||
});
|
||||
if (!response.ok) throw new Error("Cannot reach fetch-config endpoint");
|
||||
|
||||
|
||||
48
src/hooks/useSightingAmend.ts
Normal file
48
src/hooks/useSightingAmend.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { CAM_BASE } from "../utils/config";
|
||||
import type { InitialValuesForm } from "../types/types";
|
||||
|
||||
const getSightingAmend = async () => {
|
||||
const response = await fetch(`${CAM_BASE}/api/fetch-config?id=SightingAmmendA`);
|
||||
if (!response.ok) throw new Error("Cannot reach sighting amend endpoint");
|
||||
return response.json();
|
||||
};
|
||||
|
||||
const updateSightingAmend = async (data: InitialValuesForm) => {
|
||||
const updateSightingAmendPayload = {
|
||||
id: "SightingAmmendA",
|
||||
fields: [
|
||||
{
|
||||
property: "propOverviewQuality",
|
||||
value: data.overviewQuality,
|
||||
},
|
||||
{
|
||||
property: "propOverviewImageScaleFactor",
|
||||
value: data.cropSizeFactor,
|
||||
},
|
||||
],
|
||||
};
|
||||
const response = await fetch(`${CAM_BASE}/api/update-config?id=SightingAmmendA`, {
|
||||
method: "Post",
|
||||
body: JSON.stringify(updateSightingAmendPayload),
|
||||
});
|
||||
if (!response.ok) throw new Error("cannot update camera control");
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const useSightingAmend = () => {
|
||||
const sightingAmendQuery = useQuery({
|
||||
queryKey: ["getSightingAmend"],
|
||||
queryFn: getSightingAmend,
|
||||
});
|
||||
|
||||
const sightingAmendMutation = useMutation({
|
||||
mutationKey: ["updateSightingAmend"],
|
||||
mutationFn: updateSightingAmend,
|
||||
});
|
||||
|
||||
return {
|
||||
sightingAmendQuery,
|
||||
sightingAmendMutation,
|
||||
};
|
||||
};
|
||||
@@ -12,7 +12,7 @@ import { useCachedSoundSrc } from "./usecachedSoundSrc";
|
||||
|
||||
async function fetchSighting(url: string | undefined, ref: number): Promise<SightingType> {
|
||||
const res = await fetch(`${url}${ref}`, {
|
||||
signal: AbortSignal.timeout(5000),
|
||||
signal: AbortSignal.timeout(300000),
|
||||
});
|
||||
if (!res.ok) throw new Error(String(res.status));
|
||||
return res.json();
|
||||
@@ -48,7 +48,7 @@ export function useSightingFeed(url: string | undefined) {
|
||||
return 100;
|
||||
}
|
||||
|
||||
if (now - lastValidTimestamp.current > 60_000) {
|
||||
if (now - lastValidTimestamp.current > 600_000) {
|
||||
currentRef.current = -1;
|
||||
lastValidTimestamp.current = now;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user