
diff --git a/src/hooks/useCameraBlackboard.ts b/src/hooks/useCameraBlackboard.ts
index d8cd31b..81c16a8 100644
--- a/src/hooks/useCameraBlackboard.ts
+++ b/src/hooks/useCameraBlackboard.ts
@@ -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({
diff --git a/src/hooks/useCameraWifiandModem.ts b/src/hooks/useCameraWifiandModem.ts
new file mode 100644
index 0000000..d501a6b
--- /dev/null
+++ b/src/hooks/useCameraWifiandModem.ts
@@ -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,
+ };
+};
diff --git a/src/hooks/useCameraZoom.ts b/src/hooks/useCameraZoom.ts
new file mode 100644
index 0000000..772ab62
--- /dev/null
+++ b/src/hooks/useCameraZoom.ts
@@ -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 };
+};
diff --git a/src/pages/FrontCamera.tsx b/src/pages/FrontCamera.tsx
index daa5214..dee68c6 100644
--- a/src/pages/FrontCamera.tsx
+++ b/src/pages/FrontCamera.tsx
@@ -2,18 +2,9 @@ import { useState } from "react";
import CameraSettings from "../components/CameraSettings/CameraSettings";
import OverviewVideoContainer from "../components/FrontCameraSettings/OverviewVideoContainer";
import { Toaster } from "sonner";
-import type { ZoomLevel } from "../types/types";
const FrontCamera = () => {
- const [zoomLevel, setZoomLevel] = useState
({
- left: 0,
- top: 0,
- x: 0,
- y: 0,
- px: 0,
- py: 0,
- level: 1,
- });
+ const [zoomLevel, setZoomLevel] = useState(1);
return (