modifs complete

This commit is contained in:
Biqoz
2025-11-27 13:58:47 +01:00
parent 5b8b3c84c9
commit 73f97919ac
12 changed files with 931 additions and 524 deletions

View File

@@ -7,6 +7,7 @@ interface UseCollectionOptions {
limit?: number;
filter?: Record<string, unknown>;
search?: string;
referent?: string;
}
interface CollectionResponse<T> {
@@ -27,7 +28,7 @@ export function useCollection<T = Record<string, unknown>>(
const [total, setTotal] = useState(0);
const [totalPages, setTotalPages] = useState(0);
const { page = 1, limit = 20, filter = {}, search } = options;
const { page = 1, limit = 20, filter = {}, search, referent } = options;
// Mémoriser la chaîne JSON du filtre pour éviter les re-renders inutiles
const filterString = useMemo(() => JSON.stringify(filter), [filter]);
@@ -43,6 +44,9 @@ export function useCollection<T = Record<string, unknown>>(
if (search) {
params.append("search", search);
}
if (referent) {
params.append("referent", referent);
}
const response = await fetch(
`/api/collections/${collectionName}?${params}`
@@ -59,7 +63,7 @@ export function useCollection<T = Record<string, unknown>>(
} finally {
setLoading(false);
}
}, [collectionName, page, limit, filterString, search]);
}, [collectionName, page, limit, filterString, search, referent]);
useEffect(() => {
fetchData();