Open source personal finance application
feat: hide tabs and simplify sum for single-type categories
Ilya Komichev61c153ba02a4
diff --git a/app/components/categories/page/id/Index.vue b/app/components/categories/page/id/Index.vueindex 5365bd1e..7852acfe 100644--- a/app/components/categories/page/id/Index.vue+++ b/app/components/categories/page/id/Index.vue@@ -14,6 +14,7 @@ import { filterKey, statConfigKey, statDateKey } from '~/components/stat/injectiimport { useStatConfig } from '~/components/stat/useStatConfig'import { getTypesMapping } from '~/components/stat/utils'import { useTrnsFormStore } from '~/components/trnForm/useTrnsFormStore'+import { TrnType } from '~/components/trns/types'import { useTrnsStore } from '~/components/trns/useTrnsStore'import { showErrorToast, showSuccessToast } from '~/composables/useStoreSync'@@ -78,7 +79,39 @@ const category = computed(() => categoriesStore.items[categoryId.value])const preCategoriesIds = computed(() => categoriesStore.getChildrenIds(categoryId.value))const categoriesIdsOrParent = computed(() => categoriesStore.getChildrenIdsOrParent(categoryId.value))-const activeTab = useStorage<StatTabSlug>(`page-${categoryId.value}-tab`, 'summary')+const allTrnsIds = computed(() => trnsStore.getStoreTrnsIds({+ categoriesIds: categoriesIdsOrParent.value,+}))++const singleTrnType = computed<StatTabSlug | null>(() => {+ const items = trnsStore.items+ if (!items)+ return null+ let hasExpense = false+ let hasIncome = false+ for (const id of allTrnsIds.value) {+ const trn = items[id]+ if (!trn)+ continue+ if (trn.type === TrnType.Expense)+ hasExpense = true+ if (trn.type === TrnType.Income)+ hasIncome = true+ if (hasExpense && hasIncome)+ return null+ }+ if (hasExpense)+ return 'expense'+ if (hasIncome)+ return 'income'+ return null+})++const storedTab = useStorage<StatTabSlug>(`page-${categoryId.value}-tab`, 'summary')+const activeTab = computed({+ get: () => singleTrnType.value ?? storedTab.value,+ set: (v: StatTabSlug) => { storedTab.value = v },+})const storageKey = computed(() => `page-${categoryId.value}-${activeTab.value}`)const trnsIds = computed(() => trnsStore.getStoreTrnsIds({@@ -188,6 +221,7 @@ const categoriesIds = computed(() => categoriesStore.getChildrenIds(categoryId.v<StatHeaderv-model:activeTab="activeTab":backTo="category.parentId ? `/categories/${category.parentId}` : '/categories'"+ :hideTabs="!!singleTrnType"filterWallets><template #title>diff --git a/app/components/stat/ConfigModal.vue b/app/components/stat/ConfigModal.vueindex fe8a51f1..15e406e0 100644--- a/app/components/stat/ConfigModal.vue+++ b/app/components/stat/ConfigModal.vue@@ -7,7 +7,6 @@ import { useWalletsStore } from '~/components/wallets/useWalletsStore'const props = defineProps<{isShowWallets?: booleanlabelMode?: boolean- onBeforeOpen?: () => void}>()const statConfig = inject(statConfigKey)!@@ -23,7 +22,7 @@ const isOpen = ref(false):title="t('stat.config.menu.label')":isOpenisShowCloseBtn- @openModal="() => { props.onBeforeOpen?.(); isOpen = true }"+ @openModal="isOpen = true"@closeModal="isOpen = false"><template #trigger>diff --git a/app/components/stat/Header.vue b/app/components/stat/Header.vueindex d81868bb..acc1e613 100644--- a/app/components/stat/Header.vue+++ b/app/components/stat/Header.vue@@ -6,11 +6,12 @@ import { filterKey, statConfigKey } from '~/components/stat/injectionKeys'import { useTrnsFormStore } from '~/components/trnForm/useTrnsFormStore'import { useWalletsStore } from '~/components/wallets/useWalletsStore'-defineProps<{+const props = defineProps<{backTo?: stringconfigWallets?: booleanfilterCategories?: booleanfilterWallets?: boolean+ hideTabs?: boolean}>()const activeTab = defineModel<StatTabSlug>('activeTab')@@ -68,18 +69,16 @@ const isPopoverOpen = ref(false)<template #content="{ close: closeContent }"><div class="min-w-52 p-1 pt-4 pb-3"><!-- Mobile: search, filters, config -->- <div class="mb-2 grid border-b border-(--ui-border) pb-3 sm:hidden">+ <div class="sm:hidden" :class="[$slots.popover ? 'mb-2 border-b border-(--ui-border) pb-3' : '']"><StatFilterSelectorv-if="filterCategories || filterWallets":isShowCategories="!!filterCategories":isShowWallets="!!filterWallets"- :onBeforeOpen="() => { closeContent?.(); isPopoverOpen = false }"labelMode/><StatConfigModal:isShowWallets="!!configWallets"- :onBeforeOpen="() => { closeContent?.(); isPopoverOpen = false }"labelMode/></div>@@ -93,7 +92,7 @@ const isPopoverOpen = ref(false)</BottomSheetOrDropdown></template>- <template v-if="activeTab" #selected>+ <template v-if="activeTab && !props.hideTabs" #selected><StatMenu:active="activeTab"@click="(id: StatTabSlug) => activeTab = id"diff --git a/app/components/stat/date/Navigation.vue b/app/components/stat/date/Navigation.vueindex caf682ac..ced05b9a 100644--- a/app/components/stat/date/Navigation.vue+++ b/app/components/stat/date/Navigation.vue@@ -50,7 +50,7 @@ function changeDate(way: 'next' | 'prev' | 'today') {</script><template>- <div class="items-top bg-default/90 sticky top-0 z-20 -mt-2 mr-12 flex grow items-center gap-2 overflow-x-auto py-2 pb-0 backdrop-blur sm:mr-0 lg:top-[87px]">+ <div class="items-top flex grow items-center gap-2 overflow-x-auto py-2 pb-0"><DateNavv-if="isShowNav && !statDate.params.value.customDate":isEnddiff --git a/app/components/stat/filter/Selector.vue b/app/components/stat/filter/Selector.vueindex c105e0b0..91f5d850 100644--- a/app/components/stat/filter/Selector.vue+++ b/app/components/stat/filter/Selector.vue@@ -5,7 +5,6 @@ const props = defineProps<{isShowCategories?: booleanisShowWallets?: booleanlabelMode?: boolean- onBeforeOpen?: () => void}>()const filter = inject(filterKey)!@@ -13,12 +12,11 @@ const { t } = useI18n()</script><template>- <div class="flex items-center">+ <div :class="props.labelMode ? 'grid' : 'flex items-center'"><StatFilterSelectorItemv-if="props.isShowWallets":hasSelection="filter?.walletsIds.value.length > 0":labelMode="props.labelMode"- :onBeforeOpen="props.onBeforeOpen":title="t('wallets.filter')"icon="hugeicons:wallet-01">@@ -34,7 +32,6 @@ const { t } = useI18n():buttonLabel="t('base.close')":hasSelection="filter?.categoriesIds.value.length > 0":labelMode="props.labelMode"- :onBeforeOpen="props.onBeforeOpen":title="t('categories.filter')"icon="hugeicons:folder-library">diff --git a/app/components/stat/filter/SelectorItem.vue b/app/components/stat/filter/SelectorItem.vueindex a790929a..6eb1a3e5 100644--- a/app/components/stat/filter/SelectorItem.vue+++ b/app/components/stat/filter/SelectorItem.vue@@ -4,7 +4,6 @@ const props = defineProps<{hasSelection: booleanicon: stringlabelMode?: boolean- onBeforeOpen?: () => voidtitle: string}>()@@ -18,7 +17,7 @@ const isOpen = ref(false):title="props.title":isOpen="isOpen"isShowCloseBtn- @openModal="() => { props.onBeforeOpen?.(); isOpen = true }"+ @openModal="isOpen = true"@closeModal="isOpen = false"><template #trigger>diff --git a/app/components/stat/sum/Item.vue b/app/components/stat/sum/Item.vueindex 675f661a..79e8a064 100644--- a/app/components/stat/sum/Item.vue+++ b/app/components/stat/sum/Item.vue@@ -7,6 +7,7 @@ const props = defineProps<{amount: numberaverageTotal?: Record<string, number>isActive?: boolean+ plain?: booleantitle?: stringtype: SeriesSlugSelected}>()@@ -21,8 +22,11 @@ const currenciesStore = useCurrenciesStore()<template><div- :class="cn('flex-1 flex-wrap rounded-sm border border-transparent bg-(--item-3) px-3 py-2 @2xl/stat:max-w-max',- props.isActive && 'bg-item-2 border-(--ui-primary)/40',+ :class="cn(+ props.plain+ ? 'px-3 pb-1 text-center'+ : 'flex-1 flex-wrap rounded-sm border border-transparent bg-(--item-3) px-3 py-2 @2xl/stat:max-w-max',+ props.isActive && 'bg-item-2 border-(--ui-primary)/40',)"@click="(e: Event) => emit('click', e)">@@ -38,6 +42,7 @@ const currenciesStore = useCurrenciesStore():class="{'!text-income-1': props.amount > 0 && props.type !== 'netIncome','!text-expense-1': props.amount < 0 && props.type !== 'netIncome',+ '!text-2xl': props.plain,}"align="left"variant="xl"diff --git a/app/components/stat/sum/Wrap.vue b/app/components/stat/sum/Wrap.vueindex d1ce7d03..9842e7ca 100644--- a/app/components/stat/sum/Wrap.vue+++ b/app/components/stat/sum/Wrap.vue@@ -92,12 +92,13 @@ function onClick(type: SeriesSlugSelected) {</StatSumItem></div>- <div v-else class="flex items-center">+ <div v-else class="flex items-center justify-center sm:justify-start"><StatSumItem:amount="props.type === 'income' ? total.income : -((total as Record<string, number>)[props.type]!)":class="className":type="(props.type as SeriesSlugSelected)":averageTotal="isShowAverage ? props.averageTotal : undefined"+ plain@click="emit('clickAverage')"><StatAverage