diff --git a/apps/web/src/components/importer/components/file-provider-handler.tsx b/apps/web/src/components/importer/components/file-provider-handler.tsx index ec2aabbfb..2269f76c0 100644 --- a/apps/web/src/components/importer/components/file-provider-handler.tsx +++ b/apps/web/src/components/importer/components/file-provider-handler.tsx @@ -25,7 +25,7 @@ import { } from "@notesnook-importer/core"; import { formatBytes } from "@notesnook/common"; import { ScrollContainer } from "@notesnook/ui"; -import { Button, Flex, Input, Text } from "@theme-ui/components"; +import { Button, Flex, Input, Switch, Text } from "@theme-ui/components"; import { xxhash64 } from "hash-wasm"; import { useCallback, useEffect, useRef, useState } from "react"; import { useDropzone } from "react-dropzone"; @@ -53,6 +53,9 @@ export function FileProviderHandler(props: FileProviderHandlerProps) { }); const [totalNoteCount, setTotalNoteCount] = useState(0); const [_, setCounter] = useState(0); + const [nestedTagSeparator, setNestedTagSeparator] = useState< + string | undefined + >(undefined); const logs = useRef([]); const onDrop = useCallback((acceptedFiles: File[]) => { @@ -103,6 +106,10 @@ export function FileProviderHandler(props: FileProviderHandlerProps) { }, reporter: () => { setTotalNoteCount(++totalNotes); + }, + // @ts-expect-error update importer package + options: { + nestedTagToNotebookSeparator: nestedTagSeparator } }; @@ -224,6 +231,51 @@ export function FileProviderHandler(props: FileProviderHandlerProps) { + + {provider.name.toLowerCase() === "evernote" && files.length > 0 && ( + <> + label": { width: "auto" } + }} + > + + Convert nested tags to notebooks + + + setNestedTagSeparator((s) => (s ? undefined : "/")) + } + checked={nestedTagSeparator !== undefined} + /> + + {nestedTagSeparator !== undefined && ( + + Nested tag separator + setNestedTagSeparator(e.target.value)} + /> + + )} + + )} {files.length > 0 ? ( undefined); - if (!notebookIds) continue; - for (const notebookId of notebookIds) - await db.notes.addToNotebook(notebookId, noteId); + const importedNotebooks = await importNotebook(nb).catch(() => undefined); + if (!importedNotebooks) continue; + for (const importedNotebook of importedNotebooks) { + if (importedNotebook.skipApplyingToNote) continue; + await db.notes.addToNotebook(importedNotebook.id, noteId); + } } } +type ImportedNotebook = { + id: string; + skipApplyingToNote: boolean; +}; + async function importNotebook( notebook: Notebook, parent?: NotebookType -): Promise { +): Promise { if (!notebook) return []; const selector = parent @@ -185,9 +192,12 @@ async function importNotebook( if (parent && nb) await db.relations.add(parent, nb); } if (!nb) return []; - if (notebook.children.length === 0) return [nb.id]; + if (notebook.children.length === 0) { + // @ts-expect-error update imported package + return [{ id: nb.id, skipApplyingToNote: notebook.skipApplyingToNote }]; + } - const assignedNotebooks: string[] = []; + const assignedNotebooks: ImportedNotebook[] = []; for (const child of notebook.children || []) assignedNotebooks.push(...(await importNotebook(child, nb))); return assignedNotebooks; diff --git a/docs/help/contents/importing-notes/import-notes-from-evernote.md b/docs/help/contents/importing-notes/import-notes-from-evernote.md index 52ced9698..c86ccf469 100644 --- a/docs/help/contents/importing-notes/import-notes-from-evernote.md +++ b/docs/help/contents/importing-notes/import-notes-from-evernote.md @@ -28,7 +28,8 @@ Once you have all the .ENEX files containing your Evernote notes, its time to im ![](/static/evernote-importer/4.png) 3. Drop (or select) the `.enex` files you exported earlier from Evernote, and click the "Start processing" button. ![](/static/evernote-importer/5.png) -4. Once the importing completes you should see all your notes in Notesnook. If you face any issues during importing, feel free to [report them on GitHub](https://github.com/streetwriters/notesnook-importer). +4. (Optional) Since Notesnook does not support nested tags, nested tags imported from Evernote will not work as expected. Instead, you can convert nested tags into notebooks in Notesnook. To do this, enable the “Convert nested tags to notebooks” toggle and specify a nested tag separator character (such as `/` or `_`). Before importing, you’ll need to manually rename your nested tags in Evernote (either through the Evernote UI or by editing the `.enex` file) so that the full tag hierarchy is represented using the chosen separator character. +5. Once the importing completes you should see all your notes in Notesnook. If you face any issues during importing, feel free to [report them on GitHub](https://github.com/streetwriters/notesnook-importer). ## Supported formats