Open source personal finance application
chore: refactor
ilkome2320a5450fe3
diff --git a/.vscode/settings.json b/.vscode/settings.jsonindex 74f506eb..86eefae2 100644--- a/.vscode/settings.json+++ b/.vscode/settings.json@@ -1,7 +1,7 @@{"prettier.enable": false,"editor.codeActionsOnSave": {- "source.fixAll.eslint": true,+ "source.fixAll.eslint": true},- "editor.formatOnSave": false,+ "editor.formatOnSave": false}diff --git a/assets/stylus/colors-light.styl b/assets/stylus/colors-light.stylindex c13ee595..9b374af4 100644--- a/assets/stylus/colors-light.styl+++ b/assets/stylus/colors-light.styl@@ -39,12 +39,11 @@ html// ----------------------------------------------c-bg-1 #f0f0f0--c-bg-2 #ebebeb- --c-bg-3 #f5f5f5+ --c-bg-3 #fff--c-bg-4 #fafafa--c-bg-5 #dcdcdc--c-bg-6 rgba(235, 235, 235, 1)--c-bg-7 rgba(215, 215, 215, 1)- --c-bg-14 rgba(250, 250, 250, 1)--c-bg-8 rgba(190, 190, 190, 1)--c-bg-9 rgba(190, 190, 190, 1)--c-bg-10 rgba(230, 230, 230, 1)@@ -59,7 +58,6 @@ html--c-font-4 #6e6e6e--c-font-5 #969696- --c-bg-3 #fff--color-link-bg #eaeaea--c-item-bg-main #f5f6f8@@ -75,6 +73,5 @@ html--c-item-stat-bg #ebebeb--c-item-stat-icon rgba(250, 250, 250, 1)- --c-item-bg-main #f5f6f8--c-chart-lables-text-color rgba(50, 50, 50, 1)--c-chart-lables-text-shaddow #6e6e6e7adiff --git a/components/base/BottomSheet.vue b/components/base/BottomSheet.vueindex fdd9f7ef..3dc02861 100644--- a/components/base/BottomSheet.vue+++ b/components/base/BottomSheet.vue@@ -406,7 +406,6 @@ export default defineComponent({left 0width 100%height 100%- height 100%user-select none&._hiddendiff --git a/components/layout/useUIView.ts b/components/layout/useUIView.tsindex 587fdacf..d2b9659e 100644--- a/components/layout/useUIView.ts+++ b/components/layout/useUIView.ts@@ -12,15 +12,14 @@ const ui = reactive({export default function useUIView() {async function getLocalUI(): Promise<{}> {- const localUI: {} = await localforage.getItem(localName) || {}- return localUI+ return await localforage.getItem(localName) || {}}async function setUI({ name, value }) {const localUI = await getLocalUI()ui[name] = value- localforage.setItem(localName, {+ await localforage.setItem(localName, {...localUI,[name]: value,})diff --git a/components/stat/Laptop.vue b/components/stat/Laptop.vueindex c6f73e17..baba285b 100644--- a/components/stat/Laptop.vue+++ b/components/stat/Laptop.vue@@ -26,11 +26,10 @@ const isShowGroup = (type) => {}const isShowTrns = computed(() => {- const proceed = statPage.activeTab === 'details'+ return statPage.activeTab === 'details'&& statPage.average?.income !== 0&& statPage.average?.expense !== 0&& $store.getters['trns/selectedTrnsIdsWithDate'].length > 0- return proceed})const isShowGroupTrns = computed(() => {diff --git a/components/stat/PeriodArrows.vue b/components/stat/PeriodArrows.vueindex b86a6c7e..f66699f6 100644--- a/components/stat/PeriodArrows.vue+++ b/components/stat/PeriodArrows.vue@@ -11,7 +11,7 @@ const dates = computed(() => ({<template lang="pug">.flex.justify-between.px-3.arrowDate.cursor-pointer.p-2.px-4.pl-2.flex.gap-2.bg-skin-item-main-bg._left.rounded-md(- :class="{ _disable: $store.state.filter.period === 'all' || $store.getters['stat/isLastPeriodSelected'] }"+ :class="{ _disable: $store.state.filter.period === 'all' || $store.getters['stat/isNewestPeriodSelected'] }"@click="$store.dispatch('filter/setPeriodNext')")svg(width="24" height="24" fill="currentColor")@@ -23,7 +23,7 @@ const dates = computed(() => ({).arrowDate.cursor-pointer.p-2.px-4.pr-2.flex.gap-2.bg-skin-item-main-bg._right.rounded-md(- :class="{ _disable: $store.state.filter.period === 'all' || $store.getters['stat/isFirstPeriodSelected'] }"+ :class="{ _disable: $store.state.filter.period === 'all' || $store.getters['stat/isOldestPeriodSelected'] }"@click="$store.dispatch('filter/setPeriodPrev')")SharedDate.text-sm(diff --git a/components/stat/cats/PeriodCatsChartItem.vue b/components/stat/cats/PeriodCatsChartItem.vueindex b9705486..c1a5668f 100644--- a/components/stat/cats/PeriodCatsChartItem.vue+++ b/components/stat/cats/PeriodCatsChartItem.vue@@ -47,7 +47,7 @@ export default defineComponent({}},- handleMouseLeave(e) {+ handleMouseLeave() {if (this.$store.state.ui.pc)this.$emit('onActiveCategoryChange', { categoryId: null })},@@ -77,7 +77,6 @@ export default defineComponent({border-radius $m4+media-hover()padding 8px- padding-top 8pxmargin 8px 0 -8px -8px&__graph@@ -107,7 +106,6 @@ export default defineComponent({border-radius $m4 $m4 0 0&__icon- display nonedisplay flexalign-items centerjustify-content centerdiff --git a/components/stat/cats/PeriodCatsChartItem2.vue b/components/stat/cats/PeriodCatsChartItem2.vueindex e62477c6..7e62f3d7 100644--- a/components/stat/cats/PeriodCatsChartItem2.vue+++ b/components/stat/cats/PeriodCatsChartItem2.vue@@ -54,7 +54,7 @@ export default {}},- handleMouseLeave(e) {+ handleMouseLeave() {if (this.$store.state.ui.pc)this.$emit('onActiveCategoryChange', { categoryId: null })},diff --git a/components/trnForm/Date.vue b/components/trnForm/Date.vueindex 22aa34ae..64cd40cd 100644--- a/components/trnForm/Date.vue+++ b/components/trnForm/Date.vue@@ -59,8 +59,6 @@ export default {padding $m7color var(--c-font-3)font-size 28px- border-bottom 0- border-right 0border 1px solid transparentborder-radius 50%user-select nonediff --git a/components/trnForm/TrnForm.vue b/components/trnForm/TrnForm.vueindex 98302d1f..a24efec0 100644--- a/components/trnForm/TrnForm.vue+++ b/components/trnForm/TrnForm.vue@@ -359,7 +359,6 @@ function handleSubmitForm() {<style lang="stylus" scoped>.trnForm- overflow hiddenoverflow hiddenwidth 100%height autodiff --git a/components/trnForm/calculator/TrnFormCalculator.vue b/components/trnForm/calculator/TrnFormCalculator.vueindex 1e731720..e77140cc 100644--- a/components/trnForm/calculator/TrnFormCalculator.vue+++ b/components/trnForm/calculator/TrnFormCalculator.vue@@ -162,8 +162,6 @@ export default {padding $m7color var(--c-font-3)font-size 22px- border-bottom 0- border-right 0background var(--c-item-bg-main)border 1px solid var(--c-item-bd-main)border-radius 50%diff --git a/components/trns/item/Details.vue b/components/trns/item/Details.vueindex 86820f3d..1b1f2e79 100644--- a/components/trns/item/Details.vue+++ b/components/trns/item/Details.vue@@ -189,7 +189,6 @@ export default {fontFamilyNunito()&__date- font-size 13pxpadding-bottom $m8font-size 14pxdiff --git a/components/welcome/page/Welcome.vue b/components/welcome/page/Welcome.vueindex 0ba43f16..3223342b 100644--- a/components/welcome/page/Welcome.vue+++ b/components/welcome/page/Welcome.vue@@ -212,7 +212,6 @@ export default {flex-grow 1display flexflex-flow column- flex-grow 1padding $m9padding-bottom 100pxalign-self centerdiff --git a/services/firebase/api.js b/services/firebase/api.jsindex 1fb83328..5729a977 100644--- a/services/firebase/api.js+++ b/services/firebase/api.js@@ -35,4 +35,4 @@ export const removeData = path => remove(ref(db, path))export const saveData = async (path, value) => await set(ref(db, path), value)-export const unsubcribeData = path => off(ref(db, path))+export const unsubscribeData = path => off(ref(db, path))diff --git a/store/app/actions.js b/store/app/actions.jsindex 16cd27f7..ac4d80b5 100644--- a/store/app/actions.js+++ b/store/app/actions.js@@ -44,7 +44,7 @@ export default {dispatch('ui/initUi', null, { root: true })dispatch('chart/initChart', null, { root: true })- const [ativeTab, user, currencies, categories, wallets, trns, filterPeriod] = await Promise.all([+ const [activeTab, user, currencies, categories, wallets, trns, filterPeriod] = await Promise.all([localforage.getItem('finapp.activeTab'),localforage.getItem('finapp.user'),localforage.getItem('finapp.currencies'),@@ -54,8 +54,8 @@ export default {localforage.getItem('finapp.filter.period'),])- if (ativeTab)- dispatch('ui/setActiveTab', ativeTab, { root: true })+ if (activeTab)+ dispatch('ui/setActiveTab', activeTab, { root: true })if (user)commit('user/setUser', user, { root: true })if (currencies)diff --git a/store/categories/actions.js b/store/categories/actions.jsindex bec2e41f..98fff994 100644--- a/store/categories/actions.js+++ b/store/categories/actions.js@@ -1,5 +1,5 @@import localforage from 'localforage'-import { getDataAndWatch, unsubcribeData } from '~/services/firebase/api'+import { getDataAndWatch, unsubscribeData } from '~/services/firebase/api'export default {initCategories({ dispatch, rootState }) {@@ -40,8 +40,8 @@ export default {localforage.setItem('finapp.categories', items)},- unsubcribeCategories({ rootState }) {+ unsubscribeCategories({ rootState }) {const uid = rootState.user.user.uid- unsubcribeData(`users/${uid}/categories`)+ unsubscribeData(`users/${uid}/categories`)},}diff --git a/store/lang/actions.js b/store/lang/actions.jsindex cef941cc..ae8eb6bd 100644--- a/store/lang/actions.js+++ b/store/lang/actions.js@@ -32,11 +32,11 @@ export default {returncommit('setLang', lang)- localforage.setItem('finapp.lang', lang)+ await localforage.setItem('finapp.lang', lang)if (this.$i18n.locales.find(i => i.code !== this.$i18n.locale)) {if (this.app.i18n.locale !== lang)- this.app.i18n.setLocale(lang)+ await this.app.i18n.setLocale(lang)}},}diff --git a/store/stat/getters.ts b/store/stat/getters.tsindex ee96909c..359704f2 100644--- a/store/stat/getters.ts+++ b/store/stat/getters.ts@@ -1,6 +1,5 @@import dayjs from 'dayjs'-import type { TotalReturns } from '~/components/trns/getTotal'-import { getCatsIds, getTransferCategoriesIds } from '~/components/categories/getCategories'+import { getCatsIds } from '~/components/categories/getCategories'import { getTotal } from '~/components/trns/getTotal'import { getTrnsIds } from '~/components/trns/getTrns'@@ -22,15 +21,20 @@ export default {const oldestTrnDate = dayjs(oldestTrn.date).endOf(periodName)let periodsToShow = dayjs().endOf(periodName).diff(oldestTrnDate, periodName) + 1- periodsToShow = rootState.chart.periods[periodName].showedPeriods >= periodsToShow ? periodsToShow : rootState.chart.periods[periodName].showedPeriods+ periodsToShow = rootState.chart.periods[periodName].showedPeriods >= periodsToShow+ ? periodsToShow+ : rootState.chart.periods[periodName].showedPeriods- const statPeriods: Record<string, { date: number; total: TotalReturns }> = {}+ let income = 0+ let expense = 0// Start from 1 to remove last period from averagefor (let period = 1; period < periodsToShow; period++) {const dateStartOfPeriod = dayjs().subtract(period, periodName).startOf(periodName)const dateEndOfPeriod = dayjs().subtract(period, periodName).endOf(periodName)- const ids = trnsIds++ // TODO: use getTrnsIds+ const trnsIdsInPeriod = trnsIds.filter(trnId =>trnsItems[trnId].date >= dateStartOfPeriod&& trnsItems[trnId].date <= dateEndOfPeriod@@ -40,75 +44,50 @@ export default {const total = getTotal({baseRate,rates,- trnsIds: ids,+ trnsIds: trnsIdsInPeriod,trnsItems,walletsItems,})- statPeriods[dateStartOfPeriod.valueOf()] = {- date: dateStartOfPeriod.valueOf(),- total,- }- }-- let income = 0- let expense = 0- let sum = 0- let periodsCounter = 0-- for (const idx in statPeriods) {- const period = statPeriods[idx]- periodsCounter += 1-- income += period.total.incomeTransactions- expense += period.total.expenseTransactions- sum = income - expense+ income += total.incomeTransactions+ expense += total.expenseTransactions}- const delimiter = periodsCounter-// When just this period and last- if (delimiter === 1) {- return {- income: 0,- expense: 0,- sum: 0,- }- }+ const delimiter = periodsToShow - 1+ if (delimiter === 1)+ return { income: 0, expense: 0, sum: 0 }return {income: Math.ceil(income / delimiter),expense: Math.ceil(expense / delimiter),- sum: Math.ceil(sum / delimiter),+ sum: Math.ceil((income - expense) / delimiter),}},- isFirstPeriodSelected(state, getters, rootState, rootGetters) {- if (rootGetters['trns/hasTrns']) {- if (dayjs(rootState.filter.date).isSame(dayjs(), rootState.filter.period))- return true- }- else {+ isOldestPeriodSelected(state, getters, rootState, rootGetters) {+ if (!rootGetters['trns/hasTrns'])+ return false++ if (dayjs(rootState.filter.date).isSame(dayjs(), rootState.filter.period))return true- }},- isLastPeriodSelected(state, getters, rootState, rootGetters) {- if (rootGetters['trns/hasTrns']) {- const trns = rootState.trns.items- const firstCreatedTrnIdFromSelectedTrns = rootGetters['trns/firstCreatedTrnIdFromSelectedTrns']- const firstCreatedTrn = trns[firstCreatedTrnIdFromSelectedTrns]- if (!firstCreatedTrn)- return- const firstCreatedTrnDate = dayjs(firstCreatedTrn.date).startOf(state.period).valueOf()- const filterDate = dayjs(rootState.filter.date).startOf(state.period).valueOf()-- if (filterDate <= firstCreatedTrnDate)- return true- }- else {+ isNewestPeriodSelected(state, getters, rootState, rootGetters) {+ if (!rootGetters['trns/hasTrns'])+ return true++ const trns = rootState.trns.items+ const firstCreatedTrnIdFromSelectedTrns = rootGetters['trns/firstCreatedTrnIdFromSelectedTrns']+ const firstCreatedTrn = trns[firstCreatedTrnIdFromSelectedTrns]+ if (!firstCreatedTrn)+ return true++ const firstCreatedTrnDate = dayjs(firstCreatedTrn.date).startOf(state.period).valueOf()+ const filterDate = dayjs(rootState.filter.date).startOf(state.period).valueOf()++ if (filterDate <= firstCreatedTrnDate)return true- }},statCurrentPeriod(_state, _getters, rootState, rootGetters) {@@ -118,9 +97,10 @@ export default {const baseRate = rootState.currencies.baseconst rates = rootState.currencies.ratesconst storeFilter = rootState.filter- // const transferCategoriesIds = getTransferCategoriesIds(categoriesItems.value)- const categoriesIds = rootState.filter.catsIds.length > 0 ? getCatsIds(rootState.filter.catsIds, categoriesItems) : null+ const categoriesIds = rootState.filter.catsIds.length > 0+ ? getCatsIds(rootState.filter.catsIds, categoriesItems)+ : nullconst walletsIds = storeFilter.walletsIds.length > 0 ? storeFilter.walletsIds : nullconst trnsIds = getTrnsIds({@@ -131,29 +111,9 @@ export default {date: storeFilter.date,})- /**- * Return root category ID from trnId- *- * @param {String} trnId- * @return {String} root categoryId- */function getRootCategoryIdFromTrnId(trnId) {const categories = rootState.categories.items- const wallets = rootState.wallets.itemsconst trnCategoryId = trnsItems[trnId].categoryId-- if (!wallets[trnsItems[trnId].walletId] && !wallets[trnsItems[trnId].incomeWalletId] && !wallets[trnsItems[trnId].expenseWalletId]) {- console.log('no wallet for trn', trnId, trnsItems[trnId])- console.log('walletId', trnsItems[trnId].walletId)- console.log(`https://finapp-17474.firebaseio.com/users/${rootState.user.user.uid}/trns/${trnId}`)- }-- if (!categories[trnCategoryId]) {- console.log('no category for trn', trnId, trnsItems[trnId], categories[trnCategoryId])- console.log(`https://finapp-17474.firebaseio.com/users/${rootState.user.user.uid}/trns/${trnId}`)- return trnCategoryId- }-const trnCategoryParentId = categories[trnCategoryId].parentIdreturn trnCategoryParentId || trnCategoryId}@@ -193,7 +153,6 @@ export default {trnsIds,trnsItems,walletsIds: [rootState.filter.walletsIds],- // transferCategoriesIds,walletsItems,})diff --git a/store/stat/mutations.js b/store/stat/mutations.jsindex f88f70bd..531bcd19 100644--- a/store/stat/mutations.js+++ b/store/stat/mutations.js@@ -1,7 +1,6 @@export default {setDiffPeriods(state, value) {- const number = parseInt(value) || 1- state.showedPeriods = number+ state.showedPeriods = parseInt(value) || 1},setCategoryModal(state, { id, type }) {diff --git a/store/trns/actions.js b/store/trns/actions.jsindex be94b4ed..e73ee553 100644--- a/store/trns/actions.js+++ b/store/trns/actions.js@@ -11,7 +11,7 @@ import {getDataAndWatch,removeData,saveData,- unsubcribeData,+ unsubscribeData,updateData,} from '~/services/firebase/api'@@ -95,9 +95,9 @@ export default {updateData(`users/${uid}/trns`, trnsForDelete)},- unsubcribeTrns({ rootState }) {+ unsubscribeTrns({ rootState }) {const uid = rootState.user.user.uid- unsubcribeData(`users/${uid}/trns`)+ unsubscribeData(`users/${uid}/trns`)},/**diff --git a/store/trns/getters.js b/store/trns/getters.jsindex a9b9243b..911fd393 100644--- a/store/trns/getters.js+++ b/store/trns/getters.js@@ -1,6 +1,5 @@import dayjs from 'dayjs'-import { getCatsIds, getTransferCategoriesIds } from '~/components/categories/getCategories'-import { getTotal } from '~/components/trns/getTotal'+import { getCatsIds } from '~/components/categories/getCategories'import { getTrnsIds } from '~/components/trns/getTrns'export default {@@ -71,13 +70,11 @@ export default {const categoriesIds = rootState.filter.catsIds.length > 0 ? getCatsIds(rootState.filter.catsIds, catsItems) : nullconst walletsIds = storeFilter.walletsIds.length > 0 ? storeFilter.walletsIds : null- const trnsIds = getTrnsIds({+ return getTrnsIds({trnsItems,walletsIds,categoriesIds,})-- return trnsIds},// TODO: should use components/trns/getTrns when its compatiblediff --git a/store/ui/actions.js b/store/ui/actions.jsindex ee8af85b..6dbeefc6 100644--- a/store/ui/actions.js+++ b/store/ui/actions.js@@ -95,6 +95,6 @@ export default {})const periods = rootState.chart.periods- localforage.setItem('finapp.chart.periods', periods)+ await localforage.setItem('finapp.chart.periods', periods)},}diff --git a/store/user/actions.js b/store/user/actions.jsindex a2467ee3..cfd09eeb 100644--- a/store/user/actions.js+++ b/store/user/actions.js@@ -20,12 +20,12 @@ export default {},async signOut({ dispatch }) {- await dispatch('categories/unsubcribeCategories', null, { root: true })- await dispatch('trns/unsubcribeTrns', null, { root: true })- await dispatch('wallets/unsubcribeWallets', null, { root: true })+ await dispatch('categories/unsubscribeCategories', null, { root: true })+ await dispatch('trns/unsubscribeTrns', null, { root: true })+ await dispatch('wallets/unsubscribeWallets', null, { root: true })await dispatch('app/clearUserData', null, { root: true })- signOutFirebase(auth)+ await signOutFirebase(auth)if (this.$router.currentRoute.name !== 'login')this.app.context.redirect('/login')diff --git a/store/wallets/actions.js b/store/wallets/actions.jsindex b52c92a3..f898bec3 100644--- a/store/wallets/actions.js+++ b/store/wallets/actions.js@@ -1,5 +1,5 @@import localforage from 'localforage'-import { getDataAndWatch, saveData, unsubcribeData, updateData } from '~/services/firebase/api'+import { getDataAndWatch, saveData, unsubscribeData, updateData } from '~/services/firebase/api'export default {initWallets({ dispatch, rootState }) {@@ -53,8 +53,8 @@ export default {return result},- unsubcribeWallets({ rootGetters }) {+ unsubscribeWallets({ rootGetters }) {const uid = rootGetters['user/userUid']- unsubcribeData(`users/${uid}/accounts`)+ unsubscribeData(`users/${uid}/accounts`)},}