Add camera zoom functionality and refactor blackboard data fetching

- Introduced `useCameraZoom` hook for managing camera zoom operations.
- Refactored `useCameraBlackboard` to improve data fetching function naming.
- Updated `CameraSettingFields` to utilize new zoom functionality and handle zoom level changes.
- Removed unnecessary console logs from `Dashboard`.
This commit is contained in:
2025-10-01 10:59:10 +01:00
parent 3903ff1cb8
commit 6f2bc96ac7
5 changed files with 60 additions and 9 deletions

View File

@@ -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({

View File

@@ -0,0 +1,22 @@
import { useMutation } from "@tanstack/react-query";
import { CAM_BASE } from "../utils/config";
import type { 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");
}
return;
}
export const useCameraZoom = () => {
const mutation = useMutation({
mutationKey: ["zoomIn"],
mutationFn: (options: ZoomInOptions) => zoomIn(options),
});
return { mutation };
};