fix: media library on reload (#3174)

This commit is contained in:
Bartholomew 2020-02-03 13:33:09 +01:00 committed by GitHub
parent b579489525
commit 4f5544287f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 22 deletions

View File

@ -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));
})

View File

@ -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();
}
};
}