r- efactored reboots api to use useMutation for maintainability and readability.

- updated zoom debug
This commit is contained in:
2025-10-07 09:56:24 +01:00
parent a4e1e6e16f
commit b18d4272ec
5 changed files with 65 additions and 22 deletions

View File

@@ -6,6 +6,7 @@ import {
import { CAM_BASE } from "../utils/config";
import type { zoomConfig, ZoomInOptions } from "../types/types";
import { toast } from "sonner";
import { useEffect } from "react";
async function zoomIn(options: ZoomInOptions) {
const response = await fetch(
@@ -38,8 +39,10 @@ export const useCameraZoom = (options: zoomConfig) => {
const mutation = useMutation({
mutationKey: ["zoomIn"],
mutationFn: (options: ZoomInOptions) => zoomIn(options),
onError: () => {
toast.error("Failed to update zoom settings", { id: "zoom" });
onError: (err) => {
toast.error(`Failed to update zoom settings: ${err.message}`, {
id: "zoom",
});
},
});
@@ -47,5 +50,10 @@ export const useCameraZoom = (options: zoomConfig) => {
queryKey: ["fetchZoomInConfig", options],
queryFn: fetchZoomInConfig,
});
useEffect(() => {
if (query.isError) toast.error(query.error.message, { id: "hardReboot" });
}, [query?.error?.message, query.isError]);
return { mutation, query };
};