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">
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 * 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
*/
export async function retrieveSettingsForActiveAccount(): Promise<Settings> {
try {
// Get default settings first
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.
* This format is used for data migration and backup purposes.
*
*
* @param contacts - Array of Contact objects to convert
* @returns DatabaseExport object in the standardized format
*/
export const contactsToExportJson = (contacts: Contact[]): DatabaseExport => {
// 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,
name: contact.name || null,
contactMethods: contact.contactMethods ? JSON.stringify(contact.contactMethods) : null,
contactMethods: contact.contactMethods
? JSON.stringify(contact.contactMethods)
: null,
nextPubKeyHashB64: contact.nextPubKeyHashB64 || null,
notes: contact.notes || null,
profileImageUrl: contact.profileImageUrl || null,
publicKeyBase64: contact.publicKeyBase64 || null,
seesMe: contact.seesMe || false,
registered: contact.registered || false
registered: contact.registered || false,
}));
return {
data: {
data: [{
tableName: "contacts",
rows
}]
}
data: [
{
tableName: "contacts",
rows,
},
],
},
};
};

5
src/services/migrationService.ts

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

26
src/views/AccountViewView.vue

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

20
src/views/ContactImportView.vue

@ -243,7 +243,7 @@ interface ContactDbRecord {
* Ensures a value is a string, never null or undefined
*/
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
const contactMethodsStr = (contact.contactMethods != null
? JSON.stringify(contact.contactMethods)
: "[]");
const contactMethodsStr =
contact.contactMethods != null
? JSON.stringify(contact.contactMethods)
: "[]";
return {
did: safeString(contact.did), // Required field, must be present
did: safeString(contact.did), // Required field, must be present
contactMethods: contactMethodsStr,
name: safeString(contact.name),
notes: safeString(contact.notes),
@ -271,7 +272,7 @@ function contactToDbRecord(contact: Contact): ContactDbRecord {
publicKeyBase64: safeString(contact.publicKeyBase64),
nextPubKeyHashB64: safeString(contact.nextPubKeyHashB64),
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),
publicKeyBase64: safeString(record.publicKeyBase64),
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);
if (USE_DEXIE_DB) {
// 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++;
} else {

Loading…
Cancel
Save