From 7d0a705eee721bb6b45535ccda9cfe020e0e42ba Mon Sep 17 00:00:00 2001 From: Denys Konovalov Date: Tue, 2 May 2023 18:34:15 +0200 Subject: [PATCH] fix: draft folders (#772) --- packages/core/src/lib/hooks/useMediaFiles.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/core/src/lib/hooks/useMediaFiles.ts b/packages/core/src/lib/hooks/useMediaFiles.ts index cf4f8e39..36d085b4 100644 --- a/packages/core/src/lib/hooks/useMediaFiles.ts +++ b/packages/core/src/lib/hooks/useMediaFiles.ts @@ -1,6 +1,6 @@ -import trim from 'lodash/trim'; import { basename, dirname } from 'path'; import { useEffect, useMemo, useState } from 'react'; +import trim from 'lodash/trim'; import { currentBackend } from '@staticcms/core/backend'; import { selectCollection } from '@staticcms/core/reducers/selectors/collections'; @@ -41,12 +41,17 @@ export default function useMediaFiles(field?: MediaField, currentFolder?: string let alive = true; const getMediaFiles = async () => { + if (entry.mediaFiles.find(f => dirname(f.path) == currentFolder)?.draft) { + setCurrentFolderMediaFiles([]); + return; + } + const { media_folder, public_folder } = config ?? {}; const backend = currentBackend(config); const files = await backend.getMedia( currentFolder, folderSupport, - config.public_folder - ? trim(currentFolder, '/').replace(trim(config.media_folder!), config.public_folder) + public_folder + ? trim(currentFolder, '/').replace(trim(media_folder, '/'), public_folder) : currentFolder, ); @@ -60,7 +65,7 @@ export default function useMediaFiles(field?: MediaField, currentFolder?: string return () => { alive = false; }; - }, [currentFolder, config, entry, field, collection, folderSupport]); + }, [currentFolder, config, entry, folderSupport]); const files = useMemo(() => { if (entry) {