resolved conflicts from develop
This commit is contained in:
@@ -2,7 +2,7 @@ import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { CAM_BASE } from "../utils/config";
|
||||
import type { CameraBlackBoardOptions } from "../types/types";
|
||||
|
||||
const getBlackboardData = async () => {
|
||||
const getAllBlackboardData = async () => {
|
||||
const response = await fetch(`${CAM_BASE}/api/blackboard`);
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to fetch blackboard data");
|
||||
@@ -25,7 +25,7 @@ const viewBlackboardData = async (options: CameraBlackBoardOptions) => {
|
||||
export const useCameraBlackboard = () => {
|
||||
const query = useQuery({
|
||||
queryKey: ["cameraBlackboard"],
|
||||
queryFn: getBlackboardData,
|
||||
queryFn: getAllBlackboardData,
|
||||
});
|
||||
|
||||
const mutation = useMutation({
|
||||
|
||||
83
src/hooks/useCameraWifiandModem.ts
Normal file
83
src/hooks/useCameraWifiandModem.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import { useQuery, useMutation } from "@tanstack/react-query";
|
||||
import { CAM_BASE } from "../utils/config";
|
||||
import type { ModemConfig, WifiConfig } from "../types/types";
|
||||
|
||||
const getWiFiSettings = async () => {
|
||||
const response = await fetch(
|
||||
`${CAM_BASE}/api/fetch-config?id=ModemAndWifiManager-wifi`
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error("Cannot fetch Wifi settings");
|
||||
}
|
||||
return response.json();
|
||||
};
|
||||
|
||||
const updateWifiSettings = async (wifiConfig: WifiConfig) => {
|
||||
const response = await fetch(
|
||||
`${CAM_BASE}/api/update-config?id=ModemAndWifiManager-wifi`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(wifiConfig),
|
||||
}
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error("Cannot update wifi settings");
|
||||
}
|
||||
return response.json();
|
||||
};
|
||||
|
||||
const getModemSettings = async () => {
|
||||
const response = await fetch(
|
||||
`${CAM_BASE}/api/fetch-config?id=ModemAndWifiManager-modem`
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error("Cannot fetch modem settings");
|
||||
}
|
||||
return response.json();
|
||||
};
|
||||
|
||||
const updateModemSettings = async (modemConfig: ModemConfig) => {
|
||||
const response = await fetch(
|
||||
`${CAM_BASE}/api/update-config?id=ModemAndWifiManager-modem`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(modemConfig),
|
||||
}
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error("cannot update modem settings");
|
||||
}
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const useWifiAndModem = () => {
|
||||
const wifiQuery = useQuery({
|
||||
queryKey: ["getWifiSettings"],
|
||||
queryFn: getWiFiSettings,
|
||||
});
|
||||
|
||||
const wifiMutation = useMutation({
|
||||
mutationKey: ["updateWifiSettings"],
|
||||
mutationFn: (wifiConfig: WifiConfig) => updateWifiSettings(wifiConfig),
|
||||
onError: (error) => console.log(error),
|
||||
});
|
||||
|
||||
const modemQuery = useQuery({
|
||||
queryKey: ["getModemSettings"],
|
||||
queryFn: getModemSettings,
|
||||
});
|
||||
|
||||
const modemMutation = useMutation({
|
||||
mutationKey: ["updateModemSettings"],
|
||||
mutationFn: (modemConfig: ModemConfig) => updateModemSettings(modemConfig),
|
||||
});
|
||||
|
||||
return {
|
||||
wifiQuery,
|
||||
wifiMutation,
|
||||
modemQuery,
|
||||
modemMutation,
|
||||
};
|
||||
};
|
||||
44
src/hooks/useCameraZoom.ts
Normal file
44
src/hooks/useCameraZoom.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import {
|
||||
useMutation,
|
||||
useQuery,
|
||||
type QueryFunctionContext,
|
||||
} from "@tanstack/react-query";
|
||||
import { CAM_BASE } from "../utils/config";
|
||||
import type { zoomConfig, ZoomInOptions } from "../types/types";
|
||||
|
||||
async function zoomIn(options: ZoomInOptions) {
|
||||
const response = await fetch(
|
||||
`${CAM_BASE}/Ip${options.camera}-command?magnification=${options.multiplier}x`
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error("Cannot reach camera zoom endpoint");
|
||||
}
|
||||
const data = await response.json();
|
||||
console.log(data);
|
||||
return;
|
||||
}
|
||||
|
||||
async function fetchZoomInConfig({
|
||||
queryKey,
|
||||
}: QueryFunctionContext<[string, zoomConfig]>) {
|
||||
const [, { camera }] = queryKey;
|
||||
console.log(camera);
|
||||
const response = await fetch(`${CAM_BASE}/Ip${camera}-inspect`);
|
||||
if (!response.ok) {
|
||||
throw new Error("Cannot get camera zoom settings");
|
||||
}
|
||||
return response.text();
|
||||
}
|
||||
//change to string
|
||||
export const useCameraZoom = (options: zoomConfig) => {
|
||||
const mutation = useMutation({
|
||||
mutationKey: ["zoomIn"],
|
||||
mutationFn: (options: ZoomInOptions) => zoomIn(options),
|
||||
});
|
||||
|
||||
const query = useQuery({
|
||||
queryKey: ["fetchZoomInConfig", options],
|
||||
queryFn: fetchZoomInConfig,
|
||||
});
|
||||
return { mutation, query };
|
||||
};
|
||||
Reference in New Issue
Block a user