Skip to content

Open source personal finance application

refactor: improve storage key generation for category stat pages

Ilya Komichev27e6b7fddcc1
diff --git a/app/components/categories/StatPage.vue b/app/components/categories/StatPage.vue
index 615c2eab..aaf3e350 100644
--- a/app/components/categories/StatPage.vue
+++ b/app/components/categories/StatPage.vue
@@ -26,8 +26,8 @@ const categoryId = computed(() => route.params.id) as ComputedRef<CategoryId>
const category = ref(categoriesStore.items[categoryId.value])
const categoriesIdsOrParent = computed(() => categoriesStore.getChildsIdsOrParent(categoryId.value))
-const activeTab = useStorage<StatTabSlug>(`${categoryId.value}-tab`, 'netIncome')
-const storageKey = computed(() => `${categoryId.value}-${activeTab.value}`)
+const activeTab = useStorage<StatTabSlug>(`stat-${categoryId.value}-tab`, 'netIncome')
+const storageKey = computed(() => `stat-${categoryId.value}-${activeTab.value}`)
const trnsIds = computed(() => {
const categoriesIds = [...filter.categoriesIds.value, ...categoriesIdsOrParent.value]
diff --git a/app/components/categories/page/id/Index.vue b/app/components/categories/page/id/Index.vue
index 4194df8a..f7d82554 100644
--- a/app/components/categories/page/id/Index.vue
+++ b/app/components/categories/page/id/Index.vue
@@ -1,11 +1,13 @@
<script setup lang="ts">
import { useStorage } from '@vueuse/core'
+import { differenceInDays } from 'date-fns'
import type { CategoryId } from '~/components/categories/types'
import type { StatTabSlug } from '~/components/stat/types'
import { useCategoriesStore } from '~/components/categories/useCategoriesStore'
import { useStatDate } from '~/components/date/useStatDate'
+import { calculateBestIntervalsBy } from '~/components/date/utils'
import { useFilter } from '~/components/filter/useFilter'
import { useStatConfig } from '~/components/stat/useStatConfig'
import { getTypesMapping } from '~/components/stat/utils'
@@ -27,8 +29,8 @@ const category = computed(() => categoriesStore.items[categoryId.value])
const preCategoriesIds = computed(() => categoriesStore.getChildsIds(categoryId.value))
const categoriesIdsOrParent = computed(() => categoriesStore.getChildsIdsOrParent(categoryId.value))
-const activeTab = useStorage<StatTabSlug>(`${categoryId.value}-tab`, 'netIncome')
-const storageKey = computed(() => `${categoryId.value}-${activeTab.value}`)
+const activeTab = useStorage<StatTabSlug>(`page-${categoryId.value}-tab`, 'netIncome')
+const storageKey = computed(() => `page-${categoryId.value}-${activeTab.value}`)
const trnsIds = computed(() => trnsStore.getStoreTrnsIds({
categoriesIds: [...filter.categoriesIds.value, ...categoriesIdsOrParent.value],
@@ -56,6 +58,14 @@ const statConfig = useStatConfig({
provide('statConfig', statConfig)
const statDate = useStatDate({
+ initParams: {
+ intervalsBy: calculateBestIntervalsBy(maxRange.value),
+ intervalsDuration: 1,
+ isShowMaxRange: true,
+ isSkipEmpty: true,
+ rangeBy: 'day',
+ rangeDuration: differenceInDays(maxRange.value.end, maxRange.value.start),
+ },
key: storageKey.value,
maxRange,
queryParams: route.query,