- {storageEntries.map(([, storage]) => {
- const itemId = getStorageItemId(storage.id)
- const storageIsFolded = !sideNavOpenedItemSet.has(itemId)
- const showPromptToCreateFolder = (folderPathname: string) => {
- prompt({
- title: 'Create a Folder',
- message: 'Enter the path where do you want to create a folder',
- iconType: DialogIconTypes.Question,
- defaultValue: folderPathname === '/' ? '/' : `${folderPathname}/`,
- submitButtonLabel: 'Create Folder',
- onClose: async (value: string | null) => {
- if (value == null) {
- return
- }
- if (value.endsWith('/')) {
- value = value.slice(0, value.length - 1)
- }
- await createFolder(storage.id, value)
-
- push(`/app/storages/${storage.id}/notes${value}`)
-
- // Open folder item
- openSideNavFolderItemRecursively(storage.id, value)
- },
- })
- }
- const showPromptToRenameFolder = (folderPathname: string) => {
- prompt({
- title: t('folder.rename'),
- message: t('folder.renameMessage'),
- iconType: DialogIconTypes.Question,
- defaultValue: folderPathname.split('/').pop(),
- submitButtonLabel: t('folder.rename'),
- onClose: async (value: string | null) => {
- const folderPathSplit = folderPathname.split('/')
- if (
- value == null ||
- value === '' ||
- value === folderPathSplit.pop()
- ) {
- return
- }
- const newPathname = folderPathSplit.join('/') + '/' + value
- try {
- await renameFolder(storage.id, folderPathname, newPathname)
- push(`/app/storages/${storage.id}/notes${newPathname}`)
- openSideNavFolderItemRecursively(storage.id, newPathname)
- } catch (error) {
- pushMessage({
- title: t('general.error'),
- description: t('folder.renameErrorMessage'),
- })
- }
- },
- })
- }
-
- const allNotesPagePathname = `/app/storages/${storage.id}/notes`
- const allNotesPageIsActive = currentPathname === allNotesPagePathname
-
- const trashcanPagePathname = `/app/storages/${storage.id}/trashcan`
- const trashcanPageIsActive = currentPathname === trashcanPagePathname
-
- const attachmentsPagePathname = `/app/storages/${storage.id}/attachments`
- const attachmentsPageIsActive =
- currentPathname === attachmentsPagePathname
-
- const controlComponents = [
-
showPromptToCreateFolder('/')}
- icon={}
- />,
- ]
-
- if (storage.cloudStorage != null && user != null) {
- const cloudSync = () => {
- if (user == null) {
- pushMessage({
- title: 'No User Error',
- description: 'Please login first to sync the storage.',
- })
- }
- syncStorage(storage.id)
- }
-
- controlComponents.unshift(
- }
- />
- )
- }
-
- controlComponents.unshift(
- push(`/app/storages/${storage.id}`)}
- icon={}
- />
- )
-
- return (
-
- {
- toggleSideNavOpenedItem(itemId)
- }}
- onClick={() => {
- toggleSideNavOpenedItem(itemId)
- }}
- onContextMenu={(event) => {
- event.preventDefault()
- popup(event, [
- {
- type: MenuTypes.Normal,
- label: t('storage.rename'),
- onClick: async () => {
- prompt({
- title: `Rename "${storage.name}" storage`,
- message: t('storage.renameMessage'),
- iconType: DialogIconTypes.Question,
- defaultValue: storage.name,
- submitButtonLabel: t('storage.rename'),
- onClose: async (value: string | null) => {
- if (value == null) return
- await renameStorage(storage.id, value)
- },
- })
- },
- },
- {
- type: MenuTypes.Normal,
- label: t('storage.remove'),
- onClick: async () => {
- messageBox({
- title: `Remove "${storage.name}" storage`,
- message: t('storage.removeMessage'),
- iconType: DialogIconTypes.Warning,
- buttons: [t('storage.remove'), t('general.cancel')],
- defaultButtonIndex: 0,
- cancelButtonIndex: 1,
- onClose: (value: number | null) => {
- if (value === 0) {
- removeStorage(storage.id)
- }
- },
- })
- },
- },
- ])
- }}
- controlComponents={controlComponents}
- />
- {!storageIsFolded && (
- <>
- }
- active={allNotesPageIsActive}
- onClick={() => push(allNotesPagePathname)}
- />
-
-
- }
- active={attachmentsPageIsActive}
- onClick={() => push(attachmentsPagePathname)}
- onContextMenu={(event) => {
- event.preventDefault()
- }}
- />
- : }
- active={trashcanPageIsActive}
- onClick={() => push(trashcanPagePathname)}
- onContextMenu={(event) => {
- event.preventDefault()
- // TODO: Implement context menu(restore all notes)
- }}
- />
- >
- )}
-
- )
- })}
- {storageEntries.length === 0 && (
- {t('storage.noStorage')}
- )}
- {preferences['general.tutorials'] === 'display' && (
-
- )}
-
-
-