add useDocuments and load saved documents in DocumentsVault

This commit is contained in:
LathanDevers
2026-07-31 21:37:56 +02:00
parent c7389d747b
commit 6b93d21d19
16 changed files with 280 additions and 294 deletions
+31
View File
@@ -0,0 +1,31 @@
import { useState, useEffect, useCallback } from 'react';
import { pb } from '@/services/pocketbase';
import type { Document } from '@/types/Document';
export const useDocuments = () => {
const [documents, setDocuments] = useState<Document[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const fetchDocuments = useCallback(async () => {
setIsLoading(true);
setError(null);
try {
const records = await pb.collection('aegis_documents_vault').getFullList<Document>({
sort: '-created', // Du plus récent au plus ancien
});
setDocuments(records);
} catch (err) {
console.error("Erreur lors de la récupération des documents :", err);
setError("Impossible de charger les documents.");
} finally {
setIsLoading(false);
}
}, []);
useEffect(() => {
fetchDocuments();
}, [fetchDocuments]);
return { documents, isLoading, error, refetch: fetchDocuments };
};