From 074b4ded1d2a59453e2ababaebbf0c54bef208fa Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Sun, 31 Aug 2025 16:43:37 -0400 Subject: [PATCH] Clean up profile handling again! --- web-app/src/api/account.ts | 5 +- web-app/src/api/profile.ts | 7 ++- web-app/src/api/transaction.ts | 5 +- .../src/components/AddValueRecordModal.vue | 4 +- web-app/src/components/AppButton.vue | 51 ++++++++++++++----- web-app/src/components/CategoryLabel.vue | 5 +- web-app/src/components/CategorySelect.vue | 6 ++- web-app/src/components/EditCategoryModal.vue | 5 +- web-app/src/components/EditVendorModal.vue | 5 +- web-app/src/components/PaginationControls.vue | 29 ++++++----- .../src/components/history/AccountHistory.vue | 4 +- .../history/JournalEntryHistoryItem.vue | 5 +- .../history/ValueRecordHistoryItem.vue | 5 +- web-app/src/pages/AccountPage.vue | 9 ++-- web-app/src/pages/CategoriesPage.vue | 10 ++-- web-app/src/pages/LoginPage.vue | 2 +- web-app/src/pages/MyUserPage.vue | 2 +- web-app/src/pages/ProfilePage.vue | 2 +- web-app/src/pages/ProfilesPage.vue | 8 +-- web-app/src/pages/TransactionPage.vue | 10 ++-- web-app/src/pages/VendorsPage.vue | 11 ++-- web-app/src/pages/forms/EditAccountPage.vue | 8 +-- .../src/pages/forms/EditTransactionPage.vue | 20 ++++---- web-app/src/pages/home/AccountsModule.vue | 9 ++-- web-app/src/pages/home/ProfileModule.vue | 7 +-- web-app/src/pages/home/TransactionsModule.vue | 14 ++--- 26 files changed, 152 insertions(+), 96 deletions(-) diff --git a/web-app/src/api/account.ts b/web-app/src/api/account.ts index 601d903..d7e69b4 100644 --- a/web-app/src/api/account.ts +++ b/web-app/src/api/account.ts @@ -1,3 +1,4 @@ +import { type RouteLocation } from 'vue-router' import { ApiClient } from './base' import type { Currency } from './data' import type { Page, PageRequest } from './pagination' @@ -125,9 +126,9 @@ export interface AccountHistoryJournalEntryItem extends AccountHistoryItem { export class AccountApiClient extends ApiClient { readonly path: string - constructor() { + constructor(route: RouteLocation) { super() - this.path = `/profiles/${getSelectedProfile()}/accounts` + this.path = `/profiles/${getSelectedProfile(route)}/accounts` } getAccounts(): Promise { diff --git a/web-app/src/api/profile.ts b/web-app/src/api/profile.ts index 8d41562..ef2e171 100644 --- a/web-app/src/api/profile.ts +++ b/web-app/src/api/profile.ts @@ -1,4 +1,4 @@ -import { useRoute, type RouteLocation } from 'vue-router' +import { type RouteLocation } from 'vue-router' import { ApiClient } from './base' export interface Profile { @@ -35,11 +35,10 @@ export class ProfileApiClient extends ApiClient { /** * Gets the currently selected profile. Throws an error in any case where * the route doesn't contain profile name information. - * @param route The route to get the profile from. Defaults to getting it from - * Vue's `useRoute()` which is available in component contexts. + * @param route The route to get the profile from. * @returns The currently selected profile name, via the current route. */ -export function getSelectedProfile(route: RouteLocation = useRoute()): string { +export function getSelectedProfile(route: RouteLocation): string { if (!('profileName' in route.params)) { throw new Error('No "profileName" route property available.') } diff --git a/web-app/src/api/transaction.ts b/web-app/src/api/transaction.ts index e3c4400..9c45165 100644 --- a/web-app/src/api/transaction.ts +++ b/web-app/src/api/transaction.ts @@ -1,7 +1,6 @@ import { ApiClient } from './base' import type { Currency } from './data' import { type Page, type PageRequest } from './pagination' -import { getSelectedProfile } from './profile' export interface TransactionVendor { id: number @@ -144,9 +143,9 @@ export interface CreateCategoryPayload { export class TransactionApiClient extends ApiClient { readonly path: string - constructor() { + constructor(profileName: string) { super() - this.path = `/profiles/${getSelectedProfile()}` + this.path = `/profiles/${profileName}` } getVendors(): Promise { diff --git a/web-app/src/components/AddValueRecordModal.vue b/web-app/src/components/AddValueRecordModal.vue index 05072da..23f198b 100644 --- a/web-app/src/components/AddValueRecordModal.vue +++ b/web-app/src/components/AddValueRecordModal.vue @@ -8,7 +8,9 @@ import AppButton from './AppButton.vue'; import { AccountApiClient, AccountValueRecordType, type Account, type AccountValueRecord, type AccountValueRecordCreationPayload } from '@/api/account'; import { datetimeLocalToISO, getDatetimeLocalValueForNow } from '@/util/time'; import FileSelector from './FileSelector.vue'; +import { useRoute } from 'vue-router'; +const route = useRoute() const props = defineProps<{ account: Account }>() const modal = useTemplateRef('modal') const savedValueRecord: Ref = ref(undefined) @@ -36,7 +38,7 @@ async function addValueRecord() { type: AccountValueRecordType.BALANCE, value: amount.value } - const api = new AccountApiClient() + const api = new AccountApiClient(route) try { savedValueRecord.value = await api.createValueRecord(props.account.id, payload, attachments.value) modal.value?.close('saved') diff --git a/web-app/src/components/AppButton.vue b/web-app/src/components/AppButton.vue index e4eb125..3de1e53 100644 --- a/web-app/src/components/AppButton.vue +++ b/web-app/src/components/AppButton.vue @@ -1,17 +1,35 @@