Properly reset loading between collections
This commit is contained in:
parent
5280909a0c
commit
d1b6a2631d
@ -85,6 +85,10 @@ const CollectionView = ({
|
||||
viewStyle,
|
||||
}: ReturnType<typeof mergeProps>) => {
|
||||
const [readyToLoad, setReadyToLoad] = useState(false);
|
||||
const [preCollection, setPreCollection] = useState(collection);
|
||||
useEffect(() => {
|
||||
setPreCollection(collection);
|
||||
}, [collection]);
|
||||
|
||||
const newEntryUrl = useMemo(() => {
|
||||
let url = collection.get('create') ? getNewEntryUrl(collectionName) : '';
|
||||
@ -108,7 +112,7 @@ const CollectionView = ({
|
||||
collection={collection}
|
||||
viewStyle={viewStyle}
|
||||
filterTerm={filterTerm}
|
||||
readyToLoad={readyToLoad}
|
||||
readyToLoad={readyToLoad && collection === preCollection}
|
||||
/>
|
||||
);
|
||||
}, [collection, filterTerm, viewStyle, readyToLoad]);
|
||||
@ -123,6 +127,11 @@ const CollectionView = ({
|
||||
}, [searchTerm, collections, collection, isSingleSearchResult]);
|
||||
|
||||
useEffect(() => {
|
||||
setReadyToLoad(false);
|
||||
let alive = true;
|
||||
|
||||
const sortEntries = () => {
|
||||
setTimeout(async () => {
|
||||
if (sort?.first()?.get('key')) {
|
||||
setReadyToLoad(true);
|
||||
return;
|
||||
@ -137,15 +146,15 @@ const CollectionView = ({
|
||||
return;
|
||||
}
|
||||
|
||||
let alive = true;
|
||||
const sortEntries = async () => {
|
||||
await onSortClick(
|
||||
defaultSort.get('field'),
|
||||
defaultSort.get('direction') ?? SortDirection.Ascending,
|
||||
);
|
||||
|
||||
if (alive) {
|
||||
setReadyToLoad(true);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
sortEntries();
|
||||
|
Loading…
x
Reference in New Issue
Block a user