Add notification utility helpers and update PlatformServiceMixin
Created notification utility approaches to consolidate verbose $notify calls: - Simple function utility (src/utils/notify.ts) - recommended approach - Vue 3 composable (src/composables/useNotifications.ts) - Utility class with mixin (src/utils/notificationUtils.ts) Updated ClaimView.vue to demonstrate usage, reducing notification code by ~70%. Enhanced PlatformServiceMixin with improved caching and database methods. Updated ShareMyContactInfoView.vue with mixin improvements. Provides consistent timeouts, standardized patterns, and type safety. Ready for migration alongside mixin updates.
This commit is contained in:
@@ -531,6 +531,7 @@ import {
|
||||
} from "../interfaces";
|
||||
import * as libsUtil from "../libs/util";
|
||||
import { PlatformServiceMixin } from "@/utils/PlatformServiceMixin";
|
||||
import { createNotifyHelpers, TIMEOUTS } from "@/utils/notify";
|
||||
|
||||
@Component({
|
||||
components: { GiftedDialog, QuickNav },
|
||||
@@ -577,6 +578,9 @@ export default class ClaimView extends Vue {
|
||||
libsUtil = libsUtil;
|
||||
serverUtil = serverUtil;
|
||||
|
||||
// Add notification helpers
|
||||
private notify = createNotifyHelpers(this.$notify);
|
||||
|
||||
// =================================================
|
||||
// COMPUTED PROPERTIES
|
||||
// =================================================
|
||||
@@ -728,30 +732,14 @@ export default class ClaimView extends Vue {
|
||||
"Error retrieving all account DIDs on home page:" + error,
|
||||
true,
|
||||
);
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "danger",
|
||||
title: "Error Loading Profile",
|
||||
text: "See the Help page for problems with your personal data.",
|
||||
},
|
||||
5000,
|
||||
);
|
||||
this.notify.error("See the Help page for problems with your personal data.");
|
||||
}
|
||||
|
||||
const claimId = this.$route.params.id as string;
|
||||
if (claimId) {
|
||||
await this.loadClaim(claimId, this.activeDid);
|
||||
} else {
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "danger",
|
||||
title: "Error",
|
||||
text: "No claim ID was provided.",
|
||||
},
|
||||
5000,
|
||||
);
|
||||
this.notify.error("No claim ID was provided.");
|
||||
}
|
||||
this.windowDeepLink = `${APP_SERVER}/deep-link/claim/${claimId}`;
|
||||
|
||||
@@ -803,15 +791,7 @@ export default class ClaimView extends Vue {
|
||||
} else {
|
||||
// actually, axios typically throws an error so we never get here
|
||||
await this.$logError("Error getting claim: " + JSON.stringify(resp));
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "danger",
|
||||
title: "Error",
|
||||
text: "There was a problem retrieving that claim.",
|
||||
},
|
||||
5000,
|
||||
);
|
||||
this.notify.error("There was a problem retrieving that claim.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -854,15 +834,7 @@ export default class ClaimView extends Vue {
|
||||
await this.$logError(
|
||||
"Error getting give providers: " + JSON.stringify(giveResp),
|
||||
);
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "warning",
|
||||
title: "Error",
|
||||
text: "Got error retrieving linked provider data.",
|
||||
},
|
||||
5000,
|
||||
);
|
||||
this.notify.warning("Got error retrieving linked provider data.");
|
||||
}
|
||||
} else if (this.veriClaim.claimType === "Offer") {
|
||||
const offerUrl =
|
||||
@@ -879,15 +851,7 @@ export default class ClaimView extends Vue {
|
||||
await this.$logError(
|
||||
"Error getting detailed offer info: " + JSON.stringify(offerResp),
|
||||
);
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "warning",
|
||||
title: "Error",
|
||||
text: "Got error retrieving linked offer data.",
|
||||
},
|
||||
5000,
|
||||
);
|
||||
this.notify.warning("Got error retrieving linked offer data.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -911,15 +875,7 @@ export default class ClaimView extends Vue {
|
||||
await this.$logError(
|
||||
"Error retrieving claim: " + JSON.stringify(serverError),
|
||||
);
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "danger",
|
||||
title: "Error",
|
||||
text: "Something went wrong retrieving claim data.",
|
||||
},
|
||||
3000,
|
||||
);
|
||||
this.notify.error("Something went wrong retrieving claim data.", TIMEOUTS.STANDARD);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -938,15 +894,7 @@ export default class ClaimView extends Vue {
|
||||
await this.$logError(
|
||||
"Error getting full claim: " + JSON.stringify(resp),
|
||||
);
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "danger",
|
||||
title: "Error",
|
||||
text: "There was a problem getting that claim.",
|
||||
},
|
||||
5000,
|
||||
);
|
||||
this.notify.error("There was a problem getting that claim.");
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
await this.$logError(
|
||||
@@ -984,31 +932,17 @@ export default class ClaimView extends Vue {
|
||||
" if they can find out more and make an introduction: " +
|
||||
" send them this page and see if they can make a connection for you.";
|
||||
} else {
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "danger",
|
||||
title: "Error",
|
||||
text: "Something went wrong retrieving that claim.",
|
||||
},
|
||||
5000,
|
||||
);
|
||||
this.notify.error("Something went wrong retrieving that claim.", TIMEOUTS.LONG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
confirmConfirmClaim() {
|
||||
this.$notify(
|
||||
{
|
||||
group: "modal",
|
||||
type: "confirm",
|
||||
title: "Confirm",
|
||||
text: "Do you personally confirm that this is true?",
|
||||
onYes: async () => {
|
||||
await this.confirmClaim();
|
||||
},
|
||||
},
|
||||
-1,
|
||||
this.notify.confirm(
|
||||
"Do you personally confirm that this is true?",
|
||||
async () => {
|
||||
await this.confirmClaim();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1036,28 +970,12 @@ export default class ClaimView extends Vue {
|
||||
this.axios,
|
||||
);
|
||||
if (result.success) {
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "success",
|
||||
title: "Success",
|
||||
text: "Confirmation submitted.",
|
||||
},
|
||||
5000,
|
||||
);
|
||||
this.notify.confirmationSubmitted();
|
||||
} else {
|
||||
await this.$logError(
|
||||
"Got error submitting the confirmation: " + JSON.stringify(result),
|
||||
);
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "danger",
|
||||
title: "Error",
|
||||
text: "There was a problem submitting the confirmation.",
|
||||
},
|
||||
5000,
|
||||
);
|
||||
this.notify.error("There was a problem submitting the confirmation.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1089,15 +1007,7 @@ export default class ClaimView extends Vue {
|
||||
useClipboard()
|
||||
.copy(text)
|
||||
.then(() => {
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "toast",
|
||||
title: "Copied",
|
||||
text: (name || "That") + " was copied to the clipboard.",
|
||||
},
|
||||
2000,
|
||||
);
|
||||
this.notify.copied(name || "That");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1141,15 +1051,7 @@ export default class ClaimView extends Vue {
|
||||
await this.$logError(
|
||||
"Unrecognized claim type for edit: " + this.veriClaim.claimType,
|
||||
);
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "danger",
|
||||
title: "Error",
|
||||
text: "This is an unrecognized claim type.",
|
||||
},
|
||||
3000,
|
||||
);
|
||||
this.notify.error("This is an unrecognized claim type.", TIMEOUTS.STANDARD);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user