ui/queries: add required flash data queries

This commit is contained in:
Johannes Kirschbauer
2025-08-07 12:48:09 +02:00
parent a4b20f9167
commit 484d274c3c

View File

@@ -139,3 +139,52 @@ export const useClanListQuery = (clanURIs: string[]): ClanListQueryResult => {
})); }));
}; };
export type MachineFlashOptions = SuccessData<"get_machine_flash_options">;
export type MachineFlashOptionsQuery = UseQueryResult<MachineFlashOptions>;
export const useMachineFlashOptions = (
clanURI: string,
): MachineFlashOptionsQuery => {
const client = useApiClient();
return useQuery<MachineFlashOptions>(() => ({
queryKey: ["clans", encodeBase64(clanURI), "machine_flash_options"],
queryFn: async () => {
const call = client.fetch("get_machine_flash_options", {
flake: {
identifier: clanURI,
},
});
const result = await call.result;
if (result.status === "error") {
// todo should we create some specific error types?
console.error("Error fetching clan details:", result.errors);
throw new Error(result.errors[0].message);
}
return result.data;
},
}));
};
export type SystemStorageOptions = SuccessData<"list_system_storage_devices">;
export type SystemStorageOptionsQuery = UseQueryResult<SystemStorageOptions>;
export const useSystemStorageOptions = (): SystemStorageOptionsQuery => {
const client = useApiClient();
return useQuery<SystemStorageOptions>(() => ({
queryKey: ["system", "storage_devices"],
queryFn: async () => {
const call = client.fetch("list_system_storage_devices", {});
const result = await call.result;
if (result.status === "error") {
// todo should we create some specific error types?
console.error("Error fetching clan details:", result.errors);
throw new Error(result.errors[0].message);
}
return result.data;
},
}));
};