Skip to content

Open source personal finance application

refactor: rename semantically misleading functions and variables

Ilya Komichev5214e3087120
diff --git a/app/components/amount/useAmount.ts b/app/components/amount/useAmount.ts
index 4b31e057..aa5fa035 100644
--- a/app/components/amount/useAmount.ts
+++ b/app/components/amount/useAmount.ts
@@ -36,7 +36,7 @@ export function useAmount() {
const baseCurrencyCode = computed(() => currenciesStore.base)
- function getTotalOfTrnsIds(trnsIds?: TrnId[]): TotalReturns {
+ function computeTotalForTrnsIds(trnsIds?: TrnId[]): TotalReturns {
return getTotal({
baseCurrencyCode: currenciesStore.base,
rates: currenciesStore.rates,
@@ -48,7 +48,7 @@ export function useAmount() {
return {
baseCurrencyCode,
+ computeTotalForTrnsIds,
getAmountInBaseRate,
- getTotalOfTrnsIds,
}
}
diff --git a/app/components/app/Onboarding.vue b/app/components/app/Onboarding.vue
index e9672be1..b5f00470 100644
--- a/app/components/app/Onboarding.vue
+++ b/app/components/app/Onboarding.vue
@@ -53,7 +53,7 @@ const introText = computed(() => {
v-else
size="xl"
class="min-w-52 justify-center rounded-full px-8 py-3"
- @click="trnsFormStore.trnFormCreate()"
+ @click="trnsFormStore.openFormForCreate()"
>
{{ t('onboarding.actionTrn') }}
</UButton>
diff --git a/app/components/categories/StatPage.vue b/app/components/categories/StatPage.vue
index df6b2110..807c30f5 100644
--- a/app/components/categories/StatPage.vue
+++ b/app/components/categories/StatPage.vue
@@ -69,7 +69,7 @@ onMounted(() => {
statConfig.updateConfig('catsList', { isGrouped: false })
statConfig.updateConfig('catsRound', { isGrouped: false })
- if (categoriesStore.isItTransactible(categoryId.value))
+ if (categoriesStore.isTransactible(categoryId.value))
trnsFormStore.values.categoryId = categoryId.value
})
diff --git a/app/components/categories/page/id/Index.vue b/app/components/categories/page/id/Index.vue
index 8014b9f7..1e3b9df9 100644
--- a/app/components/categories/page/id/Index.vue
+++ b/app/components/categories/page/id/Index.vue
@@ -79,7 +79,7 @@ onActivated(() => {
statConfig.updateConfig('catsRound', { isGrouped: false })
statConfig.updateConfig('vertical', { isGrouped: false })
- if (categoriesStore.isItTransactible(categoryId.value))
+ if (categoriesStore.isTransactible(categoryId.value))
trnsFormStore.values.categoryId = categoryId.value
})
diff --git a/app/components/categories/useCategoriesStore.ts b/app/components/categories/useCategoriesStore.ts
index bf51e15f..6958ff59 100644
--- a/app/components/categories/useCategoriesStore.ts
+++ b/app/components/categories/useCategoriesStore.ts
@@ -43,7 +43,7 @@ type CategoriesStore = {
hasChildren: (categoryId: CategoryId) => boolean
hasItems: ComputedRef<boolean>
initCategories: () => void
- isItTransactible: (categoryId: CategoryId) => boolean
+ isTransactible: (categoryId: CategoryId) => boolean
items: ShallowRef<Categories>
recentCategoriesIds: ComputedRef<CategoryId[]>
saveCategory: (params: AddCategoryParams) => Promise<RemapInfo | void> | void
@@ -217,7 +217,7 @@ export const useCategoriesStore = defineStore('categories', (): CategoriesStore
return getTransactibleCategoriesIds(items.value ?? {}, ids)
}
- function isItTransactible(categoryId: CategoryId) {
+ function isTransactible(categoryId: CategoryId) {
return transactibleIdsSet.value.has(categoryId)
}
@@ -327,7 +327,7 @@ export const useCategoriesStore = defineStore('categories', (): CategoriesStore
hasChildren,
hasItems,
initCategories,
- isItTransactible,
+ isTransactible,
items,
recentCategoriesIds,
saveCategory,
diff --git a/app/components/date/useStatDate.ts b/app/components/date/useStatDate.ts
index 5a2611d5..f2fc6b2d 100644
--- a/app/components/date/useStatDate.ts
+++ b/app/components/date/useStatDate.ts
@@ -1,35 +1,12 @@
import { useStorage } from '@vueuse/core'
import { differenceInDays } from 'date-fns'
import defu from 'defu'
-import { z } from 'zod/v4'
import type { Grouped, IntervalGroupedLabel, Range, StatDateParams, StatDateParamsQuery } from '~/components/date/types'
-import { periods } from '~/components/date/types'
-import { calculateBestIntervalsBy, calculateIntervalInRange, getEndOf, getIntervalsInRange } from '~/components/date/utils'
-
-const queryParamsSchema = z.object({
- intervalsBy: z.enum(periods).optional(),
- intervalsDuration: z.string().transform(val => Number(val)).pipe(z.number().int()).optional(),
- intervalSelected: z.string().transform(val => Number(val)).pipe(z.number().int()).optional(),
- isShowMaxRange: z.string().transform(val => val === 'true').optional(),
- isSkipEmpty: z.string().transform(val => val === 'true').optional(),
- rangeBy: z.enum(periods).optional(),
- rangeDuration: z.string().transform(val => Number(val)).pipe(z.number().int()).optional(),
- rangeOffset: z.string().transform(val => Number(val)).pipe(z.number().int()).optional(),
-})
-
-const defaultParams: StatDateParams = {
- customDate: false,
- intervalsBy: 'day',
- intervalsDuration: 1,
- intervalSelected: -1,
- isShowMaxRange: false,
- isSkipEmpty: false,
- rangeBy: 'day',
- rangeDuration: 14,
- rangeOffset: 0,
-}
+import { calculateBestIntervalsBy, getIntervalsInRange } from '~/components/date/utils'
+
+import { computeDateRange, defaultStatDateParams, parseStatDateQueryParams } from './statDateParams'
export function useStatDate({
initParams,
@@ -47,65 +24,20 @@ export function useStatDate({
})
if (Object.keys(params.value).length === 0) {
- params.value = defu(initParams ?? {}, defaultParams)
+ params.value = defu(initParams ?? {}, defaultStatDateParams)
}
- const modals = ref({
+ const modal = ref({
dateSelector: false,
})
if (queryParams) {
- const parsed = queryParamsSchema.safeParse(queryParams)
-
- if (parsed.success) {
- const data = parsed.data
- if (data.intervalsBy)
- params.value.intervalsBy = data.intervalsBy
- if (data.intervalsDuration)
- params.value.intervalsDuration = data.intervalsDuration
- if (data.intervalSelected)
- params.value.intervalSelected = data.intervalSelected
- if (data.rangeBy)
- params.value.rangeBy = data.rangeBy
- if (data.rangeDuration)
- params.value.rangeDuration = data.rangeDuration
- if (data.rangeOffset)
- params.value.rangeOffset = data.rangeOffset
- if (data.isShowMaxRange !== undefined)
- params.value.isShowMaxRange = data.isShowMaxRange
- if (data.isSkipEmpty !== undefined)
- params.value.isSkipEmpty = data.isSkipEmpty
- }
+ params.value = parseStatDateQueryParams(queryParams, params.value)
}
- const range = computed<Range>(() => {
- if (params.value.customDate) {
- return params.value.customDate
- }
-
- else if (params.value.isShowMaxRange && params.value.isSkipEmpty) {
- return { ...maxRange.value }
- }
-
- else if (params.value.isShowMaxRange && !params.value.isSkipEmpty) {
- return {
- end: getEndOf(new Date(), params.value.rangeBy).getTime(),
- start: maxRange.value.start,
- }
- }
-
- const range = calculateIntervalInRange({
- intervalsBy: params.value.rangeBy,
- intervalsDuration: params.value.rangeDuration,
- range: {
- end: new Date().getTime(),
- start: new Date().getTime(),
- },
- rangeOffset: params.value.rangeOffset,
- })
-
- return range
- })
+ const range = computed<Range>(() =>
+ computeDateRange(params.value, maxRange.value, new Date().getTime()),
+ )
const intervalsInRange = computed(() => getIntervalsInRange({
intervalsBy: params.value.intervalsBy,
@@ -200,7 +132,7 @@ export function useStatDate({
intervalsInRange,
maxRange,
minusRange,
- modals,
+ modal,
params,
plusRange,
range,
diff --git a/app/components/layout/useMenuData.ts b/app/components/layout/useMenuData.ts
index a5018b44..f35f434f 100644
--- a/app/components/layout/useMenuData.ts
+++ b/app/components/layout/useMenuData.ts
@@ -15,7 +15,7 @@ export type MenuItem = {
export function useMenuData() {
const isMenuOpen = ref(false)
const { t } = useI18n()
- const { trnFormCreate } = useTrnsFormStore()
+ const { openFormForCreate } = useTrnsFormStore()
const walletsStore = useWalletsStore()
const categoriesStore = useCategoriesStore()
const route = useRoute()
@@ -79,7 +79,7 @@ export function useMenuData() {
if (menuId === 'trnForm') {
if (walletsStore.hasItems && categoriesStore.hasItems)
- trnFormCreate()
+ openFormForCreate()
return
}
diff --git a/app/components/offline/helpers.ts b/app/components/offline/helpers.ts
index 9ce59e2d..cee84c62 100644
--- a/app/components/offline/helpers.ts
+++ b/app/components/offline/helpers.ts
@@ -28,12 +28,12 @@ const OLD_KEYS = [
'finapp.trns.offline.delete',
]
-let oldKeysCleaned = false
+let isOldKeysCleaned = false
async function cleanOldKeys() {
- if (oldKeysCleaned)
+ if (isOldKeysCleaned)
return
- oldKeysCleaned = true
+ isOldKeysCleaned = true
for (const key of OLD_KEYS)
await localforage.removeItem(key)
}
diff --git a/app/components/stat/Average.vue b/app/components/stat/Average.vue
index 434f7983..366734ec 100644
--- a/app/components/stat/Average.vue
+++ b/app/components/stat/Average.vue
@@ -27,7 +27,7 @@ const props = defineProps<{
const { t } = useI18n()
const currenciesStore = useCurrenciesStore()
const trnsStore = useTrnsStore()
-const { getTotalOfTrnsIds } = useAmount()
+const { computeTotalForTrnsIds } = useAmount()
const untilDate = computed(() => getEndOf(sub(new Date(), { [`${props.statDate.params.value.rangeBy}s`]: props.statDate.params.value.rangeDuration }), props.statDate.params.value.rangeBy))
@@ -45,7 +45,7 @@ const datedTrnsIds = computed(() => trnsStore.getStoreTrnsIds({
walletsIds: props.walletId ? [...(props.filter.walletsIds.value ?? []), props.walletId] : props.filter.walletsIds.value,
}))
-const total = computed(() => getTotalOfTrnsIds(datedTrnsIds.value))
+const total = computed(() => computeTotalForTrnsIds(datedTrnsIds.value))
</script>
<template>
diff --git a/app/components/stat/ConfigModal.vue b/app/components/stat/ConfigModal.vue
index c4ac849c..99464b26 100644
--- a/app/components/stat/ConfigModal.vue
+++ b/app/components/stat/ConfigModal.vue
@@ -62,13 +62,13 @@ function updateStatAverage(value: number) {
</UiTitleSection>
<UiSwitchItem
- :checkboxValue="statConfig.config.value.chartShow"
+ :checkboxValue="statConfig.config.value.isChartShow"
:title="t('stat.config.chartShow.label')"
- @click="statConfig.updateConfig('chartShow', !statConfig.config.value.chartShow)"
+ @click="statConfig.updateConfig('isChartShow', !statConfig.config.value.isChartShow)"
/>
<UiSwitchItem
- v-if="statConfig.config.value.chartShow"
+ v-if="statConfig.config.value.isChartShow"
:checkboxValue="statConfig.config.value.date.isShowQuick"
:title="t('stat.config.date.quick.label')"
@click="statConfig.updateConfig('date', { isShowQuick: !statConfig.config.value.date.isShowQuick })"
@@ -76,7 +76,7 @@ function updateStatAverage(value: number) {
<!-- Chart: showed -->
<div
- v-if="statConfig.config.value.chartShow"
+ v-if="statConfig.config.value.isChartShow"
class="grid gap-4"
>
<UiSwitchItem
diff --git a/app/components/stat/categories/Line.vue b/app/components/stat/categories/Line.vue
index 1c0b8d33..38127f8d 100644
--- a/app/components/stat/categories/Line.vue
+++ b/app/components/stat/categories/Line.vue
@@ -50,11 +50,11 @@ const longPressRef = ref(null)
onLongPress(
longPressRef,
() => {
- const isTransactible = categoriesStore.isItTransactible(props.item.id)
+ const isTransactible = categoriesStore.isTransactible(props.item.id)
if (!isTransactible)
return
- trnsFormStore.trnFormCreate()
+ trnsFormStore.openFormForCreate()
trnsFormStore.$patch((state) => {
state.values.amount = [0, 0, 0]
state.values.amountRaw = ['', '', '']
diff --git a/app/components/stat/categories/Round2lines.vue b/app/components/stat/categories/Round2lines.vue
index 5c3d06e6..861e5687 100644
--- a/app/components/stat/categories/Round2lines.vue
+++ b/app/components/stat/categories/Round2lines.vue
@@ -27,11 +27,11 @@ const longPressRef = ref(null)
onLongPress(
longPressRef,
() => {
- const isTransactible = categoriesStore.isItTransactible(props.item.id)
+ const isTransactible = categoriesStore.isTransactible(props.item.id)
if (!isTransactible)
return
- trnsFormStore.trnFormCreate()
+ trnsFormStore.openFormForCreate()
trnsFormStore.$patch((state) => {
state.values.amount = [0, 0, 0]
state.values.amountRaw = ['', '', '']
diff --git a/app/components/stat/categories/Section.vue b/app/components/stat/categories/Section.vue
index 621b6a9e..0cfdd999 100644
--- a/app/components/stat/categories/Section.vue
+++ b/app/components/stat/categories/Section.vue
@@ -19,11 +19,11 @@ const emit = defineEmits<{
const visibleCategoriesLimit = 12
-const { getCategoriesWithData } = useStatCategories()
+const { computeCategoriesWithData } = useStatCategories()
const statConfig = inject(statConfigKey)!
const isExpanded = ref(false)
-const roundCategories = computed(() => getCategoriesWithData(props.selectedTrnsIds ?? [], statConfig.config.value.catsRound.isGrouped, props.preCategoriesIds))
+const roundCategories = computed(() => computeCategoriesWithData(props.selectedTrnsIds ?? [], statConfig.config.value.catsRound.isGrouped, props.preCategoriesIds))
const visibleCategories = computed(() => isExpanded.value ? roundCategories.value : roundCategories.value.slice(0, visibleCategoriesLimit))
</script>
diff --git a/app/components/stat/categories/Section2.vue b/app/components/stat/categories/Section2.vue
index 2d995887..d00ff50b 100644
--- a/app/components/stat/categories/Section2.vue
+++ b/app/components/stat/categories/Section2.vue
@@ -23,21 +23,21 @@ const emit = defineEmits<{
}>()
const { t } = useI18n()
-const { getCategoriesWithData } = useStatCategories()
+const { computeCategoriesWithData } = useStatCategories()
const categoriesStore = useCategoriesStore()
const statConfig = inject(statConfigKey)!
// Lazy computeds — each computed only when accessed (Vue computed is lazy).
// Replaces the old `categoriesStat` which eagerly computed BOTH variants on every change.
-const groupedCategories = computed(() => getCategoriesWithData(props.selectedTrnsIds ?? [], true))
-const ungroupedCategories = computed(() => getCategoriesWithData(props.selectedTrnsIds ?? [], false))
+const groupedCategories = computed(() => computeCategoriesWithData(props.selectedTrnsIds ?? [], true))
+const ungroupedCategories = computed(() => computeCategoriesWithData(props.selectedTrnsIds ?? [], false))
const categoriesWithData = computed<CategoryWithData[]>(() => {
const isGrouped = statConfig.config.value[statConfig.config.value.catsView === 'list' ? 'catsList' : 'catsRound'].isGrouped
// When showing empty categories, need a separate call with preCategoriesIds
if (statConfig.config.value.isShowEmptyCategories && props.preCategoriesIds?.length) {
- return getCategoriesWithData(props.selectedTrnsIds ?? [], isGrouped, props.preCategoriesIds)
+ return computeCategoriesWithData(props.selectedTrnsIds ?? [], isGrouped, props.preCategoriesIds)
}
return isGrouped ? groupedCategories.value : ungroupedCategories.value
diff --git a/app/components/stat/categories/Vertical.vue b/app/components/stat/categories/Vertical.vue
index fc15082a..deede875 100644
--- a/app/components/stat/categories/Vertical.vue
+++ b/app/components/stat/categories/Vertical.vue
@@ -55,11 +55,11 @@ const longPressRef = ref(null)
onLongPress(
longPressRef,
() => {
- const isTransactible = categoriesStore.isItTransactible(props.item.id)
+ const isTransactible = categoriesStore.isTransactible(props.item.id)
if (!isTransactible)
return
- trnsFormStore.trnFormCreate()
+ trnsFormStore.openFormForCreate()
trnsFormStore.$patch((state) => {
state.values.amount = [0, 0, 0]
state.values.amountRaw = ['', '', '']
diff --git a/app/components/stat/categories/useStatCategories.ts b/app/components/stat/categories/useStatCategories.ts
index eb9eecc5..f7afa142 100644
--- a/app/components/stat/categories/useStatCategories.ts
+++ b/app/components/stat/categories/useStatCategories.ts
@@ -10,11 +10,11 @@ import { useTrnsStore } from '~/components/trns/useTrnsStore'
export function useStatCategories() {
const categoriesStore = useCategoriesStore()
const trnsStore = useTrnsStore()
- const { getTotalOfTrnsIds } = useAmount()
+ const { computeTotalForTrnsIds } = useAmount()
- const computeValue = (trnsIds: TrnId[]) => getTotalOfTrnsIds(trnsIds).sum
+ const computeValue = (trnsIds: TrnId[]) => computeTotalForTrnsIds(trnsIds).sum
- function getCategoriesWithData(trnsIds: TrnId[], isGrouped?: boolean, preCategoriesIds?: CategoryId[]): CategoryWithData[] {
+ function computeCategoriesWithData(trnsIds: TrnId[], isGrouped?: boolean, preCategoriesIds?: CategoryId[]): CategoryWithData[] {
const collected = collectCategoriesByTrns({
categoriesItems: categoriesStore.items,
preCategoriesIds,
@@ -28,6 +28,6 @@ export function useStatCategories() {
}
return {
- getCategoriesWithData,
+ computeCategoriesWithData,
}
}
diff --git a/app/components/stat/chart/Wrap.vue b/app/components/stat/chart/Wrap.vue
index 7db208f3..32300e8d 100644
--- a/app/components/stat/chart/Wrap.vue
+++ b/app/components/stat/chart/Wrap.vue
@@ -48,7 +48,7 @@ function onChangePeriod(period: Period) {
<template>
<div
- v-if="statConfig.config.value.chartShow"
+ v-if="statConfig.config.value.isChartShow"
:class="{
'@3xl/main:max-w-xl': props.chartView === 'half',
}"
diff --git a/app/components/stat/date/Navigation.vue b/app/components/stat/date/Navigation.vue
index d26acd5f..532311e3 100644
--- a/app/components/stat/date/Navigation.vue
+++ b/app/components/stat/date/Navigation.vue
@@ -67,11 +67,11 @@ function changeDate(way: 'next' | 'prev' | 'today') {
<BottomSheetOrDropdown
:title="t('dates.select')"
- :isOpen="statDate.modals.value.dateSelector"
+ :isOpen="statDate.modal.value.dateSelector"
class="flex grow-0 gap-1"
isShowCloseBtn
- @openModal="statDate.modals.value.dateSelector = true"
- @closeModal="statDate.modals.value.dateSelector = false"
+ @openModal="statDate.modal.value.dateSelector = true"
+ @closeModal="statDate.modal.value.dateSelector = false"
>
<template #trigger>
<UiTitleCollapse
diff --git a/app/components/stat/statConfig.test.ts b/app/components/stat/statConfig.test.ts
index 2c0bdb2e..41c0c5af 100644
--- a/app/components/stat/statConfig.test.ts
+++ b/app/components/stat/statConfig.test.ts
@@ -4,7 +4,7 @@ import type { MiniItemConfig } from '~/components/stat/useStatConfig'
import { ConfigSchema } from '~/components/stat/useStatConfig'
-import { mergeConfigUpdate } from './statConfig'
+import { applyConfigUpdate } from './statConfig'
const defaultConfig: MiniItemConfig = {
catsList: {
@@ -22,12 +22,12 @@ const defaultConfig: MiniItemConfig = {
chart: {
isShowAverage: false,
},
- chartShow: true,
chartType: 'bar',
chartView: 'full',
date: {
isShowQuick: false,
},
+ isChartShow: true,
isShowEmptyCategories: false,
statAverage: {
count: 10,
@@ -59,7 +59,7 @@ describe('configSchema', () => {
})
it('rejects missing required field', () => {
- const { chartShow: _, ...incomplete } = defaultConfig
+ const { isChartShow: _, ...incomplete } = defaultConfig
expect(ConfigSchema.safeParse(incomplete).success).toBe(false)
})
@@ -74,27 +74,27 @@ describe('configSchema', () => {
})
})
-describe('mergeConfigUpdate', () => {
+describe('applyConfigUpdate', () => {
it('updates a primitive value', () => {
- const result = mergeConfigUpdate(defaultConfig, 'chartShow', false as any)
+ const result = applyConfigUpdate(defaultConfig, 'isChartShow', false as any)
expect(result).not.toBeNull()
- expect(result!.chartShow).toBe(false)
+ expect(result!.isChartShow).toBe(false)
})
it('updates chartType', () => {
- const result = mergeConfigUpdate(defaultConfig, 'chartType', 'line' as any)
+ const result = applyConfigUpdate(defaultConfig, 'chartType', 'line' as any)
expect(result).not.toBeNull()
expect(result!.chartType).toBe('line')
})
it('updates chartView', () => {
- const result = mergeConfigUpdate(defaultConfig, 'chartView', 'half' as any)
+ const result = applyConfigUpdate(defaultConfig, 'chartView', 'half' as any)
expect(result).not.toBeNull()
expect(result!.chartView).toBe('half')
})
it('deep-merges nested object', () => {
- const result = mergeConfigUpdate(defaultConfig, 'catsList', { isGrouped: false })
+ const result = applyConfigUpdate(defaultConfig, 'catsList', { isGrouped: false })
expect(result).not.toBeNull()
expect(result!.catsList.isGrouped).toBe(false)
// Other fields preserved via defu
@@ -103,30 +103,30 @@ describe('mergeConfigUpdate', () => {
})
it('deep-merges wallets count', () => {
- const result = mergeConfigUpdate(defaultConfig, 'wallets', { count: 12 })
+ const result = applyConfigUpdate(defaultConfig, 'wallets', { count: 12 })
expect(result).not.toBeNull()
expect(result!.wallets.count).toBe(12)
expect(result!.wallets.isShow).toBe(false) // preserved
})
it('returns null for invalid value', () => {
- const result = mergeConfigUpdate(defaultConfig, 'chartType', 'invalid' as any)
+ const result = applyConfigUpdate(defaultConfig, 'chartType', 'invalid' as any)
expect(result).toBeNull()
})
it('returns null for invalid nested value', () => {
- const result = mergeConfigUpdate(defaultConfig, 'wallets', { count: 'bad' } as any)
+ const result = applyConfigUpdate(defaultConfig, 'wallets', { count: 'bad' } as any)
expect(result).toBeNull()
})
it('does not mutate original config', () => {
- const original = { ...defaultConfig, chartShow: true }
- mergeConfigUpdate(original, 'chartShow', false as any)
- expect(original.chartShow).toBe(true)
+ const original = { ...defaultConfig, isChartShow: true }
+ applyConfigUpdate(original, 'isChartShow', false as any)
+ expect(original.isChartShow).toBe(true)
})
it('preserves other keys when updating one', () => {
- const result = mergeConfigUpdate(defaultConfig, 'isShowEmptyCategories', true as any)
+ const result = applyConfigUpdate(defaultConfig, 'isShowEmptyCategories', true as any)
expect(result).not.toBeNull()
expect(result!.isShowEmptyCategories).toBe(true)
expect(result!.chartType).toBe('bar')
diff --git a/app/components/stat/statConfig.ts b/app/components/stat/statConfig.ts
new file mode 100644
index 00000000..c3890934
--- /dev/null
+++ b/app/components/stat/statConfig.ts
@@ -0,0 +1,25 @@
+import defu from 'defu'
+
+import type { MiniItemConfig } from '~/components/stat/useStatConfig'
+
+import { ConfigSchema } from '~/components/stat/useStatConfig'
+
+/**
+ * Compute a new config by merging a partial update into the current config.
+ * Returns the new config, or null if the result fails Zod validation.
+ */
+export function applyConfigUpdate(
+ current: MiniItemConfig,
+ key: keyof MiniItemConfig,
+ value: Partial<MiniItemConfig[keyof MiniItemConfig]>,
+): MiniItemConfig | null {
+ const update = {
+ ...current,
+ [key]: typeof value === 'object' ? defu(value, current[key]) : value,
+ }
+
+ if (!ConfigSchema.safeParse(update).success)
+ return null
+
+ return update as MiniItemConfig
+}
diff --git a/app/components/stat/useStatConfig.ts b/app/components/stat/useStatConfig.ts
index 34614c26..b2e25476 100644
--- a/app/components/stat/useStatConfig.ts
+++ b/app/components/stat/useStatConfig.ts
@@ -5,6 +5,7 @@ import defu from 'defu'
import { z } from 'zod/v4'
import { chartTypes } from '~/components/stat/chart/types'
+import { applyConfigUpdate } from '~/components/stat/statConfig'
export const chartViewOptions = ['half', 'full'] as const
@@ -24,12 +25,12 @@ export const ConfigSchema = z.object({
chart: z.object({
isShowAverage: z.boolean(),
}),
- chartShow: z.boolean(),
chartType: z.enum(chartTypes),
chartView: z.enum(chartViewOptions),
date: z.object({
isShowQuick: z.boolean(),
}),
+ isChartShow: z.boolean(),
isShowEmptyCategories: z.boolean(),
statAverage: z.object({
count: z.number(),
@@ -71,14 +72,14 @@ export function useStatConfig({ props, storageKey }: StatConfigParams) {
chart: {
isShowAverage: false,
},
- chartShow: true,
chartType: 'bar',
chartView: 'full',
-
date: {
isShowQuick: false,
},
+ isChartShow: true,
+
isShowEmptyCategories: false,
statAverage: {
@@ -108,13 +109,9 @@ export function useStatConfig({ props, storageKey }: StatConfigParams) {
}
function updateConfig(key: keyof MiniItemConfig, value: Partial<MiniItemConfig[keyof MiniItemConfig]>) {
- const update = { ...config.value, [key]: typeof value === 'object' ? defu(value, config.value[key]) : value }
-
- if (!ConfigSchema.safeParse(update).success) {
- return
- }
-
- config.value = update
+ const result = applyConfigUpdate(config.value, key, value)
+ if (result)
+ config.value = result
}
return {
diff --git a/app/components/stat/useStatItem.ts b/app/components/stat/useStatItem.ts
index d8d3b11f..58fd61d9 100644
--- a/app/components/stat/useStatItem.ts
+++ b/app/components/stat/useStatItem.ts
@@ -36,7 +36,7 @@ export function useStatItem({
type,
}: UseStatItemParams) {
const trnsStore = useTrnsStore()
- const { getTotalOfTrnsIds } = useAmount()
+ const { computeTotalForTrnsIds } = useAmount()
const { addMarkArea, createSeriesItem } = useStatChart()
const newBaseStorageKey = computed(() =>
@@ -66,11 +66,11 @@ export function useStatItem({
}))
const intervalsData = computed(() =>
- bucketTrnsByIntervals(trnsStore.items ?? {}, rangeTrnsIds.value, statDate.intervalsInRange.value, getTotalOfTrnsIds),
+ bucketTrnsByIntervals(trnsStore.items ?? {}, rangeTrnsIds.value, statDate.intervalsInRange.value, computeTotalForTrnsIds),
)
const intervalsDataWithFilteredCategories = computed(() =>
- bucketTrnsByIntervals(trnsStore.items ?? {}, rangeTrnsIdsWithFilteredCategories.value, statDate.intervalsInRange.value, getTotalOfTrnsIds),
+ bucketTrnsByIntervals(trnsStore.items ?? {}, rangeTrnsIdsWithFilteredCategories.value, statDate.intervalsInRange.value, computeTotalForTrnsIds),
)
const selectedTrnsIds = computed(() => trnsStore.getStoreTrnsIds({
@@ -94,7 +94,7 @@ export function useStatItem({
const ids = statDate.params.value.intervalSelected !== -1
? intervalsDataWithFilteredCategories.value[statDate.params.value.intervalSelected]?.trnsIds
: rangeTrnsIdsWithFilteredCategories.value
- return getTotalOfTrnsIds(ids)
+ return computeTotalForTrnsIds(ids)
})
const averageTotal = computed(() => {
diff --git a/app/components/trnForm/EditedTrn.vue b/app/components/trnForm/EditedTrn.vue
index 44cfd237..6ca41dcf 100644
--- a/app/components/trnForm/EditedTrn.vue
+++ b/app/components/trnForm/EditedTrn.vue
@@ -17,7 +17,7 @@ const items = computed(() => ({
duplicate: {
click: () => {
if (trnsFormStore.values.trnId) {
- trnsFormStore.trnFormDuplicate(trnsFormStore.values.trnId)
+ trnsFormStore.openFormForDuplicate(trnsFormStore.values.trnId)
trnsFormStore.values.trnId = null
}
},
diff --git a/app/components/trnForm/FloatOpener.vue b/app/components/trnForm/FloatOpener.vue
index 303b981d..96918f6a 100644
--- a/app/components/trnForm/FloatOpener.vue
+++ b/app/components/trnForm/FloatOpener.vue
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { useTrnsFormStore } from '~/components/trnForm/useTrnsFormStore'
-const { trnFormCreate, ui } = useTrnsFormStore()
+const { openFormForCreate, ui } = useTrnsFormStore()
</script>
<template>
@@ -12,7 +12,7 @@ const { trnFormCreate, ui } = useTrnsFormStore()
justify-end from-transparent to-(--item-5)
transition hover:bg-gradient-to-r xl:flex
"
- @click="trnFormCreate()"
+ @click="openFormForCreate()"
>
<div
class="
diff --git a/app/components/trnForm/Main.vue b/app/components/trnForm/Main.vue
index 4520934a..1a0e54bd 100644
--- a/app/components/trnForm/Main.vue
+++ b/app/components/trnForm/Main.vue
@@ -39,7 +39,7 @@ const walletId = computed(() => {
:amount="trnsFormStore.values.amount[trnsFormStore.activeAmountIdx]"
:amountRaw="trnsFormStore.values.amountRaw[trnsFormStore.activeAmountIdx]"
:highlight="trnsFormStore.values.trnType === 0 ? 'expense' : 'income'"
- :isShowSum="trnsFormStore.getIsShowSum()"
+ :isShowSum="trnsFormStore.shouldShowSum()"
class="px-3 pb-2"
@change="trnsFormStore.onChangeAmount"
/>
diff --git a/app/components/trnForm/main/ActionSide.vue b/app/components/trnForm/main/ActionSide.vue
index bf8e9b40..91d075e1 100644
--- a/app/components/trnForm/main/ActionSide.vue
+++ b/app/components/trnForm/main/ActionSide.vue
@@ -5,7 +5,7 @@ import { useTrnsStore } from '~/components/trns/useTrnsStore'
const trnsStore = useTrnsStore()
const trnsFormStore = useTrnsFormStore()
-const isMath = computed(() => trnsFormStore.getIsShowSum())
+const isMath = computed(() => trnsFormStore.shouldShowSum())
const isSubmittable = computed(() => trnsFormStore.values.amount[trnsFormStore.activeAmountIdx] > 0)
async function onClickSubmit() {
diff --git a/app/components/trnForm/main/AmountTransfer.vue b/app/components/trnForm/main/AmountTransfer.vue
index b4582842..05514ea1 100644
--- a/app/components/trnForm/main/AmountTransfer.vue
+++ b/app/components/trnForm/main/AmountTransfer.vue
@@ -123,7 +123,7 @@ function copyAmount() {
:amount="trnsFormStore.values.amount[item.amountsIdx]"
:amountRaw="trnsFormStore.values.amountRaw[item.amountsIdx]"
:highlight="item.transferType"
- :isShowSum="trnsFormStore.getIsShowSum()"
+ :isShowSum="trnsFormStore.shouldShowSum()"
isTransfer
@change="trnsFormStore.onChangeAmount"
/>
diff --git a/app/components/trnForm/useTrnsFormStore.ts b/app/components/trnForm/useTrnsFormStore.ts
index 897fb4ac..c4c54ec8 100644
--- a/app/components/trnForm/useTrnsFormStore.ts
+++ b/app/components/trnForm/useTrnsFormStore.ts
@@ -78,7 +78,7 @@ export const useTrnsFormStore = defineStore('trnForm', () => {
onChangeAmount(value)
}
- function getIsShowSum() {
+ function shouldShowSum() {
if (values.trnType === TrnType.Transfer) {
const expense = values.amount[1] !== 0
&& formatInput(values.amount[1]) !== values.amountRaw[1]
@@ -223,7 +223,7 @@ export const useTrnsFormStore = defineStore('trnForm', () => {
values.amountRaw[0] = formatInput(0)
}
- function trnFormEdit(trnId: TrnId) {
+ function openFormForEdit(trnId: TrnId) {
const trn = trnsStore.items[trnId]
setValues({
@@ -236,7 +236,7 @@ export const useTrnsFormStore = defineStore('trnForm', () => {
ui.value.isShow = true
}
- function trnFormCreate() {
+ function openFormForCreate() {
setValues({
action: 'create',
categoriesIds: categoriesStore.categoriesIdsForTrnValues,
@@ -247,7 +247,7 @@ export const useTrnsFormStore = defineStore('trnForm', () => {
ui.value.isShow = true
}
- function trnFormDuplicate(trnId: TrnId) {
+ function openFormForDuplicate(trnId: TrnId) {
const trn = trnsStore.items?.[trnId] as TrnItem
if (!trn)
@@ -268,7 +268,6 @@ export const useTrnsFormStore = defineStore('trnForm', () => {
$reset,
activeAmountIdx,
closeTrnFormModal,
- getIsShowSum,
modal,
onChangeAmount,
onChangeCountSum,
@@ -278,10 +277,11 @@ export const useTrnsFormStore = defineStore('trnForm', () => {
onClickCalculator,
onClose,
onSubmit,
+ openFormForCreate,
+ openFormForDuplicate,
+ openFormForEdit,
openTrnFormModal,
- trnFormCreate,
- trnFormDuplicate,
- trnFormEdit,
+ shouldShowSum,
ui,
values,
}
diff --git a/app/components/trns/List.vue b/app/components/trns/List.vue
index 1a84ab41..b3bb9e26 100644
--- a/app/components/trns/List.vue
+++ b/app/components/trns/List.vue
@@ -43,7 +43,7 @@ const currenciesStore = useCurrenciesStore()
const trnsStore = useTrnsStore()
const trnsFormStore = useTrnsFormStore()
-const { getTotalOfTrnsIds } = useAmount()
+const { computeTotalForTrnsIds } = useAmount()
const { t } = useI18n()
const { formatDate } = useDateFormats()
const isShowWithDesc = ref(false)
@@ -98,7 +98,7 @@ const filteredByTypeIds = computed(() => {
return trnsStore.items[id]?.categoryId === 'adjustment'
if (filterBy.value === 'transfer')
- return trnsStore.items[id]?.type === selectedTypeFilter.value?.type || trnsStore.items[id]?.categoryId === 'transfer'
+ return trnsStore.items[id]?.type === selectedTypeFilter.value?.type
return trnsStore.items[id]?.type === selectedTypeFilter.value?.type
})
@@ -144,7 +144,7 @@ const groupedTrns = computed(() => paginatedTrnsIds.value
return acc
}, {} as Record<string, TrnId[]>))
-const paginatedTotal = computed(() => getTotalOfTrnsIds(paginatedTrnsIds.value))
+const paginatedTotal = computed(() => computeTotalForTrnsIds(paginatedTrnsIds.value))
const trnItemsMap = computed(() => {
const map = new Map<TrnId, ReturnType<typeof trnsStore.computeTrnItem>>()
@@ -155,7 +155,7 @@ const trnItemsMap = computed(() => {
})
function onOpenTrnForm(date: number) {
- trnsFormStore.trnFormCreate()
+ trnsFormStore.openFormForCreate()
trnsFormStore.$patch((state) => {
state.values.date = date
})
@@ -280,8 +280,8 @@ function onOpenTrnForm(date: number) {
class="opacity-60"
>
<Amount
- v-if="getTotalOfTrnsIds(groupTrnsIds).income !== 0"
- :amount="getTotalOfTrnsIds(groupTrnsIds).income"
+ v-if="computeTotalForTrnsIds(groupTrnsIds).income !== 0"
+ :amount="computeTotalForTrnsIds(groupTrnsIds).income"
:currencyCode="currenciesStore.base"
:isShowBaseRate="false"
:type="TrnType.Income"
@@ -290,8 +290,8 @@ function onOpenTrnForm(date: number) {
/>
<Amount
- v-if="getTotalOfTrnsIds(groupTrnsIds).expense !== 0"
- :amount="getTotalOfTrnsIds(groupTrnsIds).expense"
+ v-if="computeTotalForTrnsIds(groupTrnsIds).expense !== 0"
+ :amount="computeTotalForTrnsIds(groupTrnsIds).expense"
:currencyCode="currenciesStore.base"
:isShowBaseRate="false"
:type="TrnType.Expense"
diff --git a/app/components/trns/getTrns.test.ts b/app/components/trns/getTrns.test.ts
index 8b741872..fe65d49a 100644
--- a/app/components/trns/getTrns.test.ts
+++ b/app/components/trns/getTrns.test.ts
@@ -1,12 +1,12 @@
import { describe, expect, it } from 'vitest'
import { trnsItems } from '~~/mocks/trns'
-import { getTrnsIds } from '~/components/trns/getTrns'
+import { filterTrnsIds } from '~/components/trns/getTrns'
describe('get Transactions IDs', () => {
it('get Transactions IDs in Wallet Cash USD', () => {
const walletsIds = ['walletCashUSD']
- const trnsIds = getTrnsIds({ trnsItems, walletsIds })
+ const trnsIds = filterTrnsIds({ trnsItems, walletsIds })
expect(trnsIds).toEqual(expect.arrayContaining([
'transactionIncomeWalletCashUSD1000',
@@ -20,7 +20,7 @@ describe('get Transactions IDs', () => {
it('get Transactions IDs in Wallet RUB', () => {
const walletsIds = ['walletRUB']
- const trnsIds = getTrnsIds({ trnsItems, walletsIds })
+ const trnsIds = filterTrnsIds({ trnsItems, walletsIds })
expect(trnsIds).toEqual(expect.arrayContaining([
'transferExpenseWalletRUB300IncomeWalletCreditUSD10',
@@ -29,7 +29,7 @@ describe('get Transactions IDs', () => {
})
it('get All Transactions', () => {
- const trnsIds = getTrnsIds({ trnsItems })
+ const trnsIds = filterTrnsIds({ trnsItems })
expect(trnsIds).toEqual(expect.arrayContaining([
'transactionIncomeWalletCashUSD1000',
diff --git a/app/components/trns/getTrns.ts b/app/components/trns/getTrns.ts
index c4c7efcd..4c40514e 100644
--- a/app/components/trns/getTrns.ts
+++ b/app/components/trns/getTrns.ts
@@ -1,6 +1,6 @@
import type { TrnId, TrnsGetterProps } from '~/components/trns/types'
-export function getTrnsIds(props: TrnsGetterProps) {
+export function filterTrnsIds(props: TrnsGetterProps) {
if (!props.trnsIds && !props.trnsItems)
return []
diff --git a/app/components/trns/itemWrap.vue b/app/components/trns/itemWrap.vue
index 1798825b..d474cbc6 100644
--- a/app/components/trns/itemWrap.vue
+++ b/app/components/trns/itemWrap.vue
@@ -19,7 +19,7 @@ const emit = defineEmits<{
const { t } = useI18n()
const trnsStore = useTrnsStore()
-const { trnFormDuplicate, trnFormEdit } = useTrnsFormStore()
+const { openFormForDuplicate, openFormForEdit } = useTrnsFormStore()
const showDeleteConfirm = ref(false)
@@ -32,7 +32,7 @@ const contextMenuItems = computed(() => [[
{
icon: 'lucide:copy',
label: t('base.duplicate'),
- onSelect: () => trnFormDuplicate(props.trnId),
+ onSelect: () => openFormForDuplicate(props.trnId),
},
], [
{
@@ -45,7 +45,7 @@ const contextMenuItems = computed(() => [[
function click() {
emit('click')
- trnFormEdit(props.trnId)
+ openFormForEdit(props.trnId)
}
function handleDeleteConfirm() {
diff --git a/app/components/trns/useTrnsStore.ts b/app/components/trns/useTrnsStore.ts
index 668a5c68..0ac1d581 100644
--- a/app/components/trns/useTrnsStore.ts
+++ b/app/components/trns/useTrnsStore.ts
@@ -12,7 +12,7 @@ import { useCategoriesStore } from '~/components/categories/useCategoriesStore'
import { getEndOf, getStartOf } from '~/components/date/utils'
import { useDemo } from '~/components/demo/useDemo'
import { STORAGE_KEYS } from '~/components/offline/storageKeys'
-import { getTrnsIds } from '~/components/trns/getTrns'
+import { filterTrnsIds } from '~/components/trns/getTrns'
import { TrnType } from '~/components/trns/types'
import { useWalletsStore } from '~/components/wallets/useWalletsStore'
import { createDebouncedPersist, handleMutationResult, isPersistBlocked, mergeOfflineOps, pushDeleteOp, pushSaveOp } from '~/composables/useStoreSync'
@@ -53,7 +53,7 @@ export const useTrnsStore = defineStore('trns', () => {
const items = shallowRef<Trns | null>(null)
function getStoreTrnsIds(props: TrnsGetterProps) {
- return getTrnsIds({
+ return filterTrnsIds({
...props,
categoriesIds: props.categoriesIds?.length
? categoriesStore.getTransactibleIds(props.categoriesIds)
@@ -99,7 +99,7 @@ export const useTrnsStore = defineStore('trns', () => {
for (const trnId of Object.keys(items.value)) {
const trn = items.value[trnId]
- if (!trn || trn.type === TrnType.Transfer || trn.categoryId === 'adjustment' || trn.categoryId === 'transfer')
+ if (!trn || trn.type === TrnType.Transfer || trn.categoryId === 'adjustment')
continue
if (trn.date > latestDate) {
latestDate = trn.date
diff --git a/app/layouts/default.vue b/app/layouts/default.vue
index f6789c9e..6facbb1f 100644
--- a/app/layouts/default.vue
+++ b/app/layouts/default.vue
@@ -63,7 +63,7 @@ defineShortcuts({
'meta_g': () => {
trnsFormStore.ui.isShow
? trnsFormStore.ui.isShow = false
- : trnsFormStore.trnFormCreate()
+ : trnsFormStore.openFormForCreate()
},
})
</script>