Apply enhanced PlatformServiceMixin to HomeView

Replace 6 settings calls with 4 enhanced utility methods (, ). Simplify database operations with  mixin utility. Eliminate Vue property conflicts and PlatformServiceFactory import. Add consistent error handling across all platform service interactions.
This commit is contained in:
Matthew Raymer
2025-07-02 10:21:19 +00:00
parent 7b9e550780
commit a08261ed5a

View File

@@ -320,7 +320,7 @@ import {
} from "../constants/app"; } from "../constants/app";
import { logConsoleAndDb } from "../db/index"; import { logConsoleAndDb } from "../db/index";
import { Contact } from "../db/tables/contacts"; import { Contact } from "../db/tables/contacts";
import { BoundingBox, checkIsAnyFeedFilterOn } from "../db/tables/settings"; import { BoundingBox, checkIsAnyFeedFilterOn, MASTER_SETTINGS_KEY } from "../db/tables/settings";
import * as databaseUtil from "../db/databaseUtil"; import * as databaseUtil from "../db/databaseUtil";
import { import {
contactForDid, contactForDid,
@@ -342,7 +342,7 @@ import { GiveSummaryRecord } from "../interfaces/records";
import * as serverUtil from "../libs/endorserServer"; import * as serverUtil from "../libs/endorserServer";
import { logger } from "../utils/logger"; import { logger } from "../utils/logger";
import { GiveRecordWithContactInfo } from "../interfaces/give"; import { GiveRecordWithContactInfo } from "../interfaces/give";
import { PlatformServiceFactory } from "@/services/PlatformServiceFactory"; import { PlatformServiceMixin } from "@/utils/PlatformServiceMixin";
import * as Package from "../../package.json"; import * as Package from "../../package.json";
interface Claim { interface Claim {
@@ -427,6 +427,7 @@ interface FeedError {
ImageViewer, ImageViewer,
ActivityListItem, ActivityListItem,
}, },
mixins: [PlatformServiceMixin],
}) })
export default class HomeView extends Vue { export default class HomeView extends Vue {
$notify!: (notification: NotificationIface, timeout?: number) => void; $notify!: (notification: NotificationIface, timeout?: number) => void;
@@ -537,10 +538,14 @@ export default class HomeView extends Vue {
} }
} }
// Load settings with better error context // Load settings with better error context using enhanced mixin
let settings; let settings;
try { try {
settings = await databaseUtil.retrieveSettingsForActiveAccount(); settings = await (this as any).$getSettings(MASTER_SETTINGS_KEY, {
apiServer: "",
activeDid: "",
isRegistered: false,
});
} catch (error) { } catch (error) {
logConsoleAndDb( logConsoleAndDb(
`[HomeView] Failed to retrieve settings: ${error}`, `[HomeView] Failed to retrieve settings: ${error}`,
@@ -605,9 +610,10 @@ export default class HomeView extends Vue {
this.activeDid, this.activeDid,
); );
if (resp.status === 200) { if (resp.status === 200) {
const currentSettings = await (this as any).$getSettings(MASTER_SETTINGS_KEY, {});
await databaseUtil.updateDidSpecificSettings(this.activeDid, { await databaseUtil.updateDidSpecificSettings(this.activeDid, {
isRegistered: true, isRegistered: true,
...(await databaseUtil.retrieveSettingsForActiveAccount()), ...currentSettings,
}); });
this.isRegistered = true; this.isRegistered = true;
} }
@@ -675,19 +681,27 @@ export default class HomeView extends Vue {
} }
/** /**
* Loads user settings from storage * Loads user settings from storage using enhanced mixin utilities
* Sets component state for: * Sets component state for:
* - API server * - API server, Active DID, Feed filters and view settings
* - Active DID * - Registration status, Notification acknowledgments
* - Feed filters and view settings
* - Registration status
* - Notification acknowledgments
* *
* @internal * @internal
* Called by mounted() and reloadFeedOnChange() * Called by mounted() and reloadFeedOnChange()
*/ */
private async loadSettings() { private async loadSettings() {
const settings = await databaseUtil.retrieveSettingsForActiveAccount(); // Use enhanced mixin utility for default settings - much more concise!
const settings = await (this as any).$getSettings(
MASTER_SETTINGS_KEY,
{
apiServer: "",
activeDid: "",
filterFeedByVisible: false,
filterFeedByNearby: false,
isRegistered: false,
}
);
this.apiServer = settings.apiServer || ""; this.apiServer = settings.apiServer || "";
this.activeDid = settings.activeDid || ""; this.activeDid = settings.activeDid || "";
this.feedLastViewedClaimId = settings.lastViewedClaimId; this.feedLastViewedClaimId = settings.lastViewedClaimId;
@@ -711,8 +725,7 @@ export default class HomeView extends Vue {
* Called by mounted() and initializeIdentity() * Called by mounted() and initializeIdentity()
*/ */
private async loadContacts() { private async loadContacts() {
const platformService = PlatformServiceFactory.getInstance(); const dbContacts = await (this as any).$dbQuery("SELECT * FROM contacts");
const dbContacts = await platformService.dbQuery("SELECT * FROM contacts");
this.allContacts = databaseUtil.mapQueryResultToValues( this.allContacts = databaseUtil.mapQueryResultToValues(
dbContacts, dbContacts,
) as unknown as Contact[]; ) as unknown as Contact[];
@@ -739,12 +752,10 @@ export default class HomeView extends Vue {
this.activeDid, this.activeDid,
); );
if (resp.status === 200) { if (resp.status === 200) {
const settings = const currentSettings = await (this as any).$getSettings(MASTER_SETTINGS_KEY, {});
await databaseUtil.retrieveSettingsForActiveAccount();
await databaseUtil.updateDidSpecificSettings(this.activeDid, { await databaseUtil.updateDidSpecificSettings(this.activeDid, {
apiServer: this.apiServer,
isRegistered: true, isRegistered: true,
...settings, ...currentSettings,
}); });
this.isRegistered = true; this.isRegistered = true;
} }
@@ -799,14 +810,14 @@ export default class HomeView extends Vue {
} }
/** /**
* Checks if user needs onboarding * Checks if user needs onboarding using enhanced mixin utilities
* Opens onboarding dialog if not completed * Opens onboarding dialog if not completed
* *
* @internal * @internal
* Called by mounted() * Called by mounted()
*/ */
private async checkOnboarding() { private async checkOnboarding() {
const settings = await databaseUtil.retrieveSettingsForActiveAccount(); const settings = await (this as any).$getSettings(MASTER_SETTINGS_KEY, {});
if (!settings.finishedOnboarding) { if (!settings.finishedOnboarding) {
(this.$refs.onboardingDialog as OnboardingDialog).open(OnboardPage.Home); (this.$refs.onboardingDialog as OnboardingDialog).open(OnboardPage.Home);
} }
@@ -866,16 +877,20 @@ export default class HomeView extends Vue {
} }
/** /**
* Reloads feed when filter settings change * Reloads feed when filter settings change using enhanced mixin utilities
* - Updates filter states * - Updates filter states
* - Clears existing feed data * - Clears existing feed data
* - Triggers new feed load * - Triggers new feed load
* *
* @public * @public
* Called by FeedFilters component when filters change * Called by FeedFilters component when filters change
*/ */
async reloadFeedOnChange() { async reloadFeedOnChange() {
const settings = await databaseUtil.retrieveSettingsForActiveAccount(); const settings = await (this as any).$getMergedSettings(
MASTER_SETTINGS_KEY,
this.activeDid,
{ filterFeedByVisible: false, filterFeedByNearby: false }
);
this.isFeedFilteredByVisible = !!settings.filterFeedByVisible; this.isFeedFilteredByVisible = !!settings.filterFeedByVisible;
this.isFeedFilteredByNearby = !!settings.filterFeedByNearby; this.isFeedFilteredByNearby = !!settings.filterFeedByNearby;
this.isAnyFeedFilterOn = checkIsAnyFeedFilterOn(settings); this.isAnyFeedFilterOn = checkIsAnyFeedFilterOn(settings);