Skip to content

Open source personal finance application

refactor(Stat): update components

ilkome26541a7cb670
diff --git a/components/stat/Filter.vue b/components/stat/Filter.vue
index 48ef5cac..3788dc16 100644
--- a/components/stat/Filter.vue
+++ b/components/stat/Filter.vue
@@ -1,37 +1,25 @@
<script setup lang="ts">
-import useFilter from '~/modules/filter/useFilter'
-
+import type { CategoryID } from '~/components/categories/types'
const { $store } = useNuxtApp()
-const { setFilterCatsId } = useFilter()
-
-const filterWalletsItems = computed(() => {
- let wallets = {}
-
- for (const walletId of $store.state.filter.walletsIds) {
- const wallet = $store.state.wallets.items[walletId]
- if (!wallet)
- break
- wallets = { ...wallets, [walletId]: wallet }
- }
-
- return wallets
-})
-
-const filterCatsItems = computed(() => {
- let cats = {}
- for (const catId of $store.state.filter.catsIds) {
- const cat = $store.state.categories.items[catId]
- if (!cat)
- break
- cats = { ...cats, [catId]: cat }
- }
+const filterWalletsItems = computed(() =>
+ $store.state.filter.walletsIds
+ .reduce((acc, id) => {
+ acc[id] = $store.state.wallets.items[id]
+ return acc
+ }, {}),
+)
- return cats
-})
+const filterCatsItems = computed(() =>
+ $store.state.filter.catsIds
+ .reduce((acc, id) => {
+ acc[id] = $store.state.categories.items[id]
+ return acc
+ }, {}),
+)
-const onClickCategory = (catId) => {
- $store.commit('filter/removeFilterCatId', catId)
+const onClickCategory = (id: CategoryID) => {
+ $store.commit('filter/removeFilterCatId', id)
}
const onClearFilter = () => {
diff --git a/components/stat/History.vue b/components/stat/History.vue
index 32a8b7e0..01144843 100644
--- a/components/stat/History.vue
+++ b/components/stat/History.vue
@@ -1,10 +1,8 @@
<script setup lang="ts">
import { getCatsIds } from '~/components/categories/getCategories'
import { getTrnsIds } from '~/components/trns/getTrns'
-import useStatPage from '~/components/stat/useStatPage'
const { $store } = useNuxtApp()
-const { statPage } = useStatPage()
const catsItems = computed(() => $store.state.categories.items)
const trnsItems = computed(() => $store.state.trns.items)
const storeFilter = computed(() => $store.state.filter)
diff --git a/components/stat/MobileNav.vue b/components/stat/MobileNav.vue
deleted file mode 100644
index 874feaa9..00000000
--- a/components/stat/MobileNav.vue
+++ /dev/null
@@ -1,8 +0,0 @@
-<script setup lang="ts">
-
-</script>
-
-<template lang="pug">
-.my-6
- StatPeriodArrows
-</template>
diff --git a/components/stat/Page.vue b/components/stat/Page.vue
new file mode 100644
index 00000000..136e49cf
--- /dev/null
+++ b/components/stat/Page.vue
@@ -0,0 +1,25 @@
+<script lang="ts">
+import { useWindowSize } from '@vueuse/core'
+export default {
+ setup() {
+ const { width } = useWindowSize()
+
+ return { width }
+ },
+
+ head() {
+ return {
+ title: this.$t('stat.title'),
+ }
+ },
+}
+</script>
+
+<template lang="pug">
+.overflow-hidden.h-full
+ template(v-if="$store.getters['trns/hasTrns']")
+ LazyStatLaptopView(v-if="width >= 1024")
+ LazyStatMobileView(v-else)
+
+ LazyStatWelcomeActions(v-if="!$store.getters['trns/hasTrns']")
+</template>
diff --git a/components/stat/NoStatActions.vue b/components/stat/WelcomeActions.vue
similarity index 100%
rename from components/stat/NoStatActions.vue
rename to components/stat/WelcomeActions.vue
diff --git a/components/stat/ChartConfig.vue b/components/stat/chart/Options.vue
similarity index 100%
rename from components/stat/ChartConfig.vue
rename to components/stat/chart/Options.vue
diff --git a/components/stat/Periods.vue b/components/stat/chart/Periods.vue
similarity index 100%
rename from components/stat/Periods.vue
rename to components/stat/chart/Periods.vue
diff --git a/components/stat/ChartLines.vue b/components/stat/chart/View.vue
similarity index 99%
rename from components/stat/ChartLines.vue
rename to components/stat/chart/View.vue
index a0f08b41..574e5ea8 100644
--- a/components/stat/ChartLines.vue
+++ b/components/stat/chart/View.vue
@@ -1,6 +1,6 @@
<script lang="ts">
import { Chart } from 'highcharts-vue'
-import chartOptions from '~/components/stat/chartOptions'
+import chartOptions from '~/components/stat/chart/chartOptions'
import useChart from '~/components/chart/useChart'
import useFilter from '~/modules/filter/useFilter'
import { getCatsIds, getTransferCategoriesIds } from '~/components/categories/getCategories'
diff --git a/components/stat/Chart.vue b/components/stat/chart/Wrap.vue
similarity index 97%
rename from components/stat/Chart.vue
rename to components/stat/chart/Wrap.vue
index 40d9567b..a91b73cc 100644
--- a/components/stat/Chart.vue
+++ b/components/stat/chart/Wrap.vue
@@ -18,7 +18,7 @@ const chartType = computed(() => {
<template lang="pug">
.h-48(v-if="chartState.show.expense || chartState.show.income")
- LazyStatChartLines(
+ LazyStatChartView(
:categoryId="filter.categoryId"
:chartType="chartType"
:isShowExpense="chartState.show.expense"
diff --git a/components/stat/chartOptions.js b/components/stat/chart/chartOptions.js
similarity index 100%
rename from components/stat/chartOptions.js
rename to components/stat/chart/chartOptions.js
diff --git a/components/stat/GroupItem.vue b/components/stat/group/Item.vue
similarity index 100%
rename from components/stat/GroupItem.vue
rename to components/stat/group/Item.vue
diff --git a/components/stat/group/Pie.vue b/components/stat/group/Pie.vue
index a8fc954e..e8b25ff6 100644
--- a/components/stat/group/Pie.vue
+++ b/components/stat/group/Pie.vue
@@ -23,7 +23,7 @@ export default defineComponent({
<template lang="pug">
.my-6(v-if="isShow")
- LazyStatChartPie(
+ LazyStatPieChart(
v-if="isShow"
:amountType="typeText"
)
diff --git a/components/stat/StatChartPie.vue b/components/stat/group/PieChart.vue
similarity index 88%
rename from components/stat/StatChartPie.vue
rename to components/stat/group/PieChart.vue
index 47431cb0..b297ccb1 100644
--- a/components/stat/StatChartPie.vue
+++ b/components/stat/group/PieChart.vue
@@ -1,24 +1,13 @@
<script>
import { Chart } from 'highcharts-vue'
-import chartOptions from '~/components/stat/chartOptions'
+import chartOptions from '~/components/stat/chart/chartOptions'
export default {
- name: 'StatChartPie',
-
- components: {
- Chart,
- },
+ components: { Chart },
props: {
- chartType: {
- type: String,
- default: 'pie',
- },
-
- amountType: {
- type: String,
- default: null,
- },
+ chartType: { type: String, default: 'pie' },
+ amountType: { type: String, default: null },
},
computed: {
diff --git a/components/stat/MenuLaptop.vue b/components/stat/laptop/Menu.vue
similarity index 100%
rename from components/stat/MenuLaptop.vue
rename to components/stat/laptop/Menu.vue
diff --git a/components/stat/Laptop.vue b/components/stat/laptop/View.vue
similarity index 97%
rename from components/stat/Laptop.vue
rename to components/stat/laptop/View.vue
index 029181e4..2fba3d20 100644
--- a/components/stat/Laptop.vue
+++ b/components/stat/laptop/View.vue
@@ -68,13 +68,13 @@ onDeactivated(async () => {
WalletsCurrenciesChanger
.mx-2.mb-4.rounded-lg.bg-skin-item-main-bg.border.dark_border-neutral-800
- LazyStatChart(
+ LazyStatChartWrap(
:key="chartKeyDirtyFix"
v-if="ui.showMainChart && statPage.isHasTrns"
)
.sm_flex.justify-between.px-2.pb-2
- StatPeriods
- StatChartConfig
+ StatChartPeriods
+ StatChartOptions
.my-4.mx-2.p-3.rounded-lg.bg-skin-item-main-active(v-if="statPage.filter.isShow")
LazyStatFilter(v-if="statPage.filter.isShow")
@@ -84,7 +84,7 @@ onDeactivated(async () => {
StatViewConfig
.pb-4.px-2
- StatMenuLaptop
+ StatLaptopMenu
template(v-if="statPage.activeTab !== 'trns' && statPage.activeTab !== 'history'")
//- Loop throw income / expense
diff --git a/components/stat/MenuMobile.vue b/components/stat/mobile/MobileMenu.vue
similarity index 100%
rename from components/stat/MenuMobile.vue
rename to components/stat/mobile/MobileMenu.vue
diff --git a/components/stat/MobileSlide.vue b/components/stat/mobile/Slide.vue
similarity index 90%
rename from components/stat/MobileSlide.vue
rename to components/stat/mobile/Slide.vue
index c05bc8f2..2cd186dd 100644
--- a/components/stat/MobileSlide.vue
+++ b/components/stat/mobile/Slide.vue
@@ -13,5 +13,5 @@ const { statPage } = useStatPage()
slot
.my-6
- StatMobileNav(:slider="sliderObject")
+ StatPeriodArrows
</template>
diff --git a/components/stat/Mobile.vue b/components/stat/mobile/View.vue
similarity index 96%
rename from components/stat/Mobile.vue
rename to components/stat/mobile/View.vue
index fc152465..cd8de16d 100644
--- a/components/stat/Mobile.vue
+++ b/components/stat/mobile/View.vue
@@ -64,25 +64,25 @@ onDeactivated(async () => {
)
| {{ $store.state.currencies.base }}
- StatMenuMobile(:slider="sliderObject")
+ StatMobileMenu(:slider="sliderObject")
.swiper-container.overflow-hidden.h-full(ref="sliderRef")
.swiper-wrapper
//- Summary
StatMobileSlide
.my-4.px-2
- StatSumTotal
StatSumGroup(typeText="income")
StatSumGroup(typeText="expense")
+ StatSumTotal
.my-6.mx-2.rounded-lg.bg-skin-item-main-bg.border.dark_border-neutral-800
- LazyStatChart(
+ LazyStatChartWrap(
:key="chartKeyDirtyFix"
v-if="ui.showMainChart && statPage.isHasTrns"
)
.sm_flex.justify-between.px-2.pb-2
- StatPeriods
- StatChartConfig
+ StatChartPeriods
+ StatChartOptions
//- Expense
StatMobileSlide
diff --git a/components/stat/SummaryRowItemView.vue b/components/stat/sum/Average.vue
similarity index 100%
rename from components/stat/SummaryRowItemView.vue
rename to components/stat/sum/Average.vue
diff --git a/components/stat/sum/Group.vue b/components/stat/sum/Group.vue
index 6e0108bb..736599cb 100644
--- a/components/stat/sum/Group.vue
+++ b/components/stat/sum/Group.vue
@@ -27,7 +27,7 @@ const typeNumber = computed(() => moneyTypes.find(t => t.id === `${props.typeTex
)
//- Average
- LazyStatSummaryRowItemView(
+ LazyStatSumAverage(
v-if="statPage.average[typeText] !== 0"
:amount="statPage.average[typeText]"
:title="$t(`money.average.${typeText}`)"
diff --git a/components/stat/sum/Total.vue b/components/stat/sum/Total.vue
index cfed2772..19745500 100644
--- a/components/stat/sum/Total.vue
+++ b/components/stat/sum/Total.vue
@@ -10,7 +10,7 @@ const statAverage = computed(() => $store.getters['stat/statAverage'])
.overflow-hidden.overflow-x-auto.scrollbar
.flex.items-center
//- Total
- .pr-6.text-4xl
+ .pr-6.text-3xl
Amount(
:amount="statCurrentPeriod.income.total - statCurrentPeriod.expense.total"
:colorize="(statCurrentPeriod.income.total - statCurrentPeriod.expense.total) > 0 ? 'income' : 'expense'"
@@ -20,7 +20,7 @@ const statAverage = computed(() => $store.getters['stat/statAverage'])
:type="(statCurrentPeriod.income.total - statCurrentPeriod.expense.total) > 0 ? 1 : 0"
)
- LazyStatSummaryRowItemView(
+ LazyStatSumAverage(
v-if="statAverage.sum !== 0"
:type="statAverage.sum > 0 ? 1 : 0"
:amount="statAverage.sum"
diff --git a/pages/dashboard.vue b/pages/dashboard.vue
index 1f267550..fc0d2b95 100644
--- a/pages/dashboard.vue
+++ b/pages/dashboard.vue
@@ -1,25 +1,3 @@
-<script lang="ts">
-import { useWindowSize } from '@vueuse/core'
-export default {
- setup() {
- const { width } = useWindowSize()
-
- return { width }
- },
-
- head() {
- return {
- title: this.$t('stat.title'),
- }
- },
-}
-</script>
-
<template lang="pug">
-.overflow-hidden.h-full
- template(v-if="$store.getters['trns/hasTrns']")
- LazyStatLaptop(v-if="width >= 1024")
- LazyStatMobile(v-else)
-
- LazyStatNoStatActions(v-if="!$store.getters['trns/hasTrns']")
+StatPage
</template>