From 74e06ecc5cd9e484fc775437b931717aa53ec733 Mon Sep 17 00:00:00 2001 From: Daniel Lautzenheiser Date: Fri, 14 Apr 2023 14:06:14 -0400 Subject: [PATCH] fix: copy media_library settings for markdown widgets, do not show directories if folder support is off --- packages/core/src/actions/config.ts | 2 +- packages/core/src/lib/hooks/useMediaFiles.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/core/src/actions/config.ts b/packages/core/src/actions/config.ts index dee13f7e..ea33245f 100644 --- a/packages/core/src/actions/config.ts +++ b/packages/core/src/actions/config.ts @@ -61,7 +61,7 @@ const setFieldDefaults = 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 = { ...((collectionFile ?? collection).media_library ?? {}), ...(field.media_library ?? {}), diff --git a/packages/core/src/lib/hooks/useMediaFiles.ts b/packages/core/src/lib/hooks/useMediaFiles.ts index fa147dea..cda01e25 100644 --- a/packages/core/src/lib/hooks/useMediaFiles.ts +++ b/packages/core/src/lib/hooks/useMediaFiles.ts @@ -31,6 +31,7 @@ export default function useMediaFiles(field?: MediaField, currentFolder?: string ); const folderSupport = useFolderSupport({ config, collection, collectionFile, field }); + console.log('FOLDER_SUPPORT', folderSupport); useEffect(() => { if (!currentFolder || !config || !entry) { @@ -105,5 +106,8 @@ export default function useMediaFiles(field?: MediaField, currentFolder?: string return mediaLibraryFiles ?? []; }, [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], + ); }