fix: loading media on new entry
This commit is contained in:
@ -18,6 +18,7 @@ import {
|
|||||||
persistLocalBackup,
|
persistLocalBackup,
|
||||||
retrieveLocalBackup,
|
retrieveLocalBackup,
|
||||||
} from '@staticcms/core/actions/entries';
|
} from '@staticcms/core/actions/entries';
|
||||||
|
import { loadMedia } from '@staticcms/core/actions/mediaLibrary';
|
||||||
import { loadScroll, toggleScroll } from '@staticcms/core/actions/scroll';
|
import { loadScroll, toggleScroll } from '@staticcms/core/actions/scroll';
|
||||||
import { selectFields } from '@staticcms/core/lib/util/collection.util';
|
import { selectFields } from '@staticcms/core/lib/util/collection.util';
|
||||||
import { useWindowEvent } from '@staticcms/core/lib/util/window.util';
|
import { useWindowEvent } from '@staticcms/core/lib/util/window.util';
|
||||||
@ -113,7 +114,8 @@ const Editor: FC<TranslatedProps<EditorProps>> = ({
|
|||||||
navigate(`/collections/${collection.name}/new`, { replace: true });
|
navigate(`/collections/${collection.name}/new`, { replace: true });
|
||||||
} else {
|
} else {
|
||||||
setSubmitted(false);
|
setSubmitted(false);
|
||||||
setTimeout(() => {
|
setTimeout(async () => {
|
||||||
|
await dispatch(loadMedia());
|
||||||
dispatch(createEmptyDraft(collection, location.search));
|
dispatch(createEmptyDraft(collection, location.search));
|
||||||
setVersion(version + 1);
|
setVersion(version + 1);
|
||||||
navigate(`/collections/${collection.name}/new`, { replace: true });
|
navigate(`/collections/${collection.name}/new`, { replace: true });
|
||||||
@ -212,7 +214,8 @@ const Editor: FC<TranslatedProps<EditorProps>> = ({
|
|||||||
const [prevSlug, setPrevSlug] = useState<string | undefined | null>(null);
|
const [prevSlug, setPrevSlug] = useState<string | undefined | null>(null);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (newRecord && slug !== prevSlug) {
|
if (newRecord && slug !== prevSlug) {
|
||||||
setTimeout(() => {
|
setTimeout(async () => {
|
||||||
|
await dispatch(loadMedia());
|
||||||
dispatch(createEmptyDraft(collection, location.search));
|
dispatch(createEmptyDraft(collection, location.search));
|
||||||
});
|
});
|
||||||
} else if (!newRecord && slug && (prevCollection !== collection || prevSlug !== slug)) {
|
} else if (!newRecord && slug && (prevCollection !== collection || prevSlug !== slug)) {
|
||||||
|
@ -275,12 +275,10 @@ export function selectFieldsWithMediaFolders<EF extends BaseField>(
|
|||||||
if ('folder' in collection) {
|
if ('folder' in collection) {
|
||||||
const fields = collection.fields;
|
const fields = collection.fields;
|
||||||
return getFieldsWithMediaFolders(fields);
|
return getFieldsWithMediaFolders(fields);
|
||||||
} else {
|
|
||||||
const fields = getFileFromSlug(collection, slug)?.fields || [];
|
|
||||||
return getFieldsWithMediaFolders(fields);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
const fields = getFileFromSlug(collection, slug)?.fields || [];
|
||||||
|
return getFieldsWithMediaFolders(fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function selectMediaFolders<EF extends BaseField>(
|
export function selectMediaFolders<EF extends BaseField>(
|
||||||
|
@ -187,8 +187,7 @@ function mediaLibrary(
|
|||||||
dynamicSearch: Boolean(dynamicSearch),
|
dynamicSearch: Boolean(dynamicSearch),
|
||||||
dynamicSearchQuery: dynamicSearchQuery ?? '',
|
dynamicSearchQuery: dynamicSearchQuery ?? '',
|
||||||
dynamicSearchActive: !!dynamicSearchQuery,
|
dynamicSearchActive: !!dynamicSearchQuery,
|
||||||
files:
|
files: page && page > 1 ? (state.files ?? []).concat(filesWithKeys) : filesWithKeys,
|
||||||
page && page > 1 ? (state.files as MediaFile[]).concat(filesWithKeys) : filesWithKeys,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user