refactor: improve router type safety and usage

- Add explicit Router type imports across views
- Replace $router type casting with proper typing
- Use $router.back() instead of $router.go(-1) for consistency
- Add proper route and router typings to components
- Clean up router navigation methods
- Fix router push/back method calls

This commit improves type safety and consistency in router usage across
the application's view components.
This commit is contained in:
Matthew Raymer
2025-02-26 06:50:08 +00:00
parent a2e19d7e9a
commit f6802cd160
56 changed files with 581 additions and 251 deletions

View File

@@ -119,7 +119,10 @@
Copy Selections
</button>
<button @click="showCopySelectionsInfo()">
<font-awesome icon="circle-info" class="text-xl text-blue-500 ml-4" />
<font-awesome
icon="circle-info"
class="text-xl text-blue-500 ml-4"
/>
</button>
</div>
</div>
@@ -215,7 +218,10 @@
}"
title="See more about this person"
>
<font-awesome icon="circle-info" class="text-xl text-blue-500 ml-4" />
<font-awesome
icon="circle-info"
class="text-xl text-blue-500 ml-4"
/>
</router-link>
<span class="ml-4 text-sm overflow-hidden">{{
@@ -399,6 +405,8 @@ import { generateSaveAndActivateIdentity } from "../libs/util";
})
export default class ContactsView extends Vue {
$notify!: (notification: NotificationIface, timeout?: number) => void;
$route!: RouteLocationNormalizedLoaded;
$router!: Router;
activeDid = "";
apiServer = "";
@@ -465,8 +473,7 @@ export default class ContactsView extends Vue {
//
// For external links, use /contact-import/:jwt with a JWT that has an array of contacts
// because that will do better error checking for things like missing data on iOS platforms.
const importedContactJwt = (this.$route as RouteLocationNormalizedLoaded)
.query["contactJwt"] as string;
const importedContactJwt = this.$route.query["contactJwt"] as string;
if (importedContactJwt) {
// really should fully verify contents
const { payload } = decodeEndorserJwt(importedContactJwt);
@@ -481,14 +488,13 @@ export default class ContactsView extends Vue {
} as Contact;
await this.addContact(newContact);
// if we're here, they haven't redirected anywhere, so we'll redirect here without a query parameter
(this.$router as Router).push({ path: "/contacts" });
this.$router.push({ path: "/contacts" });
}
}
private async processInviteJwt() {
// handle an invite JWT sent via URL
const importedInviteJwt = (this.$route as RouteLocationNormalizedLoaded)
.query["inviteJwt"] as string;
const importedInviteJwt = this.$route.query["inviteJwt"] as string;
if (importedInviteJwt === "") {
// this happens when a platform (eg iOS) doesn't include anything after the "=" in a shared link.
this.$notify(
@@ -590,7 +596,7 @@ export default class ContactsView extends Vue {
);
}
// if we're here, they haven't redirected anywhere, so we'll redirect here without a query parameter
(this.$router as Router).push({ path: "/contacts" });
this.$router.push({ path: "/contacts" });
}
}
@@ -630,7 +636,7 @@ export default class ContactsView extends Vue {
title: "They're Added To Your List",
text: "Would you like to go to the main page now?",
onYes: async () => {
(this.$router as Router).push({ name: "home" });
this.$router.push({ name: "home" });
},
},
-1,
@@ -767,9 +773,7 @@ export default class ContactsView extends Vue {
if (contactInput.includes(CONTACT_IMPORT_CONFIRM_URL_PATH_TIME_SAFARI)) {
const jwt = getContactJwtFromJwtUrl(contactInput);
(this.$router as Router).push({
path: "/contact-import/" + jwt,
});
this.$router.push({ path: "/contact-import/" + jwt });
return;
}
@@ -877,7 +881,7 @@ export default class ContactsView extends Vue {
);
try {
const contacts = JSON.parse(jsonContactInput);
(this.$router as Router).push({
this.$router.push({
name: "contact-import",
query: { contacts: JSON.stringify(contacts) },
});
@@ -1203,7 +1207,7 @@ export default class ContactsView extends Vue {
this.showGiftedDialog(giverDid, recipientDid);
},
onYes: async () => {
(this.$router as Router).push({
this.$router.push({
name: "contact-amounts",
query: { contactDid: giverDid },
});
@@ -1403,10 +1407,10 @@ export default class ContactsView extends Vue {
if (hostResponse.data.data) {
// They're the host, take them to setup
(this.$router as Router).push({ name: "onboard-meeting-setup" });
this.$router.push({ name: "onboard-meeting-setup" });
} else {
// They're not the host, take them to list
(this.$router as Router).push({ name: "onboard-meeting-list" });
this.$router.push({ name: "onboard-meeting-list" });
}
} else {
// They're not in a meeting, show the dialog
@@ -1417,11 +1421,11 @@ export default class ContactsView extends Vue {
title: "Onboarding Meeting",
text: "Would you like to start a new meeting?",
onYes: async () => {
(this.$router as Router).push({ name: "onboard-meeting-setup" });
this.$router.push({ name: "onboard-meeting-setup" });
},
yesText: "Start New Meeting",
onNo: async () => {
(this.$router as Router).push({ name: "onboard-meeting-list" });
this.$router.push({ name: "onboard-meeting-list" });
},
noText: "Join Existing Meeting",
},