Skip to content

Commit cbea0bb

Browse files
committed
Separate new button of workspace nav item
1 parent 1e9e78a commit cbea0bb

File tree

2 files changed

+45
-38
lines changed

2 files changed

+45
-38
lines changed

src/components/atoms/NavigatorItem.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ const Container = styled.div`
2020
opacity: 1;
2121
}
2222
}
23+
24+
&.visibleControl {
25+
.control {
26+
opacity: 1;
27+
}
28+
}
2329
`
2430

2531
const FoldButton = styled.button`
@@ -106,6 +112,7 @@ interface NavigatorItemProps {
106112
iconPath?: string
107113
depth: number
108114
control?: React.ReactNode
115+
visibleControl?: boolean
109116
className?: string
110117
folded?: boolean
111118
active?: boolean
@@ -124,6 +131,7 @@ const NavigatorItem = ({
124131
iconPath,
125132
depth,
126133
control,
134+
visibleControl = false,
127135
className,
128136
folded,
129137
active,
@@ -138,7 +146,11 @@ const NavigatorItem = ({
138146
}: NavigatorItemProps) => {
139147
return (
140148
<Container
141-
className={cc([className, active && 'active'])}
149+
className={cc([
150+
className,
151+
active && 'active',
152+
visibleControl && 'visibleControl',
153+
])}
142154
onContextMenu={onContextMenu}
143155
onDrop={onDrop}
144156
onDragOver={onDragOver}

src/components/molecules/StorageNavigatorFragment.tsx

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {
1313
mdiPaperclip,
1414
mdiBookOpen,
1515
mdiSync,
16-
mdiPlus,
16+
mdiTextBoxPlusOutline,
17+
mdiFolderMultiplePlusOutline,
1718
} from '@mdi/js'
1819
import FolderNavigatorFragment from './FolderNavigatorFragment'
1920
import TagListFragment from './TagListFragment'
@@ -155,23 +156,27 @@ const StorageNavigatorFragment = ({
155156
const attachmentsPagePathname = `/app/storages/${storage.id}/attachments`
156157
const attachmentsPageIsActive = routeParams.name === 'storages.attachments'
157158

159+
const createNewNoteInRootFolder = useCallback(() => {
160+
createNoteInFolderAndRedirect('/')
161+
}, [createNoteInFolderAndRedirect])
162+
163+
const createNewFolderInRootFolder = useCallback(() => {
164+
showPromptToCreateFolder('/')
165+
}, [showPromptToCreateFolder])
166+
158167
const openWorkspaceContextMenu: MouseEventHandler = useCallback(
159168
(event) => {
160169
event.preventDefault()
161170
const contentMenuItems: MenuItemConstructorOptions[] = [
162171
{
163172
type: 'normal',
164173
label: 'New Note',
165-
click: async () => {
166-
createNoteInFolderAndRedirect('/')
167-
},
174+
click: createNewNoteInRootFolder,
168175
},
169176
{
170177
type: 'normal',
171178
label: t('folder.create'),
172-
click: async () => {
173-
showPromptToCreateFolder('/')
174-
},
179+
click: createNewFolderInRootFolder,
175180
},
176181
]
177182

@@ -188,7 +193,7 @@ const StorageNavigatorFragment = ({
188193
submitButtonLabel: t('storage.rename'),
189194
onClose: async (value: string | null) => {
190195
if (value == null) return
191-
await renameStorage(storage.id, value)
196+
renameStorage(storage.id, value)
192197
},
193198
})
194199
},
@@ -242,8 +247,8 @@ const StorageNavigatorFragment = ({
242247
storage,
243248
prompt,
244249
messageBox,
245-
createNoteInFolderAndRedirect,
246-
showPromptToCreateFolder,
250+
createNewNoteInRootFolder,
251+
createNewFolderInRootFolder,
247252
sync,
248253
t,
249254
push,
@@ -252,31 +257,6 @@ const StorageNavigatorFragment = ({
252257
]
253258
)
254259

255-
const openNewContextMenu: MouseEventHandler = useCallback(
256-
(event) => {
257-
event.preventDefault()
258-
openContextMenu({
259-
menuItems: [
260-
{
261-
type: 'normal',
262-
label: 'New Note',
263-
click: async () => {
264-
createNoteInFolderAndRedirect('/')
265-
},
266-
},
267-
{
268-
type: 'normal',
269-
label: 'New Folder',
270-
click: async () => {
271-
showPromptToCreateFolder('/')
272-
},
273-
},
274-
],
275-
})
276-
},
277-
[createNoteInFolderAndRedirect, showPromptToCreateFolder]
278-
)
279-
280260
const attachments = useMemo(() => Object.values(storage.attachmentMap), [
281261
storage.attachmentMap,
282262
])
@@ -287,6 +267,10 @@ const StorageNavigatorFragment = ({
287267

288268
const syncing = storage.type !== 'fs' && storage.sync != null
289269

270+
const folded = useMemo(() => {
271+
return !sideNavOpenedItemSet.has(rootFolderNavId)
272+
}, [sideNavOpenedItemSet, rootFolderNavId])
273+
290274
return (
291275
<>
292276
<NavigatorItem
@@ -296,13 +280,24 @@ const StorageNavigatorFragment = ({
296280
active={rootFolderIsActive}
297281
onClick={() => push(rootFolderPathname)}
298282
onContextMenu={openWorkspaceContextMenu}
299-
folded={!sideNavOpenedItemSet.has(rootFolderNavId)}
283+
folded={folded}
284+
visibleControl={true}
300285
onFoldButtonClick={() => {
301286
toggleSideNavOpenedItem(rootFolderNavId)
302287
}}
303288
control={
304289
<>
305-
<NavigatorButton onClick={openNewContextMenu} iconPath={mdiPlus} />
290+
<NavigatorButton
291+
onClick={createNewNoteInRootFolder}
292+
iconPath={mdiTextBoxPlusOutline}
293+
title='New Note'
294+
/>
295+
<NavigatorButton
296+
onClick={createNewFolderInRootFolder}
297+
iconPath={mdiFolderMultiplePlusOutline}
298+
title='New Folder'
299+
/>
300+
306301
{storage.type !== 'fs' && storage.cloudStorage != null && (
307302
<NavigatorButton
308303
active={syncing}

0 commit comments

Comments
 (0)