generated from Dicken/dickendock
Commit 6: Adminbereich (TanStack Router, 8 Menüpunkte, Scan-Logs)
This commit is contained in:
21
apps/frontend/src/hooks/useDevices.ts
Normal file
21
apps/frontend/src/hooks/useDevices.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import type { Device, Service } from "@launchpad/shared";
|
||||
|
||||
export interface DeviceWithServices extends Device {
|
||||
services: Service[];
|
||||
}
|
||||
|
||||
async function fetchDevices(): Promise<DeviceWithServices[]> {
|
||||
const res = await fetch("/api/devices");
|
||||
if (!res.ok) {
|
||||
throw new Error(`Geräte konnten nicht geladen werden (HTTP ${res.status})`);
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export function useDevices() {
|
||||
return useQuery({
|
||||
queryKey: ["devices"],
|
||||
queryFn: fetchDevices,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user