From af4b00408a4c4f8a83edbd5f3764090e1718815f Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Fri, 8 Aug 2025 21:01:24 +0200 Subject: [PATCH] UI/queries: add machine hw query --- pkgs/clan-app/ui/src/hooks/queries.ts | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/pkgs/clan-app/ui/src/hooks/queries.ts b/pkgs/clan-app/ui/src/hooks/queries.ts index 83d6cd14c..b276f826d 100644 --- a/pkgs/clan-app/ui/src/hooks/queries.ts +++ b/pkgs/clan-app/ui/src/hooks/queries.ts @@ -182,3 +182,43 @@ export const useSystemStorageOptions = (): SystemStorageOptionsQuery => { }, })); }; + +export type MachineHardwareSummary = + SuccessData<"get_machine_hardware_summary">; +export type MachineHardwareSummaryQuery = + UseQueryResult; + +export const useMachineHardwareSummary = ( + clanUri: string, + machineName: string, +): MachineHardwareSummaryQuery => { + const client = useApiClient(); + return useQuery(() => ({ + queryKey: [ + "clans", + encodeBase64(clanUri), + "machines", + machineName, + "hardware_summary", + ], + queryFn: async () => { + const call = client.fetch("get_machine_hardware_summary", { + machine: { + flake: { + identifier: clanUri, + }, + name: machineName, + }, + }); + 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; + }, + })); +};