From a433510f059509567475972578f1048bd7b3bb69 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Sun, 1 Feb 2026 04:39:22 +0100 Subject: [PATCH] Add folder child count and empty check logic in App.tsx --- src/App.tsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/App.tsx b/src/App.tsx index 525af91..6ee70cb 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -308,6 +308,24 @@ export default function App() { return map; }, [folders, hasSearch, texts, visibleFolderIds]); + const folderChildCount = useMemo(() => { + const counts = new Map(); + for (const folder of folders) { + if (!folder.parent_id) continue; + counts.set(folder.parent_id, (counts.get(folder.parent_id) ?? 0) + 1); + } + for (const text of texts) { + if (!text.folder_id) continue; + counts.set(text.folder_id, (counts.get(text.folder_id) ?? 0) + 1); + } + return counts; + }, [folders, texts]); + + const isFolderEmpty = useCallback( + (folderId: string) => (folderChildCount.get(folderId) ?? 0) === 0, + [folderChildCount] + ); + const handleMarkdownPreviewClick = useCallback( (event: React.MouseEvent) => { const target = event.target as HTMLElement | null;