From 5647c4627fb5b4bee17d601714f586f9bf508150 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Fri, 26 Jul 2024 19:12:12 -0600 Subject: [PATCH] import & update selected contacts --- src/router/index.ts | 5 + src/views/AccountViewView.vue | 67 ++++++++++-- src/views/ContactImportView.vue | 179 ++++++++++++++++++++++++++++++++ 3 files changed, 240 insertions(+), 11 deletions(-) create mode 100644 src/views/ContactImportView.vue diff --git a/src/router/index.ts b/src/router/index.ts index 54850bf..2505a76 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -63,6 +63,11 @@ const routes: Array = [ name: "contact-gift", component: () => import("../views/ContactGiftingView.vue"), }, + { + path: "/contact-import", + name: "contact-import", + component: () => import("../views/ContactImportView.vue"), + }, { path: "/contact-qr", name: "contact-qr", diff --git a/src/views/AccountViewView.vue b/src/views/AccountViewView.vue index 2d27100..539e8e1 100644 --- a/src/views/AccountViewView.vue +++ b/src/views/AccountViewView.vue @@ -216,7 +216,7 @@
Location
Set Search Area… @@ -282,14 +282,14 @@ Backup Identifier Seed + @@ -692,9 +700,11 @@ import { Buffer } from "buffer/"; import Dexie from "dexie"; import "dexie-export-import"; import { ImportProgress } from "dexie-export-import/dist/import"; +import * as R from "ramda"; import { IIdentifier } from "@veramo/core"; import { ref } from "vue"; import { Component, Vue } from "vue-facing-decorator"; +import { Router } from "vue-router"; import { useClipboard } from "@vueuse/core"; import EntityIcon from "@/components/EntityIcon.vue"; @@ -710,6 +720,7 @@ import { } from "@/constants/app"; import { db, accountsDB } from "@/db/index"; import { Account } from "@/db/tables/accounts"; +import { Contact } from "@/db/tables/contacts"; import { DEFAULT_PASSKEY_EXPIRATION_MINUTES, MASTER_SETTINGS_KEY, @@ -1146,6 +1157,40 @@ export default class AccountViewView extends Vue { } } + async checkContactImports() { + const reader = new FileReader(); + reader.onload = (event) => { + const fileContent: string = (event.target?.result as string) || "{}"; + try { + const contents = JSON.parse(fileContent); + const contactTableRows: Array = ( + contents.data?.data as [{ tableName: string; rows: Array }] + )?.find((table) => table.tableName === "contacts") + ?.rows as Array; + const contactRows = contactTableRows.map( + // @ts-expect-error for omitting this field that is found in the Dexie format + (contact) => R.omit(["$types"], contact) as Contact, + ); + (this.$router as Router).push({ + name: "contact-import", + query: { contacts: JSON.stringify(contactRows) }, + }); + } catch (error) { + console.error("Error checking contact imports:", error); + this.$notify( + { + group: "alert", + type: "danger", + title: "Error Importing", + text: "There was an error reading that Dexie file.", + }, + 3000, + ); + } + }; + reader.readAsText(inputImportFileNameRef.value as Blob); + } + private progressCallback(progress: ImportProgress) { console.log( `Import progress: ${progress.completedRows} of ${progress.totalRows} rows completed.`, diff --git a/src/views/ContactImportView.vue b/src/views/ContactImportView.vue new file mode 100644 index 0000000..827c72c --- /dev/null +++ b/src/views/ContactImportView.vue @@ -0,0 +1,179 @@ + + +