r- efactored reboots api to use useMutation for maintainability and readability.
- updated zoom debug
This commit is contained in:
@@ -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 };
|
||||
};
|
||||
|
||||
35
src/hooks/useReboots.ts
Normal file
35
src/hooks/useReboots.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { CAM_BASE } from "../utils/config";
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { toast } from "sonner";
|
||||
|
||||
async function handleSoftReboot() {
|
||||
const response = await fetch(`${CAM_BASE}/api/restart-flexiai`);
|
||||
if (!response.ok) throw new Error("Failed to Software Reboot");
|
||||
return "Software reboot triggered!";
|
||||
}
|
||||
|
||||
async function handleHardReboot() {
|
||||
const response = await fetch(`${CAM_BASE}/api/restart-hardware`);
|
||||
if (!response.ok) throw new Error("Failed to Hardware Reboot");
|
||||
return "Hardware reboot triggered!";
|
||||
}
|
||||
|
||||
export const useReboots = () => {
|
||||
const softRebootMutation = useMutation({
|
||||
mutationKey: ["softReboot"],
|
||||
mutationFn: handleSoftReboot,
|
||||
|
||||
onSuccess: () => toast.success("Software reboot triggered!"),
|
||||
onError: (error) => toast.error(error.message),
|
||||
});
|
||||
|
||||
const hardRebootMutation = useMutation({
|
||||
mutationKey: ["hardReboot"],
|
||||
mutationFn: handleHardReboot,
|
||||
|
||||
onSuccess: () => toast.success("Harware reboot triggered!"),
|
||||
onError: (error) => toast.error(error.message),
|
||||
});
|
||||
|
||||
return { softRebootMutation, hardRebootMutation };
|
||||
};
|
||||
Reference in New Issue
Block a user