Open source personal finance application
improvements: refactor, useFilter
ilkome9ed4d97a65f8
diff --git a/components/categories/Form.vue b/components/categories/Form.vueindex 4a816215..b0d247a6 100644--- a/components/categories/Form.vue+++ b/components/categories/Form.vue@@ -43,7 +43,8 @@ function findCategoryWithThisColor(color) {if (!categoriesItems)return false- const categoryIdWithThisColor = $store.getters['categories/categoriesRootIds']?.find(id => categoriesItems[id]?.color === color)+ const categoryIdWithThisColor = $store.getters['categories/categoriesRootIds']+ ?.find(id => categoriesItems[id]?.color === color)if (categoryIdWithThisColor)return categoriesItems[categoryIdWithThisColor]?.icon@@ -51,10 +52,9 @@ function findCategoryWithThisColor(color) {/*** Get child categories ids- *- * @param categoryId*/-function getChildCategoriesIds(categoryId) {+function getChildCategoriesIds(categoryId: CategoryID) {+ // TODO: always return arrayif (!categoryId)return false@@ -63,6 +63,7 @@ function getChildCategoriesIds(categoryId) {const ids = []if (category?.parentId === 0) {+ // TODO: filterfor (const id in categoriesItems) {if (categoriesItems[id].parentId === categoryId)ids.push(id)@@ -272,7 +273,7 @@ divCategoriesList(:activeItemId="categoryForm.parentId"- :ids="$store.getters['categories/categoriesForBeParent'].filter(cId => cId !== categoryId)"+ :ids="$store.getters['categories/categoriesForBeParent'].filter(id => id !== categoryId)":slider="() => ({})"class="!gap-x-1"@onClick="onParentSelect"@@ -293,7 +294,7 @@ div//- Save//---------------------------------- .pt-4.pb-6+ .absolute.bottom-40.left-0.pt-4.pb-6SharedButton(:class="['_text-center _blue2 _ml-big', { _inline: $store.state.ui.pc }]":title="$t('wallets.form.save')"diff --git a/components/categories/Item.vue b/components/categories/Item.vueindex 249c1d77..79fbad35 100644--- a/components/categories/Item.vue+++ b/components/categories/Item.vue@@ -3,7 +3,7 @@ import useFilter from '~/components/filter/useFilter'export default defineComponent({props: {- activeItemId: { type: String, default: null },+ activeItemId: { type: String || 0, default: null },category: { type: Object, required: true },id: { type: String, required: true },isHideParentCategory: { type: Boolean, default: false },@@ -29,6 +29,7 @@ export default defineComponent({return}+ // TODO: useFiltersetFilterCatsId(props.id)$store.commit('filter/setFilterDateNow')$store.dispatch('ui/setActiveTabStat', 'details')diff --git a/components/categories/List.vue b/components/categories/List.vueindex f4b587d2..9e47421f 100644--- a/components/categories/List.vue+++ b/components/categories/List.vue@@ -1,33 +1,24 @@-<script>-export default {- props: {- activeItemId: { type: String, default: null },- ids: { type: Array, required: true },- isHideParentCategory: { type: Boolean, default: false },- slider: { type: Object, required: true },- },+<script setup lang="ts">+import type { CategoryID } from '~/components/categories/types'- computed: {- categoriesIds() {- if (this.limit)- return this.ids.slice(0, this.limit)-- return this.ids- },- },-}+defineProps<{+ ids: CategoryID[]+ activeItemId?: string | 0+ isHideParentCategory?: boolean+ slider?: object+}>()</script><template lang="pug">.grid.gap-y-1.gap-x-1.3sm_grid-cols-2.sm_gap-x-6CategoriesItem(- v-for="categoryId in categoriesIds"- :category="$store.state.categories.items[categoryId]"+ v-for="categoryId in ids":activeItemId="activeItemId"+ :category="$store.state.categories.items[categoryId]":id="categoryId"+ :isHideParentCategory="isHideParentCategory":key="categoryId":slider="slider"- :isHideParentCategory="isHideParentCategory"v-on="$listeners")</template>diff --git a/components/categories/page/List.vue b/components/categories/page/List.vueindex 810d0939..481b4fbb 100644--- a/components/categories/page/List.vue+++ b/components/categories/page/List.vue@@ -1,13 +1,6 @@<script setup lang="ts">const { $store } = useNuxtApp()--const catsIds = computed(() => $store.getters['categories/categoriesRootIds']?.sort((a, b) => {- if ($store.state.categories.items[a].name < $store.state.categories.items[b].name)- return -1- if ($store.state.categories.items[a].name > $store.state.categories.items[b].name)- return 1- return 0-}))+const categoriesRootIds = computed(() => $store.getters['categories/categoriesRootIds'])</script><script lang="ts">@@ -26,12 +19,12 @@ UiPageUiHeaderTitle {{ $t('categories.name') }}template(#actions)UiHeaderLink(@click="$router.push('/categories/new')")- UiIconAdd.group-hover_text-white.w-6.h-6+ UiIconAdd.w-5.h-5.group-hover_text-white//- List- .pb-12.px-2+ .pt-1.pb-12.px-2CategoriesList(- :ids="catsIds"+ :ids="categoriesRootIds"@onClick="catId => $router.push(`/categories/${catId}`)")diff --git a/components/categories/page/id/Edit.vue b/components/categories/page/id/Edit.vueindex b3a1f7c6..bec6fc17 100644--- a/components/categories/page/id/Edit.vue+++ b/components/categories/page/id/Edit.vue@@ -14,11 +14,11 @@ const categoryForm = ref({color: category.value?.color || random(allColors),icon: category.value?.icon || random(random(icons)),name: category.value?.name || null,- order: category.value?.order || 1,- parentId: category.value?.parentId || 0,- showInLastUsed: category.value?.showInLastUsed !== undefined ? category.value.showInLastUsed : true,- showInQuickSelector: category.value?.showInQuickSelector !== undefined ? category.value.showInQuickSelector : false,- showStat: category.value?.showStat !== undefined ? category.value.showStat : true,+ order: category.value?.order ?? 1,+ parentId: category.value?.parentId ?? 0,+ showInLastUsed: category.value?.showInLastUsed ?? true,+ showInQuickSelector: category.value?.showInQuickSelector ?? false,+ showStat: category.value?.showStat ?? true,})const parentCategory = computed(() => {diff --git a/components/categories/page/id/Index.vue b/components/categories/page/id/Index.vueindex 0d4f239d..fdc99807 100644--- a/components/categories/page/id/Index.vue+++ b/components/categories/page/id/Index.vue@@ -17,7 +17,7 @@ const trnsItems = computed(() => $store.state.trns.items)const backLink = computed(() => category.value?.parentId ? `/categories/${category.value.parentId}` : '/categories')const categoryChildIds = computed(() => category.value.childIds- ?.sort((a, b) => $store.state.categories.items[b].name - $store.state.categories.items[a].name))+ ?.sort((a, b) => $store.state.categories.items[a].name.localeCompare($store.state.categories.items[b].name)))const trnsIds = computed(() =>getTrnsIds({@@ -27,6 +27,7 @@ const trnsIds = computed(() =>trnsItems: trnsItems.value,}))+// TODO: useFilterfunction handleSetFilterCategory() {setFilterCatsId(categoryId.value)$store.commit('filter/setFilterDateNow')diff --git a/components/filter/useFilter.ts b/components/filter/useFilter.tsindex 2f9c2a7d..c05916bc 100644--- a/components/filter/useFilter.ts+++ b/components/filter/useFilter.ts@@ -1,8 +1,15 @@+import type { CategoryID } from '~/components/categories/types'+import type { WalletID } from '~/components/wallets/types'+export default function useFilter() {const { $store } = useNuxtApp()const route = useRoute()const router = useRouter()- const filterPeriodNameAllReplacedToYear = computed(() => $store.state.filter.period === 'all' ? 'year' : $store.state.filter.period)+ const filterPeriodNameAllReplacedToYear = computed(() =>+ $store.state.filter.period === 'all'+ ? 'year'+ : $store.state.filter.period)+const isNeedToRedirect = computed(() => route.name !== 'index' && route.name !== 'history')function scrollTop() {@@ -11,15 +18,15 @@ export default function useFilter() {page.scrollTop = 0}- function setFilterCatsId(catId) {+ function setFilterCatsId(categoryId) {if (isNeedToRedirect.value)router.push('/')- $store.commit('filter/setFilterCatsId', catId)+ $store.commit('filter/setFilterCatsId', categoryId)scrollTop()}- function setFilterWalletsId(walletId) {+ function setFilterWalletsId(walletId: WalletID) {if (isNeedToRedirect.value)router.push('/')@@ -27,17 +34,49 @@ export default function useFilter() {scrollTop()}+ function toggleWalletFilter(walletId: WalletID) {+ if ($store.state.filter.walletsIds.includes(walletId)) {+ $store.commit('filter/removeFilterWalletId', walletId)+ scrollTop()+ return+ }++ setFilterWalletsId(walletId)+ $store.commit('filter/setFilterDateNow')+ $store.dispatch('ui/setActiveTabStat', 'details')+ scrollTop()+ }+function setDayDate(date) {$store.dispatch('filter/setPeriod', 'day')$store.dispatch('filter/setDate', parseInt(date))scrollTop()}+ /**+ * Removes+ *+ */+ function removeFilterCategoryId(id: CategoryID) {+ $store.commit('filter/removeFilterCategoryId', id)+ }++ /**+ * Clear+ */+ function clearFilter() {+ $store.commit('filter/clearFilterCatsIds')+ $store.commit('filter/clearFilterWalletsIds')+ }+return {+ clearFilter,+ filterPeriodNameAllReplacedToYear,+ removeFilterCategoryId,scrollTop,+ setDayDate,setFilterCatsId,setFilterWalletsId,- filterPeriodNameAllReplacedToYear,- setDayDate,+ toggleWalletFilter,}}diff --git a/components/layout/Sidebar.vue b/components/layout/Sidebar.vueindex c04447ac..6eff04cc 100644--- a/components/layout/Sidebar.vue+++ b/components/layout/Sidebar.vue@@ -1,20 +1,6 @@<script setup lang="ts">-import type { WalletID } from '~/components/wallets/types'import useFilter from '~/components/filter/useFilter'--const { $store } = useNuxtApp()-const { setFilterWalletsId } = useFilter()--function setWalletFilter(walletId: WalletID) {- if ($store.state.filter.walletsIds.includes(walletId)) {- $store.commit('filter/removeFilterWalletId', walletId)- return- }-- setFilterWalletsId(walletId)- $store.commit('filter/setFilterDateNow')- $store.dispatch('ui/setActiveTabStat', 'details')-}+const { toggleWalletFilter } = useFilter()</script><template lang="pug" scoped>@@ -48,7 +34,7 @@ function setWalletFilter(walletId: WalletID) {.w-6.h-6.rounded-md.flex-center.text-skin-icon-base.text-xs.leading-none(:style="{ background: walletItem.color }"class="mt-[2px]"- @click.stop="setWalletFilter(walletId)"+ @click.stop="toggleWalletFilter(walletId)") {{ walletItem.name.substring(0, 2) }}//- Name.grow.text-sm.text-skin-item-base {{ walletItem.name }}@@ -58,7 +44,6 @@ function setWalletFilter(walletId: WalletID) {Amount(:amount="walletItem.amount":currencyCode="walletItem.currency"- :isShowSign="false")template(#toggle="{ stateLimit, limit, toggle }")diff --git a/components/stat/Filter.vue b/components/stat/Filter.vueindex 3788dc16..a5d3ad90 100644--- a/components/stat/Filter.vue+++ b/components/stat/Filter.vue@@ -1,36 +1,29 @@<script setup lang="ts">-import type { CategoryID } from '~/components/categories/types'+import useFilter from '~/components/filter/useFilter'+const { $store } = useNuxtApp()+const { removeFilterCategoryId, clearFilter } = useFilter()const filterWalletsItems = computed(() =>- $store.state.filter.walletsIds- .reduce((acc, id) => {- acc[id] = $store.state.wallets.items[id]- return acc- }, {}),+ $store.state.filter.walletsIds.reduce((acc, id) => {+ acc[id] = $store.state.wallets.items[id]+ return acc+ }, {}),)-const filterCatsItems = computed(() =>- $store.state.filter.catsIds- .reduce((acc, id) => {- acc[id] = $store.state.categories.items[id]- return acc- }, {}),+const filterCategoriesItems = computed(() =>+ $store.state.filter.catsIds.reduce((acc, id) => {+ acc[id] = $store.state.categories.items[id]+ return acc+ }, {}),)--const onClickCategory = (id: CategoryID) => {- $store.commit('filter/removeFilterCatId', id)-}--const onClearFilter = () => {- $store.commit('filter/clearFilterCatsIds')- $store.commit('filter/clearFilterWalletsIds')-}</script><template lang="pug">-.overflow-hidden(v-if="filterCatsItems || filterWalletsItems")- .pb-3.text-lg.leading-none.font-nunito.font-semibold.text-skin-item-base {{ $t('base.filter') }}+.overflow-hidden(v-if="filterCategoriesItems || filterWalletsItems")+ .pb-3.text-lg.leading-none.font-nunito.font-semibold.text-skin-item-base+ | {{ $t('base.filter') }}+.safe.scrollbar.overflow-hidden.overflow-x-auto.flex.flex-wrap.items-center.gap-4//- Wallettemplate(v-if="filterWalletsItems")@@ -46,20 +39,18 @@ const onClearFilter = () => {Amount(:amount="$store.getters['wallets/walletsTotal'][walletId]":currencyCode="walletItem.currency"- :type="3":isShowBaseRate="false"- :isShowSign="false").absolute.top-1.right-1.text-sm.mdi.mdi-close//- Category- template(v-if="filterCatsItems")+ template(v-if="filterCategoriesItems").cursor-pointer.relative.py-1.px-3.flex.items-center.gap-3.rounded-md.bg-skin-item-main-bg.hocus_bg-skin-item-main-hover.shadow.hocus_shadow-lg(- v-for="(catItem, catId) in filterCatsItems"- :key="catId"- @click="onClickCategory(catId)"+ v-for="(catItem, categoryId) in filterCategoriesItems"+ :key="categoryId"+ @click="removeFilterCategoryId(categoryId)").text-2xl(:style="{ color: catItem.color }"@@ -73,8 +64,8 @@ const onClearFilter = () => {//- Clear.cursor-pointer.py-1.px-3.flex.items-center.gap-3.rounded-md.bg-skin-item-main-bg.hocus_bg-skin-item-main-hover.shadow.hocus_shadow-lg(- @click="onClearFilter"- )- .mdi.mdi-filter-remove-outline.text-2xl- .pr-1.text-xs.leading-none {{ $t('filter.clear') }}+ @click="clearFilter"+ )+ .mdi.mdi-filter-remove-outline.text-2xl+ .pr-1.text-xs.leading-none {{ $t('filter.clear') }}</template>diff --git a/components/stat/cats/PeriodCatsChart.vue b/components/stat/cats/PeriodCatsChart.vueindex c2115f3a..bf82435e 100644--- a/components/stat/cats/PeriodCatsChart.vue+++ b/components/stat/cats/PeriodCatsChart.vue@@ -1,13 +1,8 @@<script>+// TODO: setupexport default {props: {- type: {- type: String,- required: true,- validator(value) {- return value === 'income' || value === 'expense'- },- },+ type: { type: String, required: true },},data() {@@ -28,16 +23,6 @@ export default {return this.$store.getters['stat/statCurrentPeriod']},},-- methods: {- handleActiveCategoryChange({ categoryId, offset }) {- if (offset)- this.offset = offset- categoryId- ? this.activeCategoryId = categoryId- : this.activeCategoryId = null- },- },}</script>@@ -46,16 +31,16 @@ export default {.cats-chart__items.px-2.pb-2(v-if="statCurrentPeriod[type].categoriesIds.length > 0")StatCatsPeriodCatsChartItem(v-for="categoryId in statCurrentPeriod[type].categoriesIds"+ :key="`charts-${categoryId}`":biggest="biggestAmount":category="categories[categoryId]":categoryId="categoryId"- :key="`charts-${categoryId}`":total="statCurrentPeriod.categories[categoryId][type]"- @onActiveCategoryChange="handleActiveCategoryChange")</template><style lang="stylus" scoped>+// TODO: style.cats-chart&__itemsoverflow hiddendiff --git a/components/stat/cats/PeriodCatsChartItem.vue b/components/stat/cats/PeriodCatsChartItem.vueindex 109888f8..3bfa8f2a 100644--- a/components/stat/cats/PeriodCatsChartItem.vue+++ b/components/stat/cats/PeriodCatsChartItem.vue@@ -1,6 +1,7 @@<script lang="ts">import useFilter from '~/components/filter/useFilter'+// TODO: setupexport default defineComponent({props: {biggest: { type: Number, required: true },@@ -34,32 +35,12 @@ export default defineComponent({return this.total.toFixed()},},-- methods: {- handleMouseEnter(e) {- if (this.$store.state.ui.pc) {- const parent = e.target.parentNode- const parentScrollLeft = parent.scrollLeft- const targetOffset = e.target.offsetLeft- const targetWidth = e.target.clientWidth- const offset = targetOffset + (targetWidth / 2) - parentScrollLeft- this.$emit('onActiveCategoryChange', { offset, categoryId: this.categoryId })- }- },-- handleMouseLeave() {- if (this.$store.state.ui.pc)- this.$emit('onActiveCategoryChange', { categoryId: null })- },- },})</script><template lang="pug">.statCatsItem.swiper-no-swiping.active.hocus_bg-skin-item-main-hover(@click="setFilterCatsId(categoryId)"- @mouseenter="handleMouseEnter"- @mouseleave="handleMouseLeave").statCatsItem__graph.bg-skin-item-main-active.statCatsItem__graph__in(:style="styles")@@ -70,6 +51,7 @@ export default defineComponent({</template><style lang="stylus" scoped>+// TODO: styles.statCatsItemcursor pointermargin-top 16pxdiff --git a/components/stat/cats/PeriodCatsChartItem2.vue b/components/stat/cats/PeriodCatsChartItem2.vuedeleted file mode 100644index 7e62f3d7..00000000--- a/components/stat/cats/PeriodCatsChartItem2.vue+++ /dev/null@@ -1,82 +0,0 @@-<script>-export default {- name: 'StatCatsPeriodCatsChartItem2',-- props: {- category: {- type: Object,- required: true,- },- categoryId: {- type: String,- required: true,- },- total: {- type: Number,- required: true,- },- biggest: {- type: Number,- required: true,- },- },-- computed: {- styles() {- return {- width: `${Math.abs(this.total) / Math.abs(this.biggest) * 100}%`,- background: this.category.color,- }- },- amount() {- if (this.total >= 1000000)- return `${(this.total / 1000000).toFixed(2)}m`-- else if (this.total >= 10000)- return `${(this.total / 1000).toFixed()}k`-- else if (this.total > 999)- return `${(this.total / 1000).toFixed(1)}k`-- return this.total.toFixed()- },- },-- methods: {- handleMouseEnter(e) {- if (this.$store.state.ui.pc) {- const parent = e.target.parentNode- const parentScrollLeft = parent.scrollLeft- const targetOffset = e.target.offsetLeft- const targetWidth = e.target.clientWidth- const offset = targetOffset + (targetWidth / 2) - parentScrollLeft- this.$emit('onActiveCategoryChange', { offset, categoryId: this.categoryId })- }- },-- handleMouseLeave() {- if (this.$store.state.ui.pc)- this.$emit('onActiveCategoryChange', { categoryId: null })- },- },-}-</script>--<template lang="pug">-.statCatsItem.statCatsItem.swiper-no-swiping(- :style="styles"-)- .statCatsItem__text(v-if="total / biggest * 100 > 20") {{ category.name }}-</template>--<style lang="stylus" scoped>-@import "~assets/stylus/variables/margins"-@import "~assets/stylus/variables/media"--.statCatsItem- height 12px-- &__text- &__count- display none-</style>diff --git a/components/stat/group/HorizontalItem.vue b/components/stat/group/HorizontalItem.vueindex 0957cefc..80e6b930 100644--- a/components/stat/group/HorizontalItem.vue+++ b/components/stat/group/HorizontalItem.vue@@ -1,7 +1,7 @@<script setup lang="ts">import type { CategoryID, CategoryItem } from '~/components/categories/types'-import useFilter from '~/components/filter/useFilter'import type { TrnType } from '~/components/trns/types'+import useFilter from '~/components/filter/useFilter'import useStatPage from '~/components/stat/useStatPage'const props = defineProps<{diff --git a/components/stat/group/HorizontalItemCat.vue b/components/stat/group/HorizontalItemCat.vueindex 9e20fea6..edb178fa 100644--- a/components/stat/group/HorizontalItemCat.vue+++ b/components/stat/group/HorizontalItemCat.vue@@ -10,8 +10,9 @@ export default {computed: {statCategories() {const categoriesIds = this.$store.getters['categories/getChildCategoriesIds'](this.categoryId)- let stat = []+ const stat = []+ // TODO: reducefor (const categoryId of categoriesIds) {const trnsIds = this.getTrnsByCategoryId(categoryId)if (trnsIds.length > 0) {@@ -20,15 +21,7 @@ export default {}}- stat = stat.sort((a, b) => {- if (a[this.typeName] > b[this.typeName])- return -1- if (a[this.typeName] < b[this.typeName])- return 1- return 0- })-- return stat+ return stat.sort((a, b) => b[this.typeName] - a[this.typeName])},typeName() {diff --git a/components/stat/group/HorizontalItemCatItem.vue b/components/stat/group/HorizontalItemCatItem.vueindex 3de38c8f..5e1c72c9 100644--- a/components/stat/group/HorizontalItemCatItem.vue+++ b/components/stat/group/HorizontalItemCatItem.vue@@ -77,6 +77,7 @@ const trnsIds = computed(() => {</template><style lang="stylus">+// TODO: style.statItemChild.trnItem._statpadding-right $m5diff --git a/components/stat/group/RoundItem.vue b/components/stat/group/RoundItem.vueindex 125c7e0a..b21858da 100644--- a/components/stat/group/RoundItem.vue+++ b/components/stat/group/RoundItem.vue@@ -1,4 +1,5 @@<script lang="ts">+// TODO: setupimport useFilter from '~/components/filter/useFilter'export default {@@ -56,6 +57,7 @@ export default {</template><style lang="stylus">+// TODO: style.statItemRoundmax-width 160pxdiff --git a/components/trnForm/ModalWallets.vue b/components/trnForm/ModalWallets.vueindex 945a4faa..42bc1be3 100644--- a/components/trnForm/ModalWallets.vue+++ b/components/trnForm/ModalWallets.vue@@ -50,6 +50,5 @@ BaseBottomSheet(Amount(:amount="walletItem.amount":currencyCode="walletItem.currency"- :isShowSign="false")</template>diff --git a/components/trnForm/SelectedWallet.vue b/components/trnForm/SelectedWallet.vueindex d7316686..b6d7debd 100644--- a/components/trnForm/SelectedWallet.vue+++ b/components/trnForm/SelectedWallet.vue@@ -32,7 +32,6 @@ const wallet = computed(() => walletsItemsSorted.value[props.walletId]):amount="wallet.amount":currencyCode="wallet.currency":isShowBaseRate="false"- :isShowSign="false"align="left")diff --git a/components/trns/List.vue b/components/trns/List.vueindex 86ebe635..285970a5 100644--- a/components/trns/List.vue+++ b/components/trns/List.vue@@ -86,6 +86,7 @@ const actions = trnItem => ({$store.dispatch('trnForm/openTrnForm', { action: 'edit', trnId: trnItem.id })},+ // TODO: useFilteronSetFilter: (event) => {event.stopPropagation()setFilterCatsId(trnItem.categoryId)diff --git a/components/trns/item/Base.vue b/components/trns/item/Base.vueindex 613c2adf..7ba6369e 100644--- a/components/trns/item/Base.vue+++ b/components/trns/item/Base.vue@@ -35,6 +35,7 @@ const actions = {emit('onClickEdit', props.trnId)},+ // TODO: useFilteronSetFilter: (event) => {if (props.slider)returndiff --git a/components/trns/item/Modal.vue b/components/trns/item/Modal.vueindex 96c43afc..569964f6 100644--- a/components/trns/item/Modal.vue+++ b/components/trns/item/Modal.vue@@ -3,6 +3,7 @@ import useFilter from '~/components/filter/useFilter'import useCalculator from '~/components/trnForm/calculator/useCalculator'import useTrn from '~/components/trns/item/useTrn'+// TODO: useFilterexport default {setup() {const { $store } = useNuxtApp()diff --git a/components/trns/pages/History.vue b/components/trns/pages/History.vueindex ef14ff07..c85da0bd 100644--- a/components/trns/pages/History.vue+++ b/components/trns/pages/History.vue@@ -1,6 +1,8 @@<script setup lang="ts">import useStatPage from '~/components/stat/useStatPage'+import useTrns from '~/components/trns/useTrns'const { statPage } = useStatPage()+const { allTrnsIdsWithFilter } = useTrns()</script><script lang="ts">@@ -22,6 +24,6 @@ export default defineComponent({.pb-8(v-if="statPage.filter.isShow")LazyStatFilter- .my-4.px-2.md_max-w-none(class="max-w-[420px]")- TrnsListWithControl(:trnsIds="allTrnsWithFilter")+ .my-4.md_max-w-none(class="max-w-[420px]")+ TrnsListWithControl(:trnsIds="allTrnsIdsWithFilter")</template>diff --git a/components/ui/Page.vue b/components/ui/Page.vueindex cbe14711..b228780b 100644--- a/components/ui/Page.vue+++ b/components/ui/Page.vue@@ -1,5 +1,5 @@<template lang="pug">-.overflow-x-hidden.overflow-y-auto.flex.flex-col.justify-between.w-full.h-full(+.relative.overflow-x-hidden.overflow-y-auto.flex.flex-col.justify-between.w-full.h-full(class="md_pb-[52px] pb-[44px] lg_pb-0").max-w-3xldiff --git a/components/wallets/page/id/Index.vue b/components/wallets/page/id/Index.vueindex ccbf8d71..f181f74d 100644--- a/components/wallets/page/id/Index.vue+++ b/components/wallets/page/id/Index.vue@@ -10,6 +10,7 @@ const router = useRouter()const walletId = computed(() => route.params.id)const wallet = computed(() => $store.state.wallets.items[walletId.value])+if (!wallet.value)router.replace('/wallets')@@ -26,13 +27,14 @@ const trnsIds = computed(() =>const periodTrnsIds = computed(() => $store.getters['trns/selectedTrnsIdsWithDate'].filter(trnId => $store.state.trns.items[trnId].walletId === walletId.value))-function handleSetFilterWallet() {+// TODO: useFilter+function onClickFilterWallet() {setFilterWalletsId(walletId.value)$store.commit('filter/setFilterDateNow')$store.dispatch('ui/setActiveTabStat', 'details')}-function handleEditClick() {+function onEditClick() {router.push(`/wallets/${walletId.value}/edit`)}</script>@@ -63,7 +65,7 @@ UiPage(v-if="wallet")| {{ wallet.currency }}template(#actions)- UiHeaderLink(@click="handleEditClick")+ UiHeaderLink(@click="onEditClick").mdi.mdi-pencil-outline.group-hover_text-white.text-xl.mb-6.pt-3.px-2.flex.text-3xl.font-normal@@ -76,7 +78,7 @@ UiPage(v-if="wallet").px-2.flex.cursor-pointer.p-1.px-3.flex.items-center.gap-3.bg-gray-50.dark_bg-dark4.rounded-md.hocus_bg-gray-100.dark_hocus_bg-neutral-800.shadow.hocus_shadow-lg(class="dark_text-white/60"- @click="handleSetFilterWallet"+ @click="onClickFilterWallet").mdi.mdi-poll.text-xl.text-xs.leading-none {{ $t("statBy") }}: {{ wallet.name }}diff --git a/components/wallets/useWallets.ts b/components/wallets/useWallets.tsindex b75bdd36..acbce210 100644--- a/components/wallets/useWallets.ts+++ b/components/wallets/useWallets.ts@@ -1,5 +1,5 @@import type { ComputedRef } from '@vue/composition-api'-import type { WalletID, WalletItemWithAmount } from '~/components/wallets/types'+import type { WalletID, WalletItem, WalletItemWithAmount } from '~/components/wallets/types'import type { CurrencyCode } from '~/components/currencies/types'export default function useWallets() {@@ -17,35 +17,31 @@ export default function useWallets() {*/const walletsItemsSorted = computed<Record<WalletID, WalletItemWithAmount>>(() => {const walletsIdsSorted: WalletID[] = $store.getters['wallets/walletsSortedIds']- let wallets: Record<WalletID, WalletItemWithAmount> = {}- for (const walletId of walletsIdsSorted) {- wallets = {- ...wallets,- [walletId]: {- ...$store.state.wallets.items[walletId],- amount: $store.getters['wallets/walletsTotal'][walletId],- },+ return walletsIdsSorted.reduce((acc, id) => {+ acc[id] ??= []+ acc[id] = {+ ...$store.state.wallets.items[id],+ amount: $store.getters['wallets/walletsTotal'][id],}- }-- return wallets+ return acc+ }, {})})/*** Wallets currencies*/const walletsCurrencies = computed(() => {- // TODO: map, maybe Set- const currencies: CurrencyCode[] = []-- for (const walletId in walletsItemsSorted.value) {- const walletCurrency = walletsItemsSorted.value[walletId].currency- if (!currencies.includes(walletCurrency))- currencies.push(walletCurrency)- }-- return currencies+ const walletsIdsSorted: WalletID[] = $store.getters['wallets/walletsSortedIds']+ const walletsItems: Record<WalletID, WalletItem> = $store.state.wallets.items++ // TODO: check Alex+ return walletsIdsSorted.reduce((acc, id) => {+ const currency = walletsItems[id].currency+ if (!acc.includes(currency))+ acc.push(currency)+ return acc+ }, [])})return {diff --git a/pages/wallets/total.vue b/pages/wallets/total.vueindex e78aca26..7f1b3b82 100644--- a/pages/wallets/total.vue+++ b/pages/wallets/total.vue@@ -109,9 +109,9 @@ const seriesTotal = computed(() => {const t = []for (const [idx, element] of series.value.entries()) {const sum = element.total.sumTransfers + element.total.sumTransactions- idx > 0- ? t.push(t[idx - 1] + sum)- : t.push(sum)+ idx === 0+ ? t.push(sum)+ : t.push(t[idx - 1] + sum)}return tdiff --git a/store/categories/getters.ts b/store/categories/getters.tsindex 231e0255..129106da 100644--- a/store/categories/getters.ts+++ b/store/categories/getters.ts@@ -20,19 +20,16 @@ export default {return Object.keys(state.items)},- categoriesRootIds(state, getters) {+ /**+ * Categories root IDs+ */+ categoriesRootIds(state, getters): CategoryID[] {if (!getters.hasCategories)return []return Object.keys(state.items).filter(id => state.items[id].parentId === 0)- .sort((a, b) => {- if (state.items[a].order < state.items[b].order)- return -1- if (state.items[a].order > state.items[b].order)- return 1- return 0- })+ .sort((a, b) => state.items[a].name.localeCompare(state.items[b].name))},categoriesForBeParent(state, getters, rootState) {diff --git a/store/filter/mutations.js b/store/filter/mutations.jsindex 9e9a186c..60c2a607 100644--- a/store/filter/mutations.js+++ b/store/filter/mutations.js@@ -43,7 +43,7 @@ export default {state.catsIds.push(catId)},- removeFilterCatId(state, catId) {+ removeFilterCategoryId(state, catId) {state.catsIds = state.catsIds.filter(id => id !== catId)},diff --git a/store/wallets/getters.js b/store/wallets/getters.jsindex d83a7208..0e175a4e 100644--- a/store/wallets/getters.js+++ b/store/wallets/getters.js@@ -43,12 +43,7 @@ export default {walletsSortedIds(state, getters) {if (!getters.hasWallets)return []- return Object.keys(state.items).sort((a, b) => {- if (parseInt(state.items[a].order) < parseInt(state.items[b].order))- return -1- if (parseInt(state.items[a].order) > parseInt(state.items[b].order))- return 1- return 0- })++ return Object.keys(state.items).sort((a, b) => state.items[b].order - state.items[a].order)},}