fix: copy media_library settings for markdown widgets, do not show directories if folder support is off

This commit is contained in:
Daniel Lautzenheiser 2023-04-14 14:06:14 -04:00
parent c42127c261
commit 74e06ecc5c
2 changed files with 6 additions and 2 deletions

View File

@ -61,7 +61,7 @@ const setFieldDefaults =
return { ...field, public_folder: field.media_folder }; return { ...field, public_folder: field.media_folder };
} }
if (field.widget === 'image' || field.widget === 'file') { if (field.widget === 'image' || field.widget === 'file' || field.widget === 'markdown') {
field.media_library = { field.media_library = {
...((collectionFile ?? collection).media_library ?? {}), ...((collectionFile ?? collection).media_library ?? {}),
...(field.media_library ?? {}), ...(field.media_library ?? {}),

View File

@ -31,6 +31,7 @@ export default function useMediaFiles(field?: MediaField, currentFolder?: string
); );
const folderSupport = useFolderSupport({ config, collection, collectionFile, field }); const folderSupport = useFolderSupport({ config, collection, collectionFile, field });
console.log('FOLDER_SUPPORT', folderSupport);
useEffect(() => { useEffect(() => {
if (!currentFolder || !config || !entry) { if (!currentFolder || !config || !entry) {
@ -105,5 +106,8 @@ export default function useMediaFiles(field?: MediaField, currentFolder?: string
return mediaLibraryFiles ?? []; return mediaLibraryFiles ?? [];
}, [collection, config, currentFolderMediaFiles, entry, field, mediaLibraryFiles, currentFolder]); }, [collection, config, currentFolderMediaFiles, entry, field, mediaLibraryFiles, currentFolder]);
return useMemo(() => files.filter(file => file.name !== '.gitkeep'), [files]); return useMemo(
() => files.filter(file => file.name !== '.gitkeep' && (folderSupport || !file.isDirectory)),
[files, folderSupport],
);
} }