feat: Add toggle to disable creating a new tag on import
This commit is contained in:
@@ -6,11 +6,22 @@ import Modal, { ModalAction } from '../Modal/Modal'
|
|||||||
import ModalOverlay from '../Modal/ModalOverlay'
|
import ModalOverlay from '../Modal/ModalOverlay'
|
||||||
import { ImportModalController } from '@/Controllers/ImportModalController'
|
import { ImportModalController } from '@/Controllers/ImportModalController'
|
||||||
import { useApplication } from '../ApplicationProvider'
|
import { useApplication } from '../ApplicationProvider'
|
||||||
|
import Switch from '../Switch/Switch'
|
||||||
|
|
||||||
const ImportModal = ({ importModalController }: { importModalController: ImportModalController }) => {
|
const ImportModal = ({ importModalController }: { importModalController: ImportModalController }) => {
|
||||||
const application = useApplication()
|
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 isReadyToImport = files.length > 0 && files.every((file) => file.status === 'ready')
|
||||||
const importSuccessOrError =
|
const importSuccessOrError =
|
||||||
@@ -54,6 +65,12 @@ const ImportModal = ({ importModalController }: { importModalController: ImportM
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
{files.length > 0 && (
|
||||||
|
<label className="py-2 px-4 flex items-center gap-2 border-t border-border">
|
||||||
|
<Switch checked={shouldCreateTag} onChange={setShouldCreateTag} />
|
||||||
|
<span className="text-sm">Create tag with all imported notes</span>
|
||||||
|
</label>
|
||||||
|
)}
|
||||||
</Modal>
|
</Modal>
|
||||||
</ModalOverlay>
|
</ModalOverlay>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ export type ImportModalFile = (
|
|||||||
|
|
||||||
export class ImportModalController {
|
export class ImportModalController {
|
||||||
isVisible = false
|
isVisible = false
|
||||||
|
shouldCreateTag = true
|
||||||
files: ImportModalFile[] = []
|
files: ImportModalFile[] = []
|
||||||
importTag: SNTag | undefined = undefined
|
importTag: SNTag | undefined = undefined
|
||||||
|
|
||||||
@@ -41,6 +42,9 @@ export class ImportModalController {
|
|||||||
isVisible: observable,
|
isVisible: observable,
|
||||||
setIsVisible: action,
|
setIsVisible: action,
|
||||||
|
|
||||||
|
shouldCreateTag: observable,
|
||||||
|
setShouldCreateTag: action,
|
||||||
|
|
||||||
files: observable,
|
files: observable,
|
||||||
setFiles: action,
|
setFiles: action,
|
||||||
updateFile: action,
|
updateFile: action,
|
||||||
@@ -55,6 +59,10 @@ export class ImportModalController {
|
|||||||
this.isVisible = isVisible
|
this.isVisible = isVisible
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setShouldCreateTag = (shouldCreateTag: boolean) => {
|
||||||
|
this.shouldCreateTag = shouldCreateTag
|
||||||
|
}
|
||||||
|
|
||||||
setFiles = (files: File[], service?: NoteImportType) => {
|
setFiles = (files: File[], service?: NoteImportType) => {
|
||||||
this.files = files.map((file) => ({
|
this.files = files.map((file) => ({
|
||||||
id: UuidGenerator.GenerateUuid(),
|
id: UuidGenerator.GenerateUuid(),
|
||||||
@@ -78,6 +86,7 @@ export class ImportModalController {
|
|||||||
|
|
||||||
close = () => {
|
close = () => {
|
||||||
this.setIsVisible(false)
|
this.setIsVisible(false)
|
||||||
|
this.setShouldCreateTag(true)
|
||||||
if (this.importTag) {
|
if (this.importTag) {
|
||||||
this.navigationController
|
this.navigationController
|
||||||
.setSelectedTag(this.importTag, 'all', {
|
.setSelectedTag(this.importTag, 'all', {
|
||||||
@@ -158,21 +167,23 @@ export class ImportModalController {
|
|||||||
if (!importedPayloads.length) {
|
if (!importedPayloads.length) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const currentDate = new Date()
|
if (this.shouldCreateTag) {
|
||||||
const importTagItem = this.items.createTemplateItem<TagContent, SNTag>(ContentType.TYPES.Tag, {
|
const currentDate = new Date()
|
||||||
title: `Imported on ${currentDate.toLocaleString()}`,
|
const importTagItem = this.items.createTemplateItem<TagContent, SNTag>(ContentType.TYPES.Tag, {
|
||||||
expanded: false,
|
title: `Imported on ${currentDate.toLocaleString()}`,
|
||||||
iconString: '',
|
expanded: false,
|
||||||
references: importedPayloads
|
iconString: '',
|
||||||
.filter((payload) => payload.content_type === ContentType.TYPES.Note)
|
references: importedPayloads
|
||||||
.map((payload) => ({
|
.filter((payload) => payload.content_type === ContentType.TYPES.Note)
|
||||||
content_type: ContentType.TYPES.Note,
|
.map((payload) => ({
|
||||||
uuid: payload.uuid,
|
content_type: ContentType.TYPES.Note,
|
||||||
})),
|
uuid: payload.uuid,
|
||||||
})
|
})),
|
||||||
const importTag = await this.mutator.insertItem(importTagItem)
|
})
|
||||||
if (importTag) {
|
const importTag = await this.mutator.insertItem(importTagItem)
|
||||||
this.setImportTag(importTag as SNTag)
|
if (importTag) {
|
||||||
|
this.setImportTag(importTag as SNTag)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user