Skip to content

Commit b5940ce

Browse files
committed
Fix fold button of folder nav items
1 parent adaee4c commit b5940ce

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/components/molecules/FolderNavigatorItem.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ interface FolderNavigatorItemProps {
1616
storageId: string
1717
folderName: string
1818
depth: number
19+
noteCount?: number
1920
folderPathname: string
2021
folderSetWithSubFolders: Set<string>
2122
createNoteInFolderAndRedirect: (folderPathname: string) => void
@@ -30,6 +31,7 @@ const FolderNavigatorItem = ({
3031
storageId,
3132
folderPathname,
3233
folderSetWithSubFolders,
34+
noteCount = 0,
3335
createNoteInFolderAndRedirect,
3436
showPromptToCreateFolder,
3537
showPromptToRenameFolder,
@@ -50,10 +52,16 @@ const FolderNavigatorItem = ({
5052
}, [storageId, folderPathname])
5153

5254
const folded = useMemo(() => {
53-
return folderSetWithSubFolders.has(folderPathname)
55+
return folderSetWithSubFolders.has(folderPathname) || noteCount > 0
5456
? !sideNavOpenedItemSet.has(itemId)
5557
: undefined
56-
}, [folderPathname, itemId, folderSetWithSubFolders, sideNavOpenedItemSet])
58+
}, [
59+
folderPathname,
60+
itemId,
61+
folderSetWithSubFolders,
62+
sideNavOpenedItemSet,
63+
noteCount,
64+
])
5765

5866
const toggleFolded = useCallback(() => {
5967
toggleSideNavOpenedItem(itemId)

src/components/molecules/FolderNoteNavigatorFragment.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ const FolderNoteNavigatorFragment = ({
123123
depth={item.depth}
124124
storageId={storage.id}
125125
folderPathname={item.pathname}
126+
noteCount={item.noteCount}
126127
folderSetWithSubFolders={folderSetWithSubFolders}
127128
createNoteInFolderAndRedirect={createNoteInFolderAndRedirect}
128129
showPromptToCreateFolder={showPromptToCreateFolder}
@@ -171,6 +172,7 @@ interface FolderNavItem {
171172
type: 'folder'
172173
name: string
173174
pathname: string
175+
noteCount: number
174176
depth: number
175177
}
176178

@@ -201,13 +203,16 @@ function getOpenedFolderPathnameList(
201203
if (pathname === '/') {
202204
continue
203205
}
206+
const folderDoc = folderMap[pathname]
207+
const noteCount = folderDoc?.noteIdSet.size || 0
204208
const nameElements = pathname.split('/').slice(1)
205209
const depth = nameElements.length
206210
itemList.push({
207211
type: 'folder',
208212
pathname,
209213
name,
210214
depth,
215+
noteCount,
211216
})
212217

213218
const folderIsOpened = openItemIdSet.has(
@@ -225,7 +230,6 @@ function getOpenedFolderPathnameList(
225230
)
226231
)
227232

228-
const folderDoc = folderMap[pathname]
229233
if (folderIsOpened && folderDoc != null) {
230234
const noteIds = [...folderDoc.noteIdSet]
231235
const folderNotes = noteIds.reduce((list, noteId) => {

0 commit comments

Comments
 (0)