Prefetching views and favorites (#4421)

* wip

* Push

* Complete work on prefetch

* Add comment

* Fix

* Fix

* Fix

* Fix

* Remove dead code

* Simplify

* Fix tests

* Fix tests

* Fix according to review

* Fix according to review

---------

Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
This commit is contained in:
Charles Bochet
2024-03-15 18:35:40 +01:00
committed by GitHub
parent 38f28de4a6
commit afb9b3e375
21 changed files with 279 additions and 129 deletions

View File

@ -0,0 +1,27 @@
import { useRecoilValue } from 'recoil';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
import { PREFETCH_CONFIG } from '@/prefetch/constants/PrefetchConfig';
import { prefetchIsLoadedFamilyState } from '@/prefetch/states/prefetchIsLoadedFamilyState';
import { PrefetchKey } from '@/prefetch/types/PrefetchKey';
export const usePrefetchedData = <T extends ObjectRecord>(
prefetchKey: PrefetchKey,
) => {
const isDataPrefetched = useRecoilValue(
prefetchIsLoadedFamilyState(prefetchKey),
);
const prefetchQueryKey = PREFETCH_CONFIG[prefetchKey];
const { records } = useFindManyRecords<T>({
skip: !isDataPrefetched,
...prefetchQueryKey,
useRecordsWithoutConnection: true,
});
return {
isDataPrefetched,
records,
};
};