From a67442133781cb75061dde3792942dee8167b377 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Sun, 31 Aug 2025 16:00:39 -0400 Subject: [PATCH] Remove profileStore and access selected profile only with route. --- web-app/src/api/account.ts | 6 ++-- web-app/src/api/profile.ts | 19 +++++++++++ web-app/src/api/transaction.ts | 6 ++-- .../src/components/AddValueRecordModal.vue | 5 +-- web-app/src/components/CategoryLabel.vue | 5 ++- .../src/components/history/AccountHistory.vue | 5 +-- .../history/JournalEntryHistoryItem.vue | 5 ++- .../history/ValueRecordHistoryItem.vue | 5 +-- web-app/src/pages/AccountPage.vue | 20 ++++-------- web-app/src/pages/MyUserPage.vue | 2 +- web-app/src/pages/ProfilePage.vue | 2 +- web-app/src/pages/ProfilesPage.vue | 11 ------- web-app/src/pages/TransactionPage.vue | 10 +++--- web-app/src/pages/forms/EditAccountPage.vue | 14 +++----- .../src/pages/forms/EditTransactionPage.vue | 15 +++------ web-app/src/pages/home/AccountsModule.vue | 14 +++----- web-app/src/pages/home/ProfileModule.vue | 32 +++++++++++++------ web-app/src/pages/home/TransactionsModule.vue | 11 +++---- web-app/src/router/index.ts | 20 ++++++------ web-app/src/stores/profile-store.ts | 32 ------------------- 20 files changed, 96 insertions(+), 143 deletions(-) delete mode 100644 web-app/src/stores/profile-store.ts diff --git a/web-app/src/api/account.ts b/web-app/src/api/account.ts index 72d581a..601d903 100644 --- a/web-app/src/api/account.ts +++ b/web-app/src/api/account.ts @@ -1,7 +1,7 @@ import { ApiClient } from './base' import type { Currency } from './data' import type { Page, PageRequest } from './pagination' -import type { Profile } from './profile' +import { getSelectedProfile } from './profile' export interface AccountType { id: string @@ -125,9 +125,9 @@ export interface AccountHistoryJournalEntryItem extends AccountHistoryItem { export class AccountApiClient extends ApiClient { readonly path: string - constructor(profile: Profile) { + constructor() { super() - this.path = `/profiles/${profile.name}/accounts` + this.path = `/profiles/${getSelectedProfile()}/accounts` } getAccounts(): Promise { diff --git a/web-app/src/api/profile.ts b/web-app/src/api/profile.ts index 754ca59..8d41562 100644 --- a/web-app/src/api/profile.ts +++ b/web-app/src/api/profile.ts @@ -1,3 +1,4 @@ +import { useRoute, type RouteLocation } from 'vue-router' import { ApiClient } from './base' export interface Profile { @@ -30,3 +31,21 @@ export class ProfileApiClient extends ApiClient { return super.getJson(`/profiles/${profileName}/properties`) } } + +/** + * 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. + * @returns The currently selected profile name, via the current route. + */ +export function getSelectedProfile(route: RouteLocation = useRoute()): string { + if (!('profileName' in route.params)) { + throw new Error('No "profileName" route property available.') + } + const name = route.params.profileName + if (Array.isArray(name)) { + throw new Error('"profileName" route property is an array. Expected a single string.') + } + return name +} diff --git a/web-app/src/api/transaction.ts b/web-app/src/api/transaction.ts index 021beea..e3c4400 100644 --- a/web-app/src/api/transaction.ts +++ b/web-app/src/api/transaction.ts @@ -1,7 +1,7 @@ -import { useProfileStore } from '@/stores/profile-store' 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 @@ -146,9 +146,7 @@ export class TransactionApiClient extends ApiClient { constructor() { super() - const profileStore = useProfileStore() - if (!profileStore.state) throw new Error('No profile state!') - this.path = `/profiles/${profileStore.state.name}` + this.path = `/profiles/${getSelectedProfile()}` } getVendors(): Promise { diff --git a/web-app/src/components/AddValueRecordModal.vue b/web-app/src/components/AddValueRecordModal.vue index dddd6b2..05072da 100644 --- a/web-app/src/components/AddValueRecordModal.vue +++ b/web-app/src/components/AddValueRecordModal.vue @@ -6,12 +6,10 @@ import FormGroup from './form/FormGroup.vue'; import ModalWrapper from './ModalWrapper.vue'; import AppButton from './AppButton.vue'; import { AccountApiClient, AccountValueRecordType, type Account, type AccountValueRecord, type AccountValueRecordCreationPayload } from '@/api/account'; -import { useProfileStore } from '@/stores/profile-store'; import { datetimeLocalToISO, getDatetimeLocalValueForNow } from '@/util/time'; import FileSelector from './FileSelector.vue'; const props = defineProps<{ account: Account }>() -const profileStore = useProfileStore() const modal = useTemplateRef('modal') const savedValueRecord: Ref = ref(undefined) @@ -33,13 +31,12 @@ async function show(): Promise { } async function addValueRecord() { - if (!profileStore.state) return const payload: AccountValueRecordCreationPayload = { timestamp: datetimeLocalToISO(timestamp.value), type: AccountValueRecordType.BALANCE, value: amount.value } - const api = new AccountApiClient(profileStore.state) + const api = new AccountApiClient() try { savedValueRecord.value = await api.createValueRecord(props.account.id, payload, attachments.value) modal.value?.close('saved') diff --git a/web-app/src/components/CategoryLabel.vue b/web-app/src/components/CategoryLabel.vue index aaa9f54..6d08950 100644 --- a/web-app/src/components/CategoryLabel.vue +++ b/web-app/src/components/CategoryLabel.vue @@ -1,6 +1,6 @@ diff --git a/web-app/src/components/history/AccountHistory.vue b/web-app/src/components/history/AccountHistory.vue index 7714133..d49ddff 100644 --- a/web-app/src/components/history/AccountHistory.vue +++ b/web-app/src/components/history/AccountHistory.vue @@ -1,7 +1,6 @@