From 4fdfe2f824cd30911b4a41656bc55b891a5a06c5 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Sun, 12 Mar 2023 18:30:18 -0600 Subject: [PATCH] feat: add contacts DB & page --- project.yaml | 3 +- src/db/index.ts | 18 +++-- src/db/tables/accounts.ts | 6 -- src/db/tables/contacts.ts | 12 +++ src/router/index.ts | 6 ++ src/views/ContactsView.vue | 121 +++++++++++++++++++++++++++++++ src/views/NewEditProjectView.vue | 1 + src/views/ProjectViewView.vue | 1 + src/views/ProjectsView.vue | 1 + 9 files changed, 156 insertions(+), 13 deletions(-) create mode 100644 src/db/tables/contacts.ts create mode 100644 src/views/ContactsView.vue diff --git a/project.yaml b/project.yaml index c5abb19f7..00d5c593d 100644 --- a/project.yaml +++ b/project.yaml @@ -14,7 +14,8 @@ - replace user-affecting console.logs with error messages (eg. catches) -- contacts +- contacts v1: + - parse input correctly (with CSV lib and not commas) - commit screen diff --git a/src/db/index.ts b/src/db/index.ts index be9d9f4e8..67b306193 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -1,6 +1,12 @@ -import BaseDexie from "dexie"; +import BaseDexie, { Table } from "dexie"; import { encrypted, Encryption } from "@pvermeer/dexie-encrypted-addon"; -import { accountsSchema, AccountsTable } from "./tables/accounts"; +import { accountsSchema, Account } from "./tables/accounts"; +import { contactsSchema, Contact } from "./tables/contacts"; + +type AllTables = { + accounts: Table; + contacts: Table; +}; /** * In order to make the next line be acceptable, the program needs to have its linter suppress a rule: @@ -10,10 +16,9 @@ import { accountsSchema, AccountsTable } from "./tables/accounts"; * * https://9to5answer.com/how-to-bypass-warning-unexpected-any-specify-a-different-type-typescript-eslint-no-explicit-any */ -type DexieTables = AccountsTable; +type DexieTables = AllTables; export type Dexie = BaseDexie & T; export const db = new BaseDexie("kickStarter") as Dexie; -const schema = Object.assign({}, accountsSchema); /** * Needed to enable a special webpack setting to allow *await* below: @@ -27,6 +32,7 @@ const secret = if (localStorage.getItem("secret") == null) { localStorage.setItem("secret", secret); } -console.log(secret); +console.log("DB encryption secretKey:", secret); encrypted(db, { secretKey: secret }); -db.version(1).stores(schema); +db.version(1).stores(accountsSchema); +db.version(2).stores(contactsSchema); diff --git a/src/db/tables/accounts.ts b/src/db/tables/accounts.ts index 8ed1bd2b8..b78982f29 100644 --- a/src/db/tables/accounts.ts +++ b/src/db/tables/accounts.ts @@ -1,5 +1,3 @@ -import { Table } from "dexie"; - export type Account = { id?: number; publicKey: string; @@ -8,10 +6,6 @@ export type Account = { dateCreated: number; }; -export type AccountsTable = { - accounts: Table; -}; - // mark encrypted field by starting with a $ character export const accountsSchema = { accounts: "++id, publicKey, $mnemonic, $identity, dateCreated", diff --git a/src/db/tables/contacts.ts b/src/db/tables/contacts.ts new file mode 100644 index 000000000..a19790236 --- /dev/null +++ b/src/db/tables/contacts.ts @@ -0,0 +1,12 @@ +export interface Contact { + did: string; + name?: string; + publicKeyBase64?: string; + seesMe?: boolean; + registered?: boolean; +} + +// mark encrypted field by starting with a $ character +export const contactsSchema = { + contacts: "++did, name, publicKeyBase64, seesMe, registered", +}; diff --git a/src/router/index.ts b/src/router/index.ts index 38611c984..3147ab42d 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -43,6 +43,12 @@ const routes: Array = [ /* webpackChunkName: "confirm-contact" */ "../views/ConfirmContactView.vue" ), }, + { + path: "/contacts", + name: "contacts", + component: () => + import(/* webpackChunkName: "contacts" */ "../views/ContactsView.vue"), + }, { path: "/scan-contact", name: "scan-contact", diff --git a/src/views/ContactsView.vue b/src/views/ContactsView.vue new file mode 100644 index 000000000..ccd5fa397 --- /dev/null +++ b/src/views/ContactsView.vue @@ -0,0 +1,121 @@ + + + diff --git a/src/views/NewEditProjectView.vue b/src/views/NewEditProjectView.vue index 54c020f0c..bb153aaff 100644 --- a/src/views/NewEditProjectView.vue +++ b/src/views/NewEditProjectView.vue @@ -107,6 +107,7 @@ export default class NewEditProjectView extends Vue { isHiddenSave = false; isHiddenSpinner = true; + // 'created' hook runs when the Vue instance is first created async created() { if (this.projectId === "") { console.log("This is a new project"); diff --git a/src/views/ProjectViewView.vue b/src/views/ProjectViewView.vue index f0a2b4ee3..e8577ff45 100644 --- a/src/views/ProjectViewView.vue +++ b/src/views/ProjectViewView.vue @@ -222,6 +222,7 @@ export default class ProjectViewView extends Vue { } } + // 'created' hook runs when the Vue instance is first created async created() { await db.open(); const num_accounts = await db.accounts.count(); diff --git a/src/views/ProjectsView.vue b/src/views/ProjectsView.vue index 06b8fdc57..ae3abbe6a 100644 --- a/src/views/ProjectsView.vue +++ b/src/views/ProjectsView.vue @@ -151,6 +151,7 @@ export default class ProjectsView extends Vue { } } + // 'created' hook runs when the Vue instance is first created async created() { await db.open(); const num_accounts = await db.accounts.count();