WIP wifi modem settings
This commit is contained in:
45
src/hooks/useCameraWifiandModem.ts
Normal file
45
src/hooks/useCameraWifiandModem.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { useQuery, useMutation } from "@tanstack/react-query";
|
||||
import { CAM_BASE } from "../utils/config";
|
||||
import type { 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();
|
||||
};
|
||||
|
||||
export const useWifiAndModem = () => {
|
||||
const wifiQuery = useQuery({
|
||||
queryKey: ["getWifiSettings"],
|
||||
queryFn: getWiFiSettings,
|
||||
});
|
||||
|
||||
const wifiMutation = useMutation({
|
||||
mutationKey: ["updateWifiSettings"],
|
||||
mutationFn: (wifiConfig: WifiConfig) => updateWifiSettings(wifiConfig),
|
||||
});
|
||||
|
||||
return {
|
||||
wifiQuery,
|
||||
wifiMutation,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user