mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
38 lines
749 B
TypeScript
38 lines
749 B
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
import { type } from "arktype";
|
|
|
|
const volumesSchema = type({
|
|
volumes: type({
|
|
created_at: "string",
|
|
mountpoint: "string",
|
|
name: "string",
|
|
}).array(),
|
|
});
|
|
|
|
const getVolumes = async () => {
|
|
const response = await fetch("/api/volumes");
|
|
if (!response.ok) {
|
|
throw new Error("Network response was not ok");
|
|
}
|
|
return response.json();
|
|
};
|
|
|
|
export const useVolumes = () => {
|
|
const query = useQuery({
|
|
queryKey: ["volumes"],
|
|
queryFn: getVolumes,
|
|
select: (data) => {
|
|
const result = volumesSchema(data);
|
|
|
|
if (result instanceof type.errors) {
|
|
console.error("Volumes data validation failed:", result);
|
|
return { volumes: [] };
|
|
}
|
|
|
|
return result;
|
|
},
|
|
});
|
|
|
|
return query;
|
|
};
|