From f26ad410e2888cb90e34c25d19d746f54db1e53e Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Fri, 18 Aug 2023 16:58:01 +0530 Subject: [PATCH] feat: Add toggle to disable creating a new tag on import --- .../Components/ImportModal/ImportModal.tsx | 19 ++++++++- .../Controllers/ImportModalController.ts | 41 ++++++++++++------- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/packages/web/src/javascripts/Components/ImportModal/ImportModal.tsx b/packages/web/src/javascripts/Components/ImportModal/ImportModal.tsx index 7dee40c2781..c18c91d2f1f 100644 --- a/packages/web/src/javascripts/Components/ImportModal/ImportModal.tsx +++ b/packages/web/src/javascripts/Components/ImportModal/ImportModal.tsx @@ -6,11 +6,22 @@ import Modal, { ModalAction } from '../Modal/Modal' import ModalOverlay from '../Modal/ModalOverlay' import { ImportModalController } from '@/Controllers/ImportModalController' import { useApplication } from '../ApplicationProvider' +import Switch from '../Switch/Switch' const ImportModal = ({ importModalController }: { importModalController: ImportModalController }) => { const application = useApplication() - const { files, setFiles, updateFile, removeFile, parseAndImport, isVisible, close } = importModalController + const { + files, + setFiles, + shouldCreateTag, + setShouldCreateTag, + updateFile, + removeFile, + parseAndImport, + isVisible, + close, + } = importModalController const isReadyToImport = files.length > 0 && files.every((file) => file.status === 'ready') const importSuccessOrError = @@ -54,6 +65,12 @@ const ImportModal = ({ importModalController }: { importModalController: ImportM )} + {files.length > 0 && ( + + )} ) diff --git a/packages/web/src/javascripts/Controllers/ImportModalController.ts b/packages/web/src/javascripts/Controllers/ImportModalController.ts index 71646df596a..f133303fe1a 100644 --- a/packages/web/src/javascripts/Controllers/ImportModalController.ts +++ b/packages/web/src/javascripts/Controllers/ImportModalController.ts @@ -28,6 +28,7 @@ export type ImportModalFile = ( export class ImportModalController { isVisible = false + shouldCreateTag = true files: ImportModalFile[] = [] importTag: SNTag | undefined = undefined @@ -41,6 +42,9 @@ export class ImportModalController { isVisible: observable, setIsVisible: action, + shouldCreateTag: observable, + setShouldCreateTag: action, + files: observable, setFiles: action, updateFile: action, @@ -55,6 +59,10 @@ export class ImportModalController { this.isVisible = isVisible } + setShouldCreateTag = (shouldCreateTag: boolean) => { + this.shouldCreateTag = shouldCreateTag + } + setFiles = (files: File[], service?: NoteImportType) => { this.files = files.map((file) => ({ id: UuidGenerator.GenerateUuid(), @@ -78,6 +86,7 @@ export class ImportModalController { close = () => { this.setIsVisible(false) + this.setShouldCreateTag(true) if (this.importTag) { this.navigationController .setSelectedTag(this.importTag, 'all', { @@ -158,21 +167,23 @@ export class ImportModalController { if (!importedPayloads.length) { return } - const currentDate = new Date() - const importTagItem = this.items.createTemplateItem(ContentType.TYPES.Tag, { - title: `Imported on ${currentDate.toLocaleString()}`, - expanded: false, - iconString: '', - references: importedPayloads - .filter((payload) => payload.content_type === ContentType.TYPES.Note) - .map((payload) => ({ - content_type: ContentType.TYPES.Note, - uuid: payload.uuid, - })), - }) - const importTag = await this.mutator.insertItem(importTagItem) - if (importTag) { - this.setImportTag(importTag as SNTag) + if (this.shouldCreateTag) { + const currentDate = new Date() + const importTagItem = this.items.createTemplateItem(ContentType.TYPES.Tag, { + title: `Imported on ${currentDate.toLocaleString()}`, + expanded: false, + iconString: '', + references: importedPayloads + .filter((payload) => payload.content_type === ContentType.TYPES.Note) + .map((payload) => ({ + content_type: ContentType.TYPES.Note, + uuid: payload.uuid, + })), + }) + const importTag = await this.mutator.insertItem(importTagItem) + if (importTag) { + this.setImportTag(importTag as SNTag) + } } } }