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:
@@ -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({
|
||||
|
||||
22
src/hooks/useCameraZoom.ts
Normal file
22
src/hooks/useCameraZoom.ts
Normal 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 };
|
||||
};
|
||||
Reference in New Issue
Block a user