fix: media library on reload (#3174)
This commit is contained in:
parent
b579489525
commit
4f5544287f
@ -313,12 +313,13 @@ export function deleteLocalBackup(collection: Collection, slug: string) {
|
||||
*/
|
||||
|
||||
export function loadEntry(collection: Collection, slug: string) {
|
||||
return (dispatch: ThunkDispatch<State, {}, AnyAction>, getState: () => State) => {
|
||||
return async (dispatch: ThunkDispatch<State, {}, AnyAction>, getState: () => State) => {
|
||||
const state = getState();
|
||||
const backend = currentBackend(state.config);
|
||||
await waitForMediaLibraryToLoad(dispatch, getState());
|
||||
dispatch(entryLoading(collection, slug));
|
||||
return backend
|
||||
.getEntry(state, collection, slug)
|
||||
.getEntry(getState(), collection, slug)
|
||||
.then((loadedEntry: EntryValue) => {
|
||||
return dispatch(entryLoaded(collection, loadedEntry));
|
||||
})
|
||||
|
@ -147,26 +147,28 @@ export function loadMedia(
|
||||
}
|
||||
}
|
||||
dispatch(mediaLoading(page));
|
||||
return new Promise(resolve => {
|
||||
setTimeout(
|
||||
() =>
|
||||
resolve(
|
||||
backend
|
||||
.getMedia()
|
||||
.then(files => dispatch(mediaLoaded(files)))
|
||||
.catch((error: { status?: number }) => {
|
||||
console.error(error);
|
||||
if (error.status === 404) {
|
||||
console.log('This 404 was expected and handled appropriately.');
|
||||
dispatch(mediaLoaded([]));
|
||||
} else {
|
||||
dispatch(mediaLoadFailed());
|
||||
}
|
||||
}),
|
||||
),
|
||||
delay,
|
||||
);
|
||||
});
|
||||
|
||||
const loadFunction = () =>
|
||||
backend
|
||||
.getMedia()
|
||||
.then(files => dispatch(mediaLoaded(files)))
|
||||
.catch((error: { status?: number }) => {
|
||||
console.error(error);
|
||||
if (error.status === 404) {
|
||||
console.log('This 404 was expected and handled appropriately.');
|
||||
dispatch(mediaLoaded([]));
|
||||
} else {
|
||||
dispatch(mediaLoadFailed());
|
||||
}
|
||||
});
|
||||
|
||||
if (delay > 0) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => resolve(loadFunction()), delay);
|
||||
});
|
||||
} else {
|
||||
return loadFunction();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user