29 lines
861 B
TypeScript
29 lines
861 B
TypeScript
import { useState, useEffect } from 'react';
|
|
import { pb } from '@services/pocketbase';
|
|
import type { InfrastructureNode } from '@/types/InfrastructureNode';
|
|
|
|
export const useInfrastructureNodes = () => {
|
|
const [nodes, setNodes] = useState<InfrastructureNode[]>([]);
|
|
const [isLoading, setIsLoading] = useState(true);
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
useEffect(() => {
|
|
const fetchNodes = async () => {
|
|
try {
|
|
setIsLoading(true);
|
|
const records = await pb.collection('aegis_infrastructure_nodes').getFullList<InfrastructureNode>({
|
|
sort: 'created',
|
|
});
|
|
setNodes(records);
|
|
} catch {
|
|
setError("Impossible de charger l'infrastructure.");
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
};
|
|
|
|
fetchNodes();
|
|
}, []);
|
|
|
|
return { nodes, isLoading, error };
|
|
}; |