diff --git a/packages/ui-services/src/Import/Importer.ts b/packages/ui-services/src/Import/Importer.ts index 2d940fd0c..cd0ab8006 100644 --- a/packages/ui-services/src/Import/Importer.ts +++ b/packages/ui-services/src/Import/Importer.ts @@ -7,7 +7,7 @@ import { GoogleKeepConverter } from './GoogleKeepConverter/GoogleKeepConverter' import { PlaintextConverter } from './PlaintextConverter/PlaintextConverter' import { SimplenoteConverter } from './SimplenoteConverter/SimplenoteConverter' import { readFileAsText } from './Utils' -import { DecryptedTransferPayload } from '@standardnotes/models' +import { DecryptedTransferPayload, NoteContent } from '@standardnotes/models' export type NoteImportType = 'plaintext' | 'evernote' | 'google-keep' | 'simplenote' | 'aegis' @@ -81,9 +81,23 @@ export class Importer { async importFromTransferPayloads(payloads: DecryptedTransferPayload[]) { const insertedItems = await Promise.all( payloads.map(async (payload) => { - const itemPayload = this.application.items.createPayloadFromObject(payload) - const item = this.application.items.createItemFromPayload(itemPayload) - return this.application.mutator.insertItem(item) + const content = payload.content as NoteContent + const note = this.application.mutator.createTemplateItem( + payload.content_type, + { + text: content.text, + title: content.title, + noteType: content.noteType, + editorIdentifier: content.editorIdentifier, + references: content.references, + }, + { + created_at: payload.created_at, + updated_at: payload.updated_at, + uuid: payload.uuid, + }, + ) + return this.application.mutator.insertItem(note) }), ) return insertedItems diff --git a/packages/web/src/javascripts/Controllers/ImportModalController.ts b/packages/web/src/javascripts/Controllers/ImportModalController.ts index 884adad44..7564b6e74 100644 --- a/packages/web/src/javascripts/Controllers/ImportModalController.ts +++ b/packages/web/src/javascripts/Controllers/ImportModalController.ts @@ -27,7 +27,7 @@ export class ImportModalController { files: ImportModalFile[] = [] importTag: SNTag | undefined = undefined - constructor(application: WebApplication, private navigationController: NavigationController) { + constructor(private application: WebApplication, private navigationController: NavigationController) { makeObservable(this, { isVisible: observable, setIsVisible: action, @@ -149,26 +149,18 @@ export class ImportModalController { } } const currentDate = new Date() - const importTagPayload: DecryptedTransferPayload = { - uuid: UuidGenerator.GenerateUuid(), - created_at: currentDate, - created_at_timestamp: currentDate.getTime(), - updated_at: currentDate, - updated_at_timestamp: currentDate.getTime(), - content_type: ContentType.Tag, - content: { - title: `Imported on ${currentDate.toLocaleString()}`, - expanded: false, - iconString: '', - references: importedPayloads - .filter((payload) => payload.content_type === ContentType.Note) - .map((payload) => ({ - content_type: ContentType.Note, - uuid: payload.uuid, - })), - }, - } - const [importTag] = await this.importer.importFromTransferPayloads([importTagPayload]) + const importTagItem = this.application.mutator.createTemplateItem(ContentType.Tag, { + title: `Imported on ${currentDate.toLocaleString()}`, + expanded: false, + iconString: '', + references: importedPayloads + .filter((payload) => payload.content_type === ContentType.Note) + .map((payload) => ({ + content_type: ContentType.Note, + uuid: payload.uuid, + })), + }) + const importTag = await this.application.mutator.insertItem(importTagItem) if (importTag) { this.setImportTag(importTag as SNTag) }