Open source personal finance application
refactor: small updates
Ilya Komichev86ba8fa61440
diff --git a/app/components/categories/useCategoriesStore.ts b/app/components/categories/useCategoriesStore.tsindex 0f71de3e..246bcc5e 100644--- a/app/components/categories/useCategoriesStore.ts+++ b/app/components/categories/useCategoriesStore.ts@@ -32,7 +32,6 @@ type CategoriesStore = {categoriesRootIds: ComputedRef<CategoryId[]>deleteCategory: (id: CategoryId, trnsIds?: TrnId[]) => Promise<void>favoriteCategoriesIds: ComputedRef<CategoryId[]>- formatCategories: (items: Categories) => CategoriesgetChildsIds: (categoryId: CategoryId) => CategoryId[]getChildsIdsOrParent: (categoryId: CategoryId) => CategoryId[]getTransactibleIds: (ids?: CategoryId[]) => CategoryId[]@@ -167,44 +166,6 @@ export const useCategoriesStore = defineStore('categories', (): CategoriesStore})})- function formatCategories(items: Categories): Categories {- const formattedItems = { ...items }-- // Step 1: Build parent-child relationships- for (const categoryId in formattedItems) {- const category = formattedItems[categoryId]- const parentId = category?.parentId-- if (!parentId || !formattedItems[parentId])- continue-- const parent = formattedItems[parentId]- parent.childIds = parent.childIds || []-- if (!parent.childIds.includes(categoryId))- parent.childIds.push(categoryId)- }-- // Step 2: Set default values and clean up invalid child references- for (const categoryId in formattedItems) {- const category = formattedItems[categoryId]!-- // Set default values for optional properties- formattedItems[categoryId] = {- ...category,- icon: category.icon.replace('mdi mdi-', 'mdi:'),- showInLastUsed: category.showInLastUsed ?? false,- showInQuickSelector: category.showInQuickSelector ?? false,- }-- // Remove references to non-existent child categories- if (category.childIds?.length)- formattedItems[categoryId].childIds = category.childIds.filter(childId => formattedItems[childId])- }-- return formattedItems- }-function initCategories() {getDataAndWatch(`users/${userStore.uid}/categories`,@@ -303,6 +264,44 @@ export const useCategoriesStore = defineStore('categories', (): CategoriesStore}}+ function formatCategories(items: Categories): Categories {+ const formattedItems = { ...items }++ // Step 1: Build parent-child relationships+ for (const categoryId in formattedItems) {+ const category = formattedItems[categoryId]+ const parentId = category?.parentId++ if (!parentId || !formattedItems[parentId])+ continue++ const parent = formattedItems[parentId]+ parent.childIds = parent.childIds || []++ if (!parent.childIds.includes(categoryId))+ parent.childIds.push(categoryId)+ }++ // Step 2: Set default values and clean up invalid child references+ for (const categoryId in formattedItems) {+ const category = formattedItems[categoryId]!++ // Set default values for optional properties+ formattedItems[categoryId] = {+ ...category,+ icon: category.icon.replace('mdi mdi-', 'mdi:'),+ showInLastUsed: category.showInLastUsed ?? false,+ showInQuickSelector: category.showInQuickSelector ?? false,+ }++ // Remove references to non-existent child categories+ if (category.childIds?.length)+ formattedItems[categoryId].childIds = category.childIds.filter(childId => formattedItems[childId])+ }++ return formattedItems+ }+return {addCategory,categoriesForBeParent,@@ -311,7 +310,6 @@ export const useCategoriesStore = defineStore('categories', (): CategoriesStorecategoriesRootIds,deleteCategory,favoriteCategoriesIds,- formatCategories,getChildsIds,getChildsIdsOrParent,getTransactibleIds,diff --git a/app/components/trnForm/utils/calculate.ts b/app/components/trnForm/utils/calculate.tsindex 5605c33f..232c134b 100644--- a/app/components/trnForm/utils/calculate.ts+++ b/app/components/trnForm/utils/calculate.ts@@ -10,10 +10,10 @@ type CalculatorOperator = '+' | '-' | '*' | '/'type CalculatorAction = '=' | 'c' | '.' | CalculatorOperatortype CalculatorInput = string | number-export type CalculatorKey =- | '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'- | '+' | '-' | '*' | '/'- | '.' | 'c'+export type CalculatorKey+ = | '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'+ | '+' | '-' | '*' | '/'+ | '.' | 'c'function splitExpression(value: string): string[] {return value.split(/([/*\-+])/).filter(Boolean)diff --git a/app/components/trns/types.ts b/app/components/trns/types.tsindex f72d8717..d24d97ae 100644--- a/app/components/trns/types.ts+++ b/app/components/trns/types.ts@@ -73,7 +73,6 @@ export type TrnItemFull = (Transaction | Transfer)export type TrnItemDirty = Transaction | Transfer | TransferDeprecatedexport type Trns = Record<TrnId, TrnItem>-export type TrnsDirty = Record<TrnId, TrnItemDirty>export type TrnsGetterProps = {categoriesIds?: CategoryId[]diff --git a/app/components/trns/useTrnsStore.ts b/app/components/trns/useTrnsStore.tsindex def4a8ca..f1ebca61 100644--- a/app/components/trns/useTrnsStore.ts+++ b/app/components/trns/useTrnsStore.ts@@ -67,9 +67,7 @@ export const useTrnsStore = defineStore('trns', () => {)})- const lastCreatedTrnItem = computed<TrnItem | false>(- () => items.value?.[lastCreatedTrnId.value],- )+ const lastCreatedTrnItem = computed<TrnItem | false>(() => items.value?.[lastCreatedTrnId.value])function initTrns() {const path = `users/${userStore.uid}/trns`@@ -77,7 +75,7 @@ export const useTrnsStore = defineStore('trns', () => {}function setTrns(values: Trns | null) {- const trns = normalizeTrns(values || {})+ const trns = values ? normalizeTrns(values) : nullitems.value = trnslocalforage.setItem('finapp.trns', deepUnref(trns))}diff --git a/app/components/wallets/useWalletsStore.ts b/app/components/wallets/useWalletsStore.tsindex da505824..57cffb97 100644--- a/app/components/wallets/useWalletsStore.ts+++ b/app/components/wallets/useWalletsStore.ts@@ -28,20 +28,6 @@ export const useWalletsStore = defineStore('wallets', () => {}function setWallets(values: Wallets | null) {- const normalizeWallets = (items: WalletsDirty): Wallets => {- return Object.entries(items).reduce((acc, [walletId, wallet]) => {- const normalizedWallet = normalizeWalletItem(wallet)- acc[walletId] = normalizedWallet.values- if (normalizedWallet.error && !isDemo) {- createOrUpdateWallet({- id: walletId,- values: normalizedWallet.values as WalletItem,- })- }- return acc- }, {} as Wallets)- }-const wallets = values ? normalizeWallets(values) : nullitems.value = walletslocalforage.setItem('finapp.wallets', deepUnref(wallets))@@ -144,6 +130,20 @@ export const useWalletsStore = defineStore('wallets', () => {}}+ function normalizeWallets(items: WalletsDirty): Wallets {+ return Object.entries(items).reduce((acc, [walletId, wallet]) => {+ const normalizedWallet = normalizeWalletItem(wallet)+ acc[walletId] = normalizedWallet.values+ if (normalizedWallet.error && !isDemo) {+ createOrUpdateWallet({+ id: walletId,+ values: normalizedWallet.values as WalletItem,+ })+ }+ return acc+ }, {} as Wallets)+ }+return {createOrUpdateWallet,currenciesUsed,