From 484d274c3c67a3e7319443db8f462a78a8cd2340 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Thu, 7 Aug 2025 12:48:09 +0200 Subject: [PATCH] ui/queries: add required flash data queries --- pkgs/clan-app/ui/src/hooks/queries.ts | 49 +++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/pkgs/clan-app/ui/src/hooks/queries.ts b/pkgs/clan-app/ui/src/hooks/queries.ts index a73a12951..38cb37dd6 100644 --- a/pkgs/clan-app/ui/src/hooks/queries.ts +++ b/pkgs/clan-app/ui/src/hooks/queries.ts @@ -139,3 +139,52 @@ export const useClanListQuery = (clanURIs: string[]): ClanListQueryResult => { })); }; +export type MachineFlashOptions = SuccessData<"get_machine_flash_options">; +export type MachineFlashOptionsQuery = UseQueryResult; + +export const useMachineFlashOptions = ( + clanURI: string, +): MachineFlashOptionsQuery => { + const client = useApiClient(); + return useQuery(() => ({ + 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; + +export const useSystemStorageOptions = (): SystemStorageOptionsQuery => { + const client = useApiClient(); + return useQuery(() => ({ + 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; + }, + })); +};