Browse Source

fix linting

pull/137/head
Trent Larson 1 day ago
parent
commit
9ac9713172
  1. 2
      src/components/DataExportSection.vue
  2. 1
      src/db/databaseUtil.ts
  3. 22
      src/libs/util.ts
  4. 5
      src/services/migrationService.ts
  5. 26
      src/views/AccountViewView.vue
  6. 20
      src/views/ContactImportView.vue

2
src/components/DataExportSection.vue

@ -62,7 +62,7 @@ backup and database export, with platform-specific download instructions. * *
<script lang="ts"> <script lang="ts">
import { Component, Prop, Vue } from "vue-facing-decorator"; import { Component, Prop, Vue } from "vue-facing-decorator";
import { AppString, NotificationIface, USE_DEXIE_DB } from "../constants/app"; import { AppString, NotificationIface } from "../constants/app";
import { Contact } from "../db/tables/contacts"; import { Contact } from "../db/tables/contacts";
import * as databaseUtil from "../db/databaseUtil"; import * as databaseUtil from "../db/databaseUtil";

1
src/db/databaseUtil.ts

@ -104,7 +104,6 @@ export async function retrieveSettingsForDefaultAccount(): Promise<Settings> {
* @throws Will log specific errors for debugging but returns default settings on failure * @throws Will log specific errors for debugging but returns default settings on failure
*/ */
export async function retrieveSettingsForActiveAccount(): Promise<Settings> { export async function retrieveSettingsForActiveAccount(): Promise<Settings> {
try { try {
// Get default settings first // Get default settings first
const defaultSettings = await retrieveSettingsForDefaultAccount(); const defaultSettings = await retrieveSettingsForDefaultAccount();

22
src/libs/util.ts

@ -889,30 +889,34 @@ export interface DatabaseExport {
/** /**
* Converts an array of contacts to the standardized database export JSON format. * Converts an array of contacts to the standardized database export JSON format.
* This format is used for data migration and backup purposes. * This format is used for data migration and backup purposes.
* *
* @param contacts - Array of Contact objects to convert * @param contacts - Array of Contact objects to convert
* @returns DatabaseExport object in the standardized format * @returns DatabaseExport object in the standardized format
*/ */
export const contactsToExportJson = (contacts: Contact[]): DatabaseExport => { export const contactsToExportJson = (contacts: Contact[]): DatabaseExport => {
// Convert each contact to a plain object and ensure all fields are included // Convert each contact to a plain object and ensure all fields are included
const rows = contacts.map(contact => ({ const rows = contacts.map((contact) => ({
did: contact.did, did: contact.did,
name: contact.name || null, name: contact.name || null,
contactMethods: contact.contactMethods ? JSON.stringify(contact.contactMethods) : null, contactMethods: contact.contactMethods
? JSON.stringify(contact.contactMethods)
: null,
nextPubKeyHashB64: contact.nextPubKeyHashB64 || null, nextPubKeyHashB64: contact.nextPubKeyHashB64 || null,
notes: contact.notes || null, notes: contact.notes || null,
profileImageUrl: contact.profileImageUrl || null, profileImageUrl: contact.profileImageUrl || null,
publicKeyBase64: contact.publicKeyBase64 || null, publicKeyBase64: contact.publicKeyBase64 || null,
seesMe: contact.seesMe || false, seesMe: contact.seesMe || false,
registered: contact.registered || false registered: contact.registered || false,
})); }));
return { return {
data: { data: {
data: [{ data: [
tableName: "contacts", {
rows tableName: "contacts",
}] rows,
} },
],
},
}; };
}; };

5
src/services/migrationService.ts

@ -31,9 +31,8 @@ export class MigrationService {
sqlQuery: (sql: string) => Promise<T>, sqlQuery: (sql: string) => Promise<T>,
extractMigrationNames: (result: T) => Set<string>, extractMigrationNames: (result: T) => Set<string>,
): Promise<void> { ): Promise<void> {
// Create migrations table if it doesn't exist // Create migrations table if it doesn't exist
const result0 = await sqlExec(` await sqlExec(`
CREATE TABLE IF NOT EXISTS migrations ( CREATE TABLE IF NOT EXISTS migrations (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL UNIQUE, name TEXT NOT NULL UNIQUE,
@ -45,7 +44,6 @@ export class MigrationService {
const result1: T = await sqlQuery("SELECT name FROM migrations;"); const result1: T = await sqlQuery("SELECT name FROM migrations;");
const executedMigrations = extractMigrationNames(result1); const executedMigrations = extractMigrationNames(result1);
// Run pending migrations in order // Run pending migrations in order
for (const migration of this.migrations) { for (const migration of this.migrations) {
if (!executedMigrations.has(migration.name)) { if (!executedMigrations.has(migration.name)) {
@ -54,7 +52,6 @@ export class MigrationService {
await sqlExec( await sqlExec(
`INSERT INTO migrations (name) VALUES ('${migration.name}')`, `INSERT INTO migrations (name) VALUES ('${migration.name}')`,
); );
} }
} }
} }

26
src/views/AccountViewView.vue

@ -430,12 +430,16 @@
<div class="mb-4 text-center"> <div class="mb-4 text-center">
{{ limitsMessage }} {{ limitsMessage }}
</div> </div>
<div> <div v-if="endorserLimits">
<p class="text-sm"> <p class="text-sm">
You have done You have done
<b>{{ endorserLimits?.doneClaimsThisWeek || "?" }} claims</b> out of <b
<b>{{ endorserLimits?.maxClaimsPerWeek || "?" }}</b> for this week. >{{ endorserLimits?.doneClaimsThisWeek || "?" }} claim{{
Your claims counter resets at endorserLimits?.doneClaimsThisWeek === 1 ? "" : "s"
}}</b
>
out of <b>{{ endorserLimits?.maxClaimsPerWeek || "?" }}</b> for this
week. Your claims counter resets at
<b class="whitespace-nowrap">{{ <b class="whitespace-nowrap">{{
readableDate(endorserLimits?.nextWeekBeginDateTime) readableDate(endorserLimits?.nextWeekBeginDateTime)
}}</b> }}</b>
@ -446,7 +450,9 @@
>{{ >{{
endorserLimits?.doneRegistrationsThisMonth || "?" endorserLimits?.doneRegistrationsThisMonth || "?"
}} }}
registrations</b registration{{
endorserLimits?.doneRegistrationsThisMonth === 1 ? "" : "s"
}}</b
> >
out of out of
<b>{{ endorserLimits?.maxRegistrationsPerMonth || "?" }}</b> for this <b>{{ endorserLimits?.maxRegistrationsPerMonth || "?" }}</b> for this
@ -459,9 +465,13 @@
</p> </p>
<p class="mt-3 text-sm"> <p class="mt-3 text-sm">
You have uploaded You have uploaded
<b>{{ imageLimits?.doneImagesThisWeek || "?" }} images</b> out of <b
<b>{{ imageLimits?.maxImagesPerWeek || "?" }}</b> for this week. Your >{{ imageLimits?.doneImagesThisWeek || "?" }} image{{
image counter resets at imageLimits?.doneImagesThisWeek === 1 ? "" : "s"
}}</b
>
out of <b>{{ imageLimits?.maxImagesPerWeek || "?" }}</b> for this
week. Your image counter resets at
<b class="whitespace-nowrap">{{ <b class="whitespace-nowrap">{{
readableDate(imageLimits?.nextWeekBeginDateTime) readableDate(imageLimits?.nextWeekBeginDateTime)
}}</b> }}</b>

20
src/views/ContactImportView.vue

@ -243,7 +243,7 @@ interface ContactDbRecord {
* Ensures a value is a string, never null or undefined * Ensures a value is a string, never null or undefined
*/ */
function safeString(val: unknown): string { function safeString(val: unknown): string {
return typeof val === 'string' ? val : (val == null ? '' : String(val)); return typeof val === "string" ? val : val == null ? "" : String(val);
} }
/** /**
@ -258,12 +258,13 @@ function contactToDbRecord(contact: Contact): ContactDbRecord {
} }
// Convert contactMethods array to JSON string, defaulting to empty array // Convert contactMethods array to JSON string, defaulting to empty array
const contactMethodsStr = (contact.contactMethods != null const contactMethodsStr =
? JSON.stringify(contact.contactMethods) contact.contactMethods != null
: "[]"); ? JSON.stringify(contact.contactMethods)
: "[]";
return { return {
did: safeString(contact.did), // Required field, must be present did: safeString(contact.did), // Required field, must be present
contactMethods: contactMethodsStr, contactMethods: contactMethodsStr,
name: safeString(contact.name), name: safeString(contact.name),
notes: safeString(contact.notes), notes: safeString(contact.notes),
@ -271,7 +272,7 @@ function contactToDbRecord(contact: Contact): ContactDbRecord {
publicKeyBase64: safeString(contact.publicKeyBase64), publicKeyBase64: safeString(contact.publicKeyBase64),
nextPubKeyHashB64: safeString(contact.nextPubKeyHashB64), nextPubKeyHashB64: safeString(contact.nextPubKeyHashB64),
seesMe: contact.seesMe ?? false, seesMe: contact.seesMe ?? false,
registered: contact.registered ?? false registered: contact.registered ?? false,
}; };
} }
@ -288,7 +289,7 @@ function dbRecordToContact(record: ContactDbRecord): Contact {
profileImageUrl: safeString(record.profileImageUrl), profileImageUrl: safeString(record.profileImageUrl),
publicKeyBase64: safeString(record.publicKeyBase64), publicKeyBase64: safeString(record.publicKeyBase64),
nextPubKeyHashB64: safeString(record.nextPubKeyHashB64), nextPubKeyHashB64: safeString(record.nextPubKeyHashB64),
contactMethods: JSON.parse(record.contactMethods || "[]") contactMethods: JSON.parse(record.contactMethods || "[]"),
}; };
} }
@ -618,7 +619,10 @@ export default class ContactImportView extends Vue {
await platformService.dbExec(sql, params); await platformService.dbExec(sql, params);
if (USE_DEXIE_DB) { if (USE_DEXIE_DB) {
// For Dexie, we need to parse the contactMethods back to an array // For Dexie, we need to parse the contactMethods back to an array
await db.contacts.update(contact.did, dbRecordToContact(contactToStore)); await db.contacts.update(
contact.did,
dbRecordToContact(contactToStore),
);
} }
updatedCount++; updatedCount++;
} else { } else {

Loading…
Cancel
Save