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) { 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 state = getState();
const backend = currentBackend(state.config); const backend = currentBackend(state.config);
await waitForMediaLibraryToLoad(dispatch, getState());
dispatch(entryLoading(collection, slug)); dispatch(entryLoading(collection, slug));
return backend return backend
.getEntry(state, collection, slug) .getEntry(getState(), collection, slug)
.then((loadedEntry: EntryValue) => { .then((loadedEntry: EntryValue) => {
return dispatch(entryLoaded(collection, loadedEntry)); return dispatch(entryLoaded(collection, loadedEntry));
}) })

View File

@ -147,10 +147,8 @@ export function loadMedia(
} }
} }
dispatch(mediaLoading(page)); dispatch(mediaLoading(page));
return new Promise(resolve => {
setTimeout( const loadFunction = () =>
() =>
resolve(
backend backend
.getMedia() .getMedia()
.then(files => dispatch(mediaLoaded(files))) .then(files => dispatch(mediaLoaded(files)))
@ -162,11 +160,15 @@ export function loadMedia(
} else { } else {
dispatch(mediaLoadFailed()); dispatch(mediaLoadFailed());
} }
}),
),
delay,
);
}); });
if (delay > 0) {
return new Promise(resolve => {
setTimeout(() => resolve(loadFunction()), delay);
});
} else {
return loadFunction();
}
}; };
} }