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