Open source personal finance application
refactor: enhance statistical components and UI consistency
Ilya Komicheve02dc1fc4dc2
diff --git a/app/components/bottomSheet/BottomSheetOrDropdown.vue b/app/components/bottomSheet/BottomSheetOrDropdown.vueindex a0afc2d9..248470ee 100644--- a/app/components/bottomSheet/BottomSheetOrDropdown.vue+++ b/app/components/bottomSheet/BottomSheetOrDropdown.vue@@ -26,7 +26,7 @@ const isLaptop = computed(() => width.value >= 766 && pointerType.value === 'mou:popper="{placement: props.placement ?? 'bottom-start',}"- class="group"+ class="group grow"><slot name="trigger" />diff --git a/app/components/stat/Average.vue b/app/components/stat/Average.vueindex b59c70fe..f87bd406 100644--- a/app/components/stat/Average.vue+++ b/app/components/stat/Average.vue@@ -1,40 +1,40 @@<script setup lang="ts">-import { useStorage } from '@vueuse/core'+// import { useStorage } from '@vueuse/core'import { sub } from 'date-fns'import type { CategoryId } from '~/components/categories/types'import type { Range, StatDateProvider } from '~/components/date/types'import type { FilterProvider } from '~/components/filter/types'+import type { StatTabSlug } from '~/components/stat/types'import type { TrnId } from '~/components/trns/types'import type { WalletId } from '~/components/wallets/types'import { useAmount } from '~/components/amount/useAmount'import { useCurrenciesStore } from '~/components/currencies/useCurrenciesStore'import { getEndOf, getStartOf } from '~/components/date/utils'-import { useGetDateRange } from '~/components/stat/date/useGetDateRange'+// import { useGetDateRange } from '~/components/stat/date/useGetDateRange'import { useTrnsStore } from '~/components/trns/useTrnsStore'const props = defineProps<{+ averageConfig: numbercategoryId?: CategoryIdfilter: FilterProviderstatDate: StatDateProvider+ statTabSlug: StatTabSlugtrnsIds: TrnId[]walletId?: WalletId}>()+const { t } = useI18n()const currenciesStore = useCurrenciesStore()const trnsStore = useTrnsStore()const { getTotalOfTrnsIds } = useAmount()-const averageConfig = useStorage('averageConfig', {- count: 10,-})-const untilDate = computed(() => getEndOf(sub(new Date(), { [`${props.statDate.params.value.rangeBy}s`]: props.statDate.params.value.rangeDuration }), props.statDate.params.value.rangeBy))const dates = computed<Range>(() => ({end: untilDate.value.getTime(),- start: getStartOf(sub(untilDate.value, { [`${props.statDate.params.value.rangeBy}s`]: (props.statDate.params.value.rangeDuration * averageConfig.value.count) - 1 }), props.statDate.params.value.rangeBy).getTime(),+ start: getStartOf(sub(untilDate.value, { [`${props.statDate.params.value.rangeBy}s`]: (props.statDate.params.value.rangeDuration * props.averageConfig) - 1 }), props.statDate.params.value.rangeBy).getTime(),}))const datedTrnsIds = computed(() => trnsStore.getStoreTrnsIds({@@ -48,85 +48,93 @@ const datedTrnsIds = computed(() => trnsStore.getStoreTrnsIds({includesChildCategories: true,}))-const { locale, t } = useI18n()-const { getStringDateRange } = useGetDateRange(t, locale.value)+// const { locale, t } = useI18n()+// const { getStringDateRange } = useGetDateRange(t, locale.value)const total = computed(() => getTotalOfTrnsIds(datedTrnsIds.value))-const last = computed(() => {- const rangeBy = props.statDate.params.value.rangeBy- const value = averageConfig.value.count * props.statDate.params.value.rangeDuration- return `${value} ${t(`dates.${rangeBy}.plural`, value)}`-})+// const last = computed(() => {+// const rangeBy = props.statDate.params.value.rangeBy+// const value = props.averageConfig * props.statDate.params.value.rangeDuration+// return `${value} ${t(`dates.${rangeBy}.plural`, value)}`+// })</script><template>- <div class="grid gap-4 pb-2 pl-3 md:max-w-lg">- <div class="grid w-full grow gap-1 pb-[2px]">- <UiTitle6 class="text-nowrap !leading-3">+ <div class="grid gap-4">+ <div class="grid w-full grow gap-1">+ <!-- <UiTitle6 class="text-nowrap !leading-3">{{ t('money.average') }}- <br>{{ t('for') }} {{ last }}+ <br>{{ t('forLast') }} {{ last }}<br>{{ getStringDateRange(dates, props.statDate.params.value.rangeBy, props.statDate.params.value.rangeDuration) }}+ </UiTitle6> -->++ <UiTitle6 class="text-nowrap !leading-3">+ {{ t('money.average') }}+ <br>{{ t('forLast') }}</UiTitle6>- <div class="flex gap-4 overflow-x-auto pb-2">+ <div class="flex gap-4"><Amount- :amount="total.income / averageConfig.count"+ v-if="statTabSlug === 'income'"+ :amount="total.income / props.averageConfig":currencyCode="currenciesStore.base":type="1"align="left"colorize="income"- variant="xl"+ variant="base"/><Amount- :amount="total.expense / averageConfig.count"+ v-if="statTabSlug === 'expense'"+ :amount="total.expense / props.averageConfig":currencyCode="currenciesStore.base":type="0"align="left"colorize="expense"- variant="xl"+ variant="base"/><Amount- :amount="total.sum / averageConfig.count"+ v-if="statTabSlug === 'netIncome'"+ :amount="total.sum / props.averageConfig"+ :colorize="total.sum > 0 ? 'income' : 'expense'":currencyCode="currenciesStore.base":type="total.sum > 0 ? 1 : 0"align="left"- :colorize="total.sum > 0 ? 'income' : 'expense'"- variant="xl"+ variant="base"/></div></div>- <div class="flex gap-1">+ <!-- <div class="flex gap-1"><UiItem2:class="[{- '!hocus:transparent opacity-30': averageConfig.count === 1,+ '!hocus:transparent opacity-30': props.averageConfig === 1,}]"- @click="averageConfig.count = averageConfig.count - 1"+ @click="props.averageConfig = props.averageConfig - 1"><Icon name="lucide:minus" /></UiItem2><FormInput- :value="averageConfig.count"+ :value="props.averageConfig":max="100"min="1"class="min-w-16 max-w-20 !px-2 text-center"type="number"- @updateValue="value => averageConfig.count = Number(value)"+ @updateValue="value => props.averageConfig = Number(value)"/><UiItem2- :class="{ '!hocus:transparent opacity-30': averageConfig.count >= 100 }"- @click="averageConfig.count = averageConfig.count + 1"+ :class="{ '!hocus:transparent opacity-30': props.averageConfig >= 100 }"+ @click="props.averageConfig = props.averageConfig + 1"><Icon name="lucide:plus" /></UiItem2>- </div>+ </div> --></div></template><i18n lang="yaml">en:- for: for the last+ forLast: for the last periodsru:- for: за прошлые+ forLast: за прошлые периоды</i18n>diff --git a/app/components/stat/Config.vue b/app/components/stat/Config.vueindex 30d314fa..73ce5fcf 100644--- a/app/components/stat/Config.vue+++ b/app/components/stat/Config.vue@@ -20,6 +20,13 @@ function updateWalletsLimit(value: number) {if (value <= walletsStore.sortedIds.length && value > 0)statConfig.updateConfig('wallets', { count: value })}++function updateStatAverage(value: number) {+ if (value <= 0)+ return++ statConfig.updateConfig('statAverage', { count: value })+}</script><template>@@ -154,7 +161,7 @@ function updateWalletsLimit(value: number) {</div><!-- Statistics -->- <div>+ <div class="pb-0"><UiTitleOption class="pb-2">{{ t('statistics.title') }}</UiTitleOption>@@ -164,6 +171,44 @@ function updateWalletsLimit(value: number) {:title="t('stat.config.date.quick.label')"@click="statConfig.updateConfig('date', { isShowQuick: !statConfig.config.value.date.isShowQuick })"/>++ <UiCheckbox+ :checkboxValue="statConfig.config.value.statAverage.isShow"+ :title="t('stat.config.statAverage.label')"+ @click="statConfig.updateConfig('statAverage', { isShow: !statConfig.config.value.statAverage.isShow })"+ />++ <div+ v-if="statConfig.config.value.statAverage.isShow"+ class="flex gap-4 pt-2"+ >+ <div class="flex gap-1">+ <UiItem2+ :class="[{+ '!hocus:transparent opacity-30': statConfig.config.value.statAverage.count === 1,+ }]"+ @click="updateStatAverage(statConfig.config.value.statAverage.count - 1)"+ >+ <Icon name="lucide:minus" />+ </UiItem2>+ <FormInput+ :placeholder="t('stat.config.showedWallets.placeholder')"+ :value="statConfig.config.value.statAverage.count"+ :max="walletsStore.sortedIds.length"+ min="1"+ class="max-w-20 !px-2 text-center"+ type="number"+ @updateValue="value => statConfig.updateConfig('statAverage', { count: +value })"+ />++ <UiItem2+ :class="{ '!hocus:transparent opacity-30': statConfig.config.value.statAverage.count >= walletsStore.sortedIds.length }"+ @click="updateStatAverage(statConfig.config.value.statAverage.count + 1)"+ >+ <Icon name="lucide:plus" />+ </UiItem2>+ </div>+ </div></div><slot />diff --git a/app/components/stat/Header.vue b/app/components/stat/Header.vueindex 90e71506..901d537c 100644--- a/app/components/stat/Header.vue+++ b/app/components/stat/Header.vue@@ -89,11 +89,11 @@ const statConfigModal: Ref<StatConfigModal> = ref({</div></template>- <template #after>- <div- v-if="filter.isShow?.value || statConfig.config.value.wallets.isShow || $slots.summary"- class="grid gap-2 px-2 pb-0 lg:px-4 2xl:px-8"- >+ <template+ v-if="filter.isShow?.value || statConfig.config.value.wallets.isShow || $slots.summary"+ #after+ >+ <div class="grid gap-2 px-2 pb-0 lg:px-4 2xl:px-8"><template v-if="filter.isShow?.value || statConfig.config.value.wallets.isShow"><FilterSelectedv-if="props.filter && filter.isShow?.value && filter.categoriesIds.value.length > 0 || (filter.walletsIds.value.length > 0 && !statConfig.config.value.wallets.isShow)"diff --git a/app/components/stat/Item.vue b/app/components/stat/Item.vueindex d3fec06f..2d5df38c 100644--- a/app/components/stat/Item.vue+++ b/app/components/stat/Item.vue@@ -18,6 +18,7 @@ import StatTrnsSection from '~/components/stat/trns/Section.vue'import { useTrnsStore } from '~/components/trns/useTrnsStore'const props = defineProps<{+ activeTab: StatTabSlughasChildren?: booleanisOneCategory?: booleanisQuickModal?: boolean@@ -209,7 +210,7 @@ function getIntervalsData(trnsIds: TrnId[], intervalsInRange: Range[]) {<div class="@container/stat"><StatChartWrapv-if="!props.isOneCategory || (props.isOneCategory && !categoriesStore.transferCategoriesIds.includes(categoryId))"- :chartView="statConfig.config.value.chartView"+ :chartView="activeTab === 'summary' ? 'half' : statConfig.config.value.chartView":series="chart.series.value":xAxisLabels="chart.xAxisLabels.value">@@ -222,24 +223,36 @@ function getIntervalsData(trnsIds: TrnId[], intervalsInRange: Range[]) {<StatSumWrapv-if="!props.isOneCategory || (props.isOneCategory && !categoriesStore.transferCategoriesIds.includes(categoryId))"+ :averageTotal:isShowExpense="statTypeShow.expense":isShowIncome="statTypeShow.income":selectedType="selectedType":total="rangeTotal"- :averageTotal:type="props.type"+ :isShowAverage="statConfig.config.value.statAverage.isShow"+ class="pb-2"@click="onClickSumItem"- />-- <!-- <StatAverage- :trnsIds- :statDate- :filter- :categoryId- :walletId- /> -->-- <div class="grid w-full gap-2">+ @clickAverage="statConfig.updateConfig('statAverage', { isShow: !statConfig.config.value.statAverage.isShow })"+ >+ <template #average>+ <StatAverage+ :averageConfig="statConfig.config.value.statAverage.count"+ :categoryId+ :filter+ :statDate+ :statTabSlug="props.type"+ :trnsIds+ :walletId+ />+ </template>+ </StatSumWrap>++ <div+ class="grid w-full gap-2"+ :class="{+ '@3xl/page:grid-cols-[1.2fr,1fr] @3xl/page:gap-8': props.activeTab !== 'summary',+ }"+ ><StatCategoriesSectionv-if="props.hasChildren || (props.preCategoriesIds ?? []).length > 0":isOneCategory="props.isOneCategory"diff --git a/app/components/stat/ItemWrap.vue b/app/components/stat/ItemWrap.vueindex 3e2ebff1..88ad4661 100644--- a/app/components/stat/ItemWrap.vue+++ b/app/components/stat/ItemWrap.vue@@ -50,6 +50,7 @@ const incomeTrnsIds = computed(() => trnsStore.getStoreTrnsIds({class="grid max-w-7xl gap-8 px-2 pb-24 md:grid-cols-2 lg:gap-8 lg:px-4 xl:py-2 2xl:px-8"><StatItem+ :activeTab="props.activeTab":hasChildren="props.hasChildren":isOneCategory="props.isOneCategory":preCategoriesIds="props.preCategoriesIds"@@ -60,6 +61,7 @@ const incomeTrnsIds = computed(() => trnsStore.getStoreTrnsIds({/><StatItem+ :activeTab="props.activeTab":hasChildren="props.hasChildren":isOneCategory="props.isOneCategory":preCategoriesIds="props.preCategoriesIds"@@ -75,6 +77,7 @@ const incomeTrnsIds = computed(() => trnsStore.getStoreTrnsIds({class="min-h-dvh max-w-7xl px-2 lg:px-4 xl:py-2 2xl:px-8"><StatItem+ :activeTab="props.activeTab":hasChildren="props.hasChildren":isOneCategory="props.isOneCategory":preCategoriesIds="props.preCategoriesIds"diff --git a/app/components/stat/Menu.vue b/app/components/stat/Menu.vueindex c32548dd..42a057b0 100644--- a/app/components/stat/Menu.vue+++ b/app/components/stat/Menu.vue@@ -57,7 +57,7 @@ watch(() => props.active, () => {</script><template>- <div class="flex gap-2">+ <div class="-mb-px flex gap-2"><divv-for="item in menu":key="item.id"diff --git a/app/components/stat/chart/Wrap.vue b/app/components/stat/chart/Wrap.vueindex b804bb6e..80613b42 100644--- a/app/components/stat/chart/Wrap.vue+++ b/app/components/stat/chart/Wrap.vue@@ -33,17 +33,12 @@ function onClickChart(idx: number) {if (statDate.params.value.intervalsBy === 'day' && statDate.params.value.intervalsDuration === 1) {const day = statDate.intervalsInRange.value[statDate.params.value.intervalSelected]?.start- if (day) {+ if (day)trnsFormStore.values.date = day- }}}}-const isShowChart = computed(() => {- return statConfig.config.value?.chartShow-})-function onChangePeriod(period: Period) {statDate.params.value.intervalSelected = -1statDate.params.value.intervalsBy = period@@ -57,7 +52,7 @@ function onChangePeriod(period: Period) {}"><div- v-if="isShowChart"+ v-if="statConfig.config.value?.chartShow"class="pb-2"><div class="flex justify-end">@@ -72,10 +67,10 @@ function onChangePeriod(period: Period) {</div><StatChartView- :xAxisLabels="props.xAxisLabels":chartType="statConfig.config.value?.chartType":period="statDate.params.value.intervalsBy":series="props.series"+ :xAxisLabels="props.xAxisLabels"@click="onClickChart"/></div>diff --git a/app/components/stat/date/Nav.vue b/app/components/stat/date/Nav.vueindex fb9e39f7..dad128ef 100644--- a/app/components/stat/date/Nav.vue+++ b/app/components/stat/date/Nav.vue@@ -16,6 +16,7 @@ const emit = defineEmits<{<div class="flex items-center gap-1"><UiItem3v-if="props.isShowNavHome"+ class="@xl/page:order-3"@click="emit('changeDate', 'today')"><Icon name="lucide:undo-2" size="20" />diff --git a/app/components/stat/date/Navigation.vue b/app/components/stat/date/Navigation.vueindex 802966ab..97e1869f 100644--- a/app/components/stat/date/Navigation.vue+++ b/app/components/stat/date/Navigation.vue@@ -57,15 +57,18 @@ function changeDate(way: 'next' | 'prev' | 'today') {</script><template>- <div class="items-top grid grid-cols-[1fr,auto] gap-2 md:max-w-lg">+ <div class="items-top @xl/page:pl-2 @xl/page:grid-cols-[auto,1fr] grid grid-cols-[1fr,auto] gap-2 md:max-w-lg"><BottomSheetOrDropdown:title="t('dates.select')":isOpen="statDate.modals.value.dateSelector"+ class="@xl/page:order-2 flex gap-1"@onOpenModal="statDate.modals.value.dateSelector = true"@onCloseModal="statDate.modals.value.dateSelector = false"><template #trigger>- <UiTitle8 isShown>+ <UiTitle8+ isShown+ ><StatDateRange /></UiTitle8></template>diff --git a/app/components/stat/sum/Item.vue b/app/components/stat/sum/Item.vueindex e377b085..f902178d 100644--- a/app/components/stat/sum/Item.vue+++ b/app/components/stat/sum/Item.vue@@ -30,23 +30,27 @@ const currenciesStore = useCurrenciesStore()}"@click="(e: Event) => emit('click', e)">- <UiTextSm1>- {{ props.isTotal ? $t('money.all') : '' }}- {{ $t(`money.${props.type}`) }}- </UiTextSm1>-<div class="flex items-end gap-5 overflow-hidden overflow-x-auto pb-2">- <Amount- :amount="props.amount"- :currencyCode="props.currencyCode || currenciesStore.base"- :class="{- '!text-income-1': props.amount > 0 && type !== 'summary',- '!text-expense-1': props.amount < 0 && type !== 'summary',- }"- align="left"- variant="xl"- v-bind="props.amountProps"- />+ <div class="grid gap-2">+ <UiTitleOption>+ {{ props.isTotal ? $t('money.all') : '' }}+ {{ $t(`money.${props.type}`) }}+ </UiTitleOption>++ <Amount+ :amount="props.amount"+ :currencyCode="props.currencyCode || currenciesStore.base"+ :class="{+ '!text-income-1': props.amount > 0 && type !== 'summary',+ '!text-expense-1': props.amount < 0 && type !== 'summary',+ }"+ align="left"+ variant="xl"+ v-bind="props.amountProps"+ />+ </div>++ <slot /><divv-if="props.averageTotal"diff --git a/app/components/stat/sum/Wrap.vue b/app/components/stat/sum/Wrap.vueindex d4e7ce3d..1c74727b 100644--- a/app/components/stat/sum/Wrap.vue+++ b/app/components/stat/sum/Wrap.vue@@ -6,6 +6,7 @@ import { getStyles } from '~/components/ui/getStyles'const props = defineProps<{averageTotal?: Record<string, number>+ isShowAverage: booleanisShowExpense: booleanisShowIncome: booleanselectedType: StatTabSlug@@ -15,6 +16,7 @@ const props = defineProps<{const emit = defineEmits<{click: [type: StatTabSlug]+ clickAverage: []}>()const classes = computed(() => {@@ -35,17 +37,17 @@ function onClick(type: StatTabSlug) {</script><template>- <div class="rounded-md pb-4 md:max-w-lg">+ <div><divv-if="props.type === 'netIncome'"- class="_justify-stretch flex flex-wrap"+ class="flex flex-wrap justify-stretch md:max-w-lg"><StatSumItemv-if="props.isShowExpense":amount="-total.expense":isActive="selectedType === 'expense'":class="classes"- class="_grow"+ class="grow"type="expense"@click="onClick('expense')"/>@@ -55,7 +57,7 @@ function onClick(type: StatTabSlug) {:amount="total.income":isActive="selectedType === 'income'":class="classes"- class="_grow"+ class="grow"type="income"@click="onClick('income')"/>@@ -64,7 +66,7 @@ function onClick(type: StatTabSlug) {v-if="props.isShowIncome && props.isShowExpense":amount="total.sum":class="classes"- class="_grow"+ class="grow"type="summary"@click="onClick('summary')"/>@@ -78,11 +80,14 @@ function onClick(type: StatTabSlug) {:amount="props.type === 'income' ? total[props.type] : -total[props.type]":class="classes":type="props.type"- :averageTotal="props.averageTotal"+ :averageTotal="props.isShowAverage ? props.averageTotal : undefined":amountProps="{variant: '3xl',}"- />+ @click="emit('clickAverage')"+ >+ <slot v-if="props.isShowAverage" name="average" />+ </StatSumItem></div></div></template>diff --git a/app/components/stat/useStatConfig.ts b/app/components/stat/useStatConfig.tsindex 0b30e542..92fc05ac 100644--- a/app/components/stat/useStatConfig.ts+++ b/app/components/stat/useStatConfig.ts@@ -18,31 +18,30 @@ export const ConfigSchema = z.object({isShowFavorites: z.boolean(),isShowRecent: z.boolean(),}),-catsRound: z.object({isGrouped: z.boolean(),isShowFavorites: z.boolean(),isShowRecent: z.boolean(),}),catsView: z.enum(['list', 'round']),-chart: z.object({isShowAverage: z.boolean(),}),-chartShow: z.boolean(),-chartType: z.enum(chartTypes),chartView: z.enum(chartViewOptions),date: z.object({isShowQuick: z.boolean(),}),isShowEmptyCategories: z.boolean(),+ statAverage: z.object({+ count: z.number(),+ isShow: z.boolean(),+ }),vertical: z.object({isGrouped: z.boolean(),isShow: z.boolean(),}),-wallets: z.object({count: z.number(),isShow: z.boolean(),@@ -81,7 +80,7 @@ export function useStatConfig({ props, storageKey }: StatConfigParams) {},chartShow: true,chartType: 'bar',- chartView: 'half',+ chartView: 'full',date: {isShowQuick: false,@@ -89,6 +88,11 @@ export function useStatConfig({ props, storageKey }: StatConfigParams) {isShowEmptyCategories: false,+ statAverage: {+ count: 10,+ isShow: true,+ },+vertical: {isGrouped: false,isShow: false,diff --git a/i18n/locales/en-US.js b/i18n/locales/en-US.jsindex 783a81fd..ef5f75ff 100644--- a/i18n/locales/en-US.js+++ b/i18n/locales/en-US.js@@ -284,6 +284,13 @@ export default {menu: {label: 'Page Settings',},+ statAverage: {+ count: {+ label: 'Count of wallets',+ placeholder: 'Select count of wallets',+ },+ title: 'Average values',+ },wallets: {label: 'Show wallets',title: 'Wallets',diff --git a/i18n/locales/ru-RU.js b/i18n/locales/ru-RU.jsindex 25fdf6c3..0b10ee44 100644--- a/i18n/locales/ru-RU.js+++ b/i18n/locales/ru-RU.js@@ -282,11 +282,19 @@ export default {label: 'Слайдер быстрого выбора даты',},},-menu: {label: 'Настройки страницы',},+ statAverage: {+ count: {+ label: 'Количество кошельков',+ placeholder: 'Выберите количество кошельков',+ },+ label: 'Показывать средние значения',+ title: 'Средние значения',+ },+wallets: {label: 'Показывать кошельки',title: 'Кошельки',