WIP wifi modem settings

This commit is contained in:
2025-10-02 22:53:38 +01:00
parent e11d914c5e
commit 054b0bf4ea
6 changed files with 174 additions and 70 deletions

View 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,
};
};