Skip to content

Open source personal finance application

improvements: typos, refactor

ilkome8d8dac404557
diff --git a/components/categories/Form.vue b/components/categories/Form.vue
index d32c3f9b..468818bc 100644
--- a/components/categories/Form.vue
+++ b/components/categories/Form.vue
@@ -50,7 +50,7 @@ function findCategoryWithThisColor(color) {
}
/**
- * Get child categoreies ids
+ * Get child categories ids
*
* @param categoryId
*/
diff --git a/components/categories/getCategories.ts b/components/categories/getCategories.ts
index ba297d08..547c0ced 100644
--- a/components/categories/getCategories.ts
+++ b/components/categories/getCategories.ts
@@ -1,17 +1,11 @@
import type { CategoryID, CategoryItem } from '~/components/categories/types'
-// TODO: need a proper name
-export function getCategoriesIds(catsIds: CategoryID[], categoriesItems) {
- const ids: CategoryID[] = []
-
- for (const catId of catsIds) {
- const category = categoriesItems[catId]
- category?.childIds
- ? ids.push(...category.childIds)
- : ids.push(catId)
- }
-
- return ids
+// TODO: need a proper name, maybe getTransactibleCategoriesIds
+export function getCategoriesIds(
+ catsIds: CategoryID[],
+ categoriesItems: Record<CategoryID, CategoryItem>,
+): CategoryID[] {
+ return catsIds.map(id => categoriesItems[id]?.childIds ?? id).flat()
}
export function getTransferCategoriesIds(items: Record<CategoryID, CategoryItem>): CategoryID[] {
diff --git a/components/categories/types.ts b/components/categories/types.ts
index e71b3383..77a7ea8a 100644
--- a/components/categories/types.ts
+++ b/components/categories/types.ts
@@ -3,7 +3,7 @@ export type CategoryID = string
export interface CategoryItem {
name: string
color: string
- parentId?: CategoryID
+ parentId: CategoryID | 0
childIds?: CategoryID[]
}
diff --git a/components/date/Selector.vue b/components/date/Selector.vue
index 3cff51f7..a7a99a0b 100644
--- a/components/date/Selector.vue
+++ b/components/date/Selector.vue
@@ -1,24 +1,33 @@
<script setup lang="ts">
import useFilter from '~/modules/filter/useFilter'
import usePeriods from '~/components/periods/usePeriods'
+import { getMaxPeriodsToShow } from '~/components/date/helpers'
+import { getOldestTrnDate } from '~/components/trns/helpers'
const { $store } = useNuxtApp()
const { periodsNames } = usePeriods()
const { filterPeriodNameAllReplacedToYear } = useFilter()
const filterPeriod = computed(() => $store.state.filter.period)
-const onSelectPeriod = (period) => {
+const onSelectPeriodName = (period, close) => {
+ close()
$store.dispatch('filter/setPeriod', period)
}
-const periodCounts = {
- items: [1, 3, 6, 7, 12, 14, 16, 24, 30, 36, 48, 60],
- onSelect: (value) => {
- $store.commit('chart/setElementsToChart', {
- period: filterPeriod.value,
- value,
- })
- },
+// TODO: duplicate computed
+const maxPeriodsNumber = computed(() => {
+ const trnsItems = $store.state.trns.items
+ const oldestTrnDate = getOldestTrnDate(trnsItems)
+ return getMaxPeriodsToShow(filterPeriodNameAllReplacedToYear.value, oldestTrnDate)
+})
+
+const periodCounts = [1, 3, 6, 7, 12, 14, 16, 24, 30, 36, 48, 60]
+function onSelectPeriodCount(value, close) {
+ close()
+ $store.commit('chart/setElementsToChart', {
+ period: filterPeriod.value,
+ value,
+ })
}
</script>
@@ -43,26 +52,31 @@ Portal(to="modal")
:icon="periodItem.icon"
:isActive="filterPeriod === periodItem.slug"
:name="$t(`dates.${periodItem.slug}.simple`)"
- @onClick="onSelectPeriod(periodItem.slug)"
+ @onClick="onSelectPeriodName(periodItem.slug, close)"
)
ModalButton(
:isActive="filterPeriod === 'all'"
:name="$t('dates.all.simple')"
icon="mdi mdi-database"
- @onClick="onSelectPeriod('all')"
+ @onClick="onSelectPeriodName('all', close)"
)
//- Counts
.title {{ $t('dates.count') }}
.counts.flex.items-center.justify-center
.countsItem(
- v-for="periodCount in periodCounts.items"
+ v-for="periodCount in periodCounts"
:key="periodCount"
:class="{ _active: periodCount === $store.state.chart.periods[filterPeriodNameAllReplacedToYear].showedPeriods }"
- @click="periodCounts.onSelect(periodCount)"
+ @click="onSelectPeriodCount(periodCount, close)"
) {{ periodCount }}
+ .countsItem(
+ :class="{ _active: maxPeriodsNumber === $store.state.chart.periods[filterPeriodNameAllReplacedToYear].showedPeriods }"
+ @click="onSelectPeriodCount(maxPeriodsNumber, close)"
+ ) {{ maxPeriodsNumber }}
+
.pb-4.px-3.flex.justify-evenly.gap-6
.cursor-pointer.grow.py-3.px-5.flex-center.rounded-full.text-sm.bg-skin-item-main-bg.hocus_bg-skin-item-main-hover(
class="basis-1/2 max-w-[280px]"
diff --git a/components/date/helpers.ts b/components/date/helpers.ts
new file mode 100644
index 00000000..5263ad51
--- /dev/null
+++ b/components/date/helpers.ts
@@ -0,0 +1,9 @@
+import dayjs from 'dayjs'
+import type { DateValueOf, PeriodsNamesExceptAll } from '~/components/date/types'
+
+/**
+ * Get max periods to show
+ */
+export function getMaxPeriodsToShow(periodName: PeriodsNamesExceptAll, fromDate: DateValueOf): number {
+ return dayjs().endOf(periodName).diff(fromDate, periodName) + 1
+}
diff --git a/components/date/types.ts b/components/date/types.ts
index 7fc424a1..9e41299b 100644
--- a/components/date/types.ts
+++ b/components/date/types.ts
@@ -1,3 +1,5 @@
+export type DateValueOf = number
+
export type PeriodNames = 'day' | 'week' | 'month' | 'year' | 'all'
// Note: dayjs doesn't understand Omit
diff --git a/components/stat/Trns.vue b/components/stat/Trns.vue
index 53ea6962..43262eb4 100644
--- a/components/stat/Trns.vue
+++ b/components/stat/Trns.vue
@@ -1,7 +1,3 @@
-<script>
-export default {}
-</script>
-
<template lang="pug">
.my-4
.pb-2.text-lg.leading-none.font-nunito.font-semibold.text-skin-item-base {{ $t('trns.inPeriodTitle') }}
diff --git a/components/stat/chart/Periods.vue b/components/stat/chart/Periods.vue
index 204668ea..1a893821 100644
--- a/components/stat/chart/Periods.vue
+++ b/components/stat/chart/Periods.vue
@@ -1,55 +1,59 @@
-<script>
+<script setup lang="ts">
import useFilter from '~/modules/filter/useFilter'
import usePeriods from '~/components/periods/usePeriods'
+import { getMaxPeriodsToShow } from '~/components/date/helpers'
+import { getOldestTrnDate } from '~/components/trns/helpers'
-export default {
- setup() {
- const { $store } = useNuxtApp()
+const { $store } = useNuxtApp()
- // Filter
- const { filterPeriodNameAllReplacedToYear } = useFilter()
+// Filter
+const { filterPeriodNameAllReplacedToYear } = useFilter()
- function saveChartsPeriodsToLocalStorage() {
- $store.dispatch('ui/saveUiView')
- }
+const showedPeriods = computed(() => $store.state.chart.periods[filterPeriodNameAllReplacedToYear.value].showedPeriods)
- function addPeriodOrGroup() {
- $store.commit('chart/addElementsToChart', {
- periodName: filterPeriodNameAllReplacedToYear.value,
- periodType: 'showedPeriods',
- })
- saveChartsPeriodsToLocalStorage()
- }
-
- function removePeriodOrGroup() {
- if ($store.state.chart.periods[filterPeriodNameAllReplacedToYear.value].showedPeriods <= 2)
- return
+function saveChartsPeriodsToLocalStorage() {
+ $store.dispatch('ui/saveUiView')
+}
- $store.commit('chart/removeElementsFromChart', {
- periodName: filterPeriodNameAllReplacedToYear.value,
- periodType: 'showedPeriods',
- })
- saveChartsPeriodsToLocalStorage()
- }
+function addPeriod() {
+ $store.commit('chart/addElementsToChart', {
+ periodName: filterPeriodNameAllReplacedToYear.value,
+ periodType: 'showedPeriods',
+ })
+ saveChartsPeriodsToLocalStorage()
+}
- // Periods
- const { periodsNames } = usePeriods()
+function removePeriod() {
+ if (showedPeriods.value <= 1)
+ return
- return {
- addPeriodOrGroup,
- removePeriodOrGroup,
- filterPeriodNameAllReplacedToYear,
- periodsNames,
- }
- },
+ $store.commit('chart/removeElementsFromChart', {
+ periodName: filterPeriodNameAllReplacedToYear.value,
+ periodType: 'showedPeriods',
+ })
+ saveChartsPeriodsToLocalStorage()
}
+
+// Periods
+const { periodsNames } = usePeriods()
+
+// TODO: duplicate computed
+const maxPeriodsNumber = computed(() => {
+ const trnsItems = $store.state.trns.items
+ const oldestTrnDate = getOldestTrnDate(trnsItems)
+ return getMaxPeriodsToShow(filterPeriodNameAllReplacedToYear.value, oldestTrnDate)
+})
+
+const isShowRemove = computed(() => showedPeriods.value <= 1)
+const isShowAdd = computed(() => showedPeriods.value >= maxPeriodsNumber.value)
</script>
<template lang="pug">
.flex-center
.overflow-hidden.flex.items-center.text-xs
.cursor-pointer.w-10.py-2.px-3.flex-center.rounded-md.hocus_bg-skin-item-main-hover(
- @click="removePeriodOrGroup"
+ :class="{ 'opacity-0 cursor-default pointer-events-none': isShowRemove }"
+ @click="removePeriod"
): .mdi.mdi-minus
.cursor-pointer.py-2.px-3.rounded-md.hocus_bg-skin-item-main-hover(
@@ -58,11 +62,12 @@ export default {
:class="{ 'cursor-default text-skin-item-base-up': periodItem.slug === filterPeriodNameAllReplacedToYear }"
@click="$store.dispatch('filter/setPeriod', periodItem.slug)"
)
- span.pr-1(v-if="periodItem.slug === filterPeriodNameAllReplacedToYear")
- | {{ $store.state.chart.periods[filterPeriodNameAllReplacedToYear].showedPeriods }}
| {{ periodItem.name }}
+ span.pl-1(v-if="periodItem.slug === filterPeriodNameAllReplacedToYear")
+ | {{ showedPeriods }}/{{ maxPeriodsNumber }}
.cursor-pointer.w-10.py-2.px-3.flex-center.rounded-md.hocus_bg-skin-item-main-hover(
- @click="addPeriodOrGroup"
+ :class="{ 'opacity-0 cursor-default pointer-events-none': isShowAdd }"
+ @click="addPeriod"
): .mdi.mdi-plus
</template>
diff --git a/components/stat/group/HorizontalItem.vue b/components/stat/group/HorizontalItem.vue
index 67b042ba..51d74f77 100644
--- a/components/stat/group/HorizontalItem.vue
+++ b/components/stat/group/HorizontalItem.vue
@@ -26,10 +26,6 @@ export default {
},
computed: {
- childCategoriesIds() {
- return this.$store.getters['categories/getChildCategoriesIds'](this.categoryId)
- },
-
isCategoryHasChildren() {
return this.$store.getters['categories/isCategoryHasChildren'](this.categoryId)
},
@@ -40,27 +36,6 @@ export default {
background: this.category.color,
}
},
-
- getCatgoryName() {
- const cats = []
- const categoriesIds = this.$store.getters['categories/getChildCategoriesIds'](this.categoryId)
-
- const getTrnsByCategoryId = (categoryId) => {
- const trns = this.$store.state.trns.items
- let trnsIds = this.$store.getters['trns/selectedTrnsIdsWithDate']
- trnsIds = trnsIds.filter(id => trns[id].categoryId === categoryId)
- trnsIds = trnsIds.filter(id => trns[id].type === this.type)
- return trnsIds
- }
-
- for (const categoryId of categoriesIds) {
- const trnsIds = getTrnsByCategoryId(categoryId)
- if (trnsIds.length > 0)
- cats.push(this.$store.state.categories.items[categoryId]?.name)
- }
-
- return cats
- },
},
methods: {
diff --git a/components/stat/sum/Total.vue b/components/stat/sum/Total.vue
index 19745500..dc8e7b88 100644
--- a/components/stat/sum/Total.vue
+++ b/components/stat/sum/Total.vue
@@ -21,7 +21,7 @@ const statAverage = computed(() => $store.getters['stat/statAverage'])
)
LazyStatSumAverage(
- v-if="statAverage.sum !== 0"
+ v-if="statAverage && statAverage.sum !== 0"
:type="statAverage.sum > 0 ? 1 : 0"
:amount="statAverage.sum"
:title="$t('money.averageTotal')"
diff --git a/components/trnForm/Categories.vue b/components/trnForm/Categories.vue
index c059708b..15988f7a 100644
--- a/components/trnForm/Categories.vue
+++ b/components/trnForm/Categories.vue
@@ -75,14 +75,14 @@ export default {
.swiper-slide
.scrollBlock.scrollerBlock(
- v-if="$store.getters['categories/quickSelectorCategoriesIds'] && $store.getters['categories/quickSelectorCategoriesIds'].length"
+ v-if="$store.getters['categories/favoriteCategoriesIds'] && $store.getters['categories/favoriteCategoriesIds'].length"
)
.py-4.px-3.text-center.text-skin-item-base.text-xl.font-nunito.font-semibold.bg-skin-layout-main.rounded-t-2xl
| {{ $t('categories.favoriteTitle') }} {{ $t('categories.title') }}
.pb-1.px-3
CategoriesList(
:activeItemId="$store.state.trnForm.values.categoryId"
- :ids="$store.getters['categories/quickSelectorCategoriesIds']"
+ :ids="$store.getters['categories/favoriteCategoriesIds']"
class="!gap-x-1"
@onClick="handleCategoryClick"
)
diff --git a/components/trnForm/TrnForm.vue b/components/trnForm/TrnForm.vue
index 62827061..278ec7fd 100644
--- a/components/trnForm/TrnForm.vue
+++ b/components/trnForm/TrnForm.vue
@@ -269,12 +269,12 @@ function handleSubmitForm() {
)
//- Favorite categories
- .pb-7(v-if="$store.getters['categories/quickSelectorCategoriesIds'] && $store.getters['categories/quickSelectorCategoriesIds'].length > 0")
+ .pb-7(v-if="$store.getters['categories/favoriteCategoriesIds'] && $store.getters['categories/favoriteCategoriesIds'].length > 0")
.subTitle.text-center.pb-2.text-xs {{ $t('categories.favoriteTitle') }} {{ $t('categories.title') }}
.px-3
CategoriesList(
v-if="sliderObj"
- :ids="$store.getters['categories/quickSelectorCategoriesIds']"
+ :ids="$store.getters['categories/favoriteCategoriesIds']"
:activeItemId="$store.state.trnForm.values.categoryId"
:slider="sliderObj"
class="!gap-x-1"
diff --git a/components/trnForm/Trns.vue b/components/trnForm/Trns.vue
index 00618ea4..52fed364 100644
--- a/components/trnForm/Trns.vue
+++ b/components/trnForm/Trns.vue
@@ -12,7 +12,6 @@ export default defineComponent({
data() {
return {
pageNumber: 1,
- sortByEditDate: false,
filterBy: 'wallet',
}
},
@@ -43,7 +42,8 @@ export default defineComponent({
const category = this.$store.state.categories.items[catId]
filter.walletsIds = [this.$store.state.trnForm.values.walletId]
- filter.categoriesIds = category?.childIds ? category?.childIds : [catId]
+ // TODO: create function
+ filter.categoriesIds = category?.childIds ?? [catId]
}
const trnsIds = getTrnsIds({ ...filter, trnsItems })
@@ -54,24 +54,18 @@ export default defineComponent({
return trnsIds
},
+ // TODO: duplicate function
+ // Maybe move to trns
groupedTrns() {
- const trns = this.$store.state.trns.items
+ const trnsItems = this.$store.state.trns.items
const trnsIds = this.paginatedTrnsIds
- const trnsList = {}
-
- for (const trnId of trnsIds) {
- let dayDate
- this.sortByEditDate
- ? dayDate = this.$day(trns[trnId].edited).startOf('day').valueOf()
- : dayDate = this.$day(trns[trnId].date).startOf('day').valueOf()
- if (!trnsList[dayDate])
- trnsList[dayDate] = [trnId]
-
- else
- trnsList[dayDate].push(trnId)
- }
- return trnsList
+ return trnsIds.reduce((acc, trnId) => {
+ const date = this.$day(trnsItems[trnId].date).startOf('day').valueOf()
+ acc[date] ??= []
+ acc[date].push(trnId)
+ return acc
+ }, {})
},
},
diff --git a/components/trns/helpers.ts b/components/trns/helpers.ts
new file mode 100644
index 00000000..8cfb31bf
--- /dev/null
+++ b/components/trns/helpers.ts
@@ -0,0 +1,12 @@
+import dayjs from 'dayjs'
+import type { DateValueOf } from '~/components/date/types'
+import type { TrnID, TrnItem } from '~/components/trns/types'
+
+/**
+ * Get the oldest Transaction date
+ */
+export function getOldestTrnDate(trnsItems: Record<TrnID, TrnItem>): DateValueOf {
+ const startOfToday = dayjs().startOf('day').valueOf()
+ const minDate = Math.min(...Object.values(trnsItems).map(trn => trn.date))
+ return minDate || startOfToday
+}
diff --git a/components/trns/item/Details.vue b/components/trns/item/Details.vue
index 945e6514..19119d55 100644
--- a/components/trns/item/Details.vue
+++ b/components/trns/item/Details.vue
@@ -147,19 +147,6 @@ export default {
</template>
<style lang="stylus" scoped>
-.transfer
- padding-top $m5
- font-size 14px
-
- span
- padding-right 2px
- color var(--c-font-3)
- font-size 11px
-
-.trnFormHeaderSeparator
- color var(--c-font-1)
- font-size 32px
-
.trnItem
position relative
color var(--c-font-4)
@@ -196,11 +183,6 @@ export default {
font-size 14px
padding-top $m7
- &__statWrap
- display flex
- align-items center
- padding-bottom 10px
-
&__wallet
display flex
align-items center
@@ -215,9 +197,4 @@ export default {
.walletName
font-size 16px
-
- &__groups
- display inline-block
- padding-left 10px
- font-size 10px
</style>
diff --git a/components/trns/list/TrnsList.vue b/components/trns/list/TrnsList.vue
index 4257b086..b4b8ce5e 100644
--- a/components/trns/list/TrnsList.vue
+++ b/components/trns/list/TrnsList.vue
@@ -97,19 +97,17 @@ export default defineComponent({
return this.trnsIdsWithLimit.slice(0, end)
},
+ // TODO: duplicate function
groupedTrns() {
- const trns = this.$store.state.trns.items
- const trnsList = {}
-
- for (const trnId of this.paginatedTrnsIds) {
- const dayDate = this.$day(trns[trnId].date).startOf('day').valueOf()
-
- !trnsList[dayDate]
- ? trnsList[dayDate] = [trnId]
- : trnsList[dayDate].push(trnId)
- }
-
- return trnsList
+ const trnsItems = this.$store.state.trns.items
+ const trnsIds = this.paginatedTrnsIds
+
+ return trnsIds.reduce((acc, trnId) => {
+ const date = this.$day(trnsItems[trnId].date).startOf('day').valueOf()
+ acc[date] ??= []
+ acc[date].push(trnId)
+ return acc
+ }, {})
},
},
diff --git a/components/trns/list/TrnsListHistory.vue b/components/trns/list/TrnsListHistory.vue
index cd570ba7..d578d744 100644
--- a/components/trns/list/TrnsListHistory.vue
+++ b/components/trns/list/TrnsListHistory.vue
@@ -46,7 +46,6 @@ export default defineComponent({
data() {
return {
pageNumber: 1,
- sortByEditDate: false,
isShowTrnsWithDesc: false,
}
},
@@ -78,22 +77,17 @@ export default defineComponent({
return this.trnsIdsWithLimit.slice(0, end)
},
+ // TODO: duplicate function
groupedTrns() {
- const trns = this.$store.state.trns.items
- const trnsList = {}
-
- for (const trnId of this.paginatedTrnsIds) {
- let dayDate
- this.sortByEditDate
- ? dayDate = this.$day(trns[trnId].edited).startOf('day').valueOf()
- : dayDate = this.$day(trns[trnId].date).startOf('day').valueOf()
-
- !trnsList[dayDate]
- ? trnsList[dayDate] = [trnId]
- : trnsList[dayDate].push(trnId)
- }
-
- return trnsList
+ const trnsItems = this.$store.state.trns.items
+ const trnsIds = this.paginatedTrnsIds
+
+ return trnsIds.reduce((acc, trnId) => {
+ const date = this.$day(trnsItems[trnId].date).startOf('day').valueOf()
+ acc[date] ??= []
+ acc[date].push(trnId)
+ return acc
+ }, {})
},
},
diff --git a/components/wallets/List.vue b/components/wallets/List.vue
index 345b935c..5d7686c8 100644
--- a/components/wallets/List.vue
+++ b/components/wallets/List.vue
@@ -21,6 +21,7 @@ const walletsIdsLimited = computed(() => {
})
const walletsItemsLimited = computed(() => {
+ // TODO: Reduce
if (stateLimit.value !== 0) {
let wallets = {}
for (const id of walletsIdsLimited.value) {
diff --git a/components/wallets/Sort.vue b/components/wallets/Sort.vue
index c9cf7e2f..68e1a595 100644
--- a/components/wallets/Sort.vue
+++ b/components/wallets/Sort.vue
@@ -27,9 +27,11 @@ export default {
'wallets/saveWalletsOrder',
sortedWallets,
)
- if (result.succsess) {
+
+ if (result.success) {
if (this.$listeners.closeModal)
this.$listeners.closeModal()
+
this.$notify({
type: 'success',
title: random(successEmo),
diff --git a/components/wallets/useWallets.ts b/components/wallets/useWallets.ts
index a6ed4ead..b75bdd36 100644
--- a/components/wallets/useWallets.ts
+++ b/components/wallets/useWallets.ts
@@ -36,6 +36,7 @@ export default function useWallets() {
* Wallets currencies
*/
const walletsCurrencies = computed(() => {
+ // TODO: map, maybe Set
const currencies: CurrencyCode[] = []
for (const walletId in walletsItemsSorted.value) {
diff --git a/package.json b/package.json
index ea3f4a60..f99a35e1 100644
--- a/package.json
+++ b/package.json
@@ -27,7 +27,6 @@
"highcharts-vue": "1.4.0",
"localforage": "1.10.0",
"lodash.merge": "4.6.2",
- "lodash.minby": "4.6.0",
"lodash.sortby": "4.7.0",
"nuxt-edge": "latest",
"portal-vue": "2.1.7",
diff --git a/pages/wallets/total.vue b/pages/wallets/total.vue
index 697299b0..2f5d57ae 100644
--- a/pages/wallets/total.vue
+++ b/pages/wallets/total.vue
@@ -1,7 +1,5 @@
<script setup lang="ts">
import _merge from 'lodash.merge'
-import _minby from 'lodash.minby'
-import _sortby from 'lodash.sortby'
import dayjs from 'dayjs'
import type { ComputedRef, Ref } from '@vue/composition-api'
import type { PeriodsNamesExceptAll } from '~/components/date/types'
@@ -11,28 +9,15 @@ import { averageLine, baseSeriesItemStyle, options } from '~/components/chart/ch
import { getTransferCategoriesIds } from '~/components/categories/getCategories'
import { getTotal } from '~/components/amount/getTotal'
import { getTrnsIds } from '~/components/trns/getTrns'
+import { getOldestTrnDate } from '~/components/trns/helpers'
import { formatAmount, getCurrencySymbol } from '~/components/amount/formatAmount'
+import { getMaxPeriodsToShow } from '~/components/date/helpers'
type DateValueOf = number
const { baseCurrencyCode } = useAmount()
const { $store } = useNuxtApp()
-/**
- * Get oldest TrnItem
- */
-function getOldestTrnDate(trnsItems: Record<TrnID, TrnItem>): DateValueOf {
- const startOfToday = dayjs().startOf('day').valueOf()
- return _minby(Object.values(trnsItems), 'date')?.date || startOfToday
-}
-
-/**
- * Get max periods to show
- */
-function getMaxPeriodsToShow(periodName: PeriodsNamesExceptAll, fromDate: DateValueOf): number {
- return dayjs().endOf(periodName).diff(fromDate, periodName) + 1
-}
-
/**
* Transactions
*/
@@ -75,6 +60,7 @@ function getPeriodsDates({ fromDate, periodName, periodsCount }: {
}) {
const periods = []
+ // TODO: new Array map
for (let index = 0; index < periodsCount; index++) {
periods.push({
date: dayjs(fromDate).startOf(periodName).add(index, periodName).startOf(periodName).format(),
diff --git a/services/rates/api.ts b/services/rates/api.ts
index e358f5ac..ddac4f07 100644
--- a/services/rates/api.ts
+++ b/services/rates/api.ts
@@ -7,7 +7,7 @@ export const getRatesOfUSD = async (apiKey: string): Promise<Props | false> => {
const { data } = await axios.get(serviceUrl)
if (!data) {
- console.log('api unavaliable')
+ console.log('api unavailable')
return false
}
diff --git a/store/categories/getters.ts b/store/categories/getters.ts
index c57e4fed..231e0255 100644
--- a/store/categories/getters.ts
+++ b/store/categories/getters.ts
@@ -1,3 +1,6 @@
+import _sortby from 'lodash.sortby'
+import type { TrnID, TrnItem } from '~/components/trns/types'
+import type { CategoryID, CategoryItem } from '~/components/categories/types'
import { getTransferCategoriesIds } from '~/components/categories/getCategories'
export default {
@@ -33,18 +36,18 @@ export default {
},
categoriesForBeParent(state, getters, rootState) {
- const categoriesItems = state.items
- const trnsItems = rootState.trns.items
+ const categoriesItems: Record<CategoryID, CategoryItem> = state.items
+ const trnsItems: Record<TrnID, TrnItem> = rootState.trns.items
const transferCategoriesIds = getTransferCategoriesIds(categoriesItems)
- return getters.categoriesRootIds.filter((categoryId) => {
- const hasTrnsIn = Object.values(trnsItems).some(trn => trn.categoryId === categoryId)
- const isTransferCategory = transferCategoriesIds.includes(categoryId)
+ return getters.categoriesRootIds.filter((id: CategoryID) => {
+ const hasTrnsInCategory = Object.values(trnsItems).some(trn => trn.categoryId === id)
+ const isTransferCategory = transferCategoriesIds.includes(id)
- if (hasTrnsIn || isTransferCategory)
+ if (hasTrnsInCategory || isTransferCategory)
return false
- return categoryId
+ return id
})
},
@@ -71,52 +74,49 @@ export default {
const transferCategoriesIds = getTransferCategoriesIds(categoriesItems)
const trnsIds = Object.keys(trnsItems)
- .filter(trnId => trnsItems[trnId].type !== 2)
+ .filter(id => trnsItems[id].type !== 2)
.sort((a, b) => trnsItems[b].date - trnsItems[a].date)
- const lastCategoriesIds = []
+ const lastCategories = []
- for (const trnId of trnsIds.slice(0, 500)) {
- if (lastCategoriesIds.length > 16)
+ // TODO: map, filter
+ for (const trnId of trnsIds) {
+ if (lastCategories.length > 16)
break
const categoryId = trnsItems[trnId].categoryId
const category = state.items[categoryId]
- if (!category || !category.showInLastUsed)
+ if (!category || ('showInLastUsed' in category && !category.showInLastUsed))
continue
- const isCategoryAlreadyAdded = lastCategoriesIds.includes(categoryId)
+ const isCategoryAlreadyAdded = lastCategories.some(c => c.id === categoryId)
const isTransferCategory = transferCategoriesIds.includes(categoryId)
- const isCategoryInQuickSelector = getters.quickSelectorCategoriesIds.includes(categoryId)
-
- if (!isCategoryAlreadyAdded && !isTransferCategory && !isCategoryInQuickSelector)
- lastCategoriesIds.push(categoryId)
+ const isCategoryInQuickSelector = getters.favoriteCategoriesIds.includes(categoryId)
+
+ if (!isCategoryAlreadyAdded && !isTransferCategory && !isCategoryInQuickSelector) {
+ lastCategories.push({
+ id: categoryId,
+ ...category,
+ })
+ }
}
- lastCategoriesIds.sort((a, b) => {
- if (state.items[a].name > state.items[b].name)
- return 1
- if (state.items[a].name < state.items[b].name)
- return -1
- return 0
- })
-
- return lastCategoriesIds
+ return _sortby(lastCategories, category =>
+ [state.items[category.parentId]?.name || false, category.name])
+ .map(c => c.id)
},
- quickSelectorCategoriesIds(state, getters) {
+ favoriteCategoriesIds(state, getters) {
if (!getters.hasCategories)
return []
- return Object.keys(state.items)
- .filter(key => state.items[key].showInQuickSelector)
- .sort((a, b) => {
- if (state.items[a].name < state.items[b].name)
- return -1
- if (state.items[a].name > state.items[b].name)
- return 1
- return 0
- })
+ const filteredCategories = Object.keys(state.items)
+ .filter(id => state.items[id].showInQuickSelector)
+ .map(id => ({ id, ...state.items[id] }))
+
+ return _sortby(filteredCategories, category =>
+ [state.items[category.parentId]?.name || false, category.name])
+ .map(c => c.id)
},
}
diff --git a/store/categories/mutations.js b/store/categories/mutations.js
index 8323f39f..e439b8b0 100644
--- a/store/categories/mutations.js
+++ b/store/categories/mutations.js
@@ -1,17 +1,16 @@
export default {
setCategories(state, items) {
const freezedItems = {}
- if (items) {
- for (const itemId of Object.keys(items))
- freezedItems[itemId] = Object.freeze(items[itemId])
- }
+ for (const itemId of Object.keys(items))
+ freezedItems[itemId] = Object.freeze(items[itemId])
+
state.items = {
...freezedItems,
transfer: {
color: 'var(--c-blue-1)',
icon: 'mdi mdi-repeat',
name: 'Transfer',
- order: 0,
+ order: 999,
parentId: 0,
childIds: [],
showInLastUsed: false,
diff --git a/store/stat/getters.ts b/store/stat/getters.ts
index 7a9a2a86..da8a4f0a 100644
--- a/store/stat/getters.ts
+++ b/store/stat/getters.ts
@@ -40,25 +40,20 @@ export default {
}
function getCategoriesIdsWithTrnsIds() {
- const filterCategoryId = rootState.filter.categoryId
const categoriesWithTrnsIds = {}
- // TODO: map, filter
for (const trnId of trnsIds) {
- if (trnsItems[trnId]) {
- let categoryId
- filterCategoryId
- ? categoryId = trnsItems[trnId].categoryId
- : categoryId = getRootCategoryIdFromTrnId(trnId)
-
- const isTransferCategory = transferCategoriesIds.includes(categoryId)
- if (isTransferCategory)
- continue
-
- !categoriesWithTrnsIds[categoryId]
- ? categoriesWithTrnsIds[categoryId] = [trnId]
- : categoriesWithTrnsIds[categoryId].push(trnId)
- }
+ if (!trnsItems[trnId])
+ continue
+
+ const categoryId = getRootCategoryIdFromTrnId(trnId)
+
+ const isTransferCategory = transferCategoriesIds.includes(categoryId)
+ if (isTransferCategory)
+ continue
+
+ categoriesWithTrnsIds[categoryId] ??= []
+ categoriesWithTrnsIds[categoryId].push(trnId)
}
return categoriesWithTrnsIds
@@ -97,6 +92,12 @@ export default {
}
}
+ // sort categories amount
+ function sortCategoriesByTotal(categories, typeName) {
+ const categoriesIds = Object.keys(categories)
+ return categoriesIds.sort((a, b) => categories[b][typeName] - categories[a][typeName])
+ }
+
// separate categories by income and expense
const statIncome = {}
const statExpense = {}
@@ -108,24 +109,6 @@ export default {
statExpense[categoryId] = total
}
- // sort categories amount
- function sortCategoriesByTotal(categories, typeName) {
- const categoriesIds = Object.keys(categories)
- let sortedCategoriesIds = []
-
- if (categoriesIds.length) {
- sortedCategoriesIds = categoriesIds.sort((a, b) => {
- if (categories[a][typeName] > categories[b][typeName])
- return -1
- if (categories[a][typeName] < categories[b][typeName])
- return 1
- return 0
- })
- }
-
- return sortedCategoriesIds
- }
-
// sorted
const incomeCategoriesIds = sortCategoriesByTotal(statIncome, 'income')
const expenseCategoriesIds = sortCategoriesByTotal(statExpense, 'expense')
@@ -170,13 +153,14 @@ export default {
const trnsIds = rootGetters['trns/selectedTrnsIds']
const periodName = rootState.filter.period
const transferCategoriesIds = getTransferCategoriesIds(categoriesItems)
+ const emptyData = { income: 0, expense: 0, sum: 0 }
if (periodName === 'all')
- return
+ return emptyData
const oldestTrn = trnsItems[rootGetters['trns/firstCreatedTrnId']]
if (!oldestTrn)
- return
+ return emptyData
const oldestTrnDate = dayjs(oldestTrn.date).endOf(periodName)
let periodsToShow = dayjs().endOf(periodName).diff(oldestTrnDate, periodName) + 1
@@ -214,7 +198,7 @@ export default {
// When just this period and last
const delimiter = periodsToShow - 1
if (delimiter === 1)
- return { income: 0, expense: 0, sum: 0 }
+ return emptyData
return {
income: Math.ceil(income / delimiter),
diff --git a/store/trnForm/actions.js b/store/trnForm/actions.js
index 63f8d69b..186abf9b 100644
--- a/store/trnForm/actions.js
+++ b/store/trnForm/actions.js
@@ -11,7 +11,6 @@ export default {
openTrnForm({ rootState, rootGetters, commit }, { action, trnId }) {
commit('openTrnForm')
const lastTrn = rootState.trns.items[rootGetters['trns/lastCreatedTrnId']]
- console.log(rootGetters['trns/lastCreatedTrnId'], lastTrn)
switch (action) {
case 'create':
diff --git a/store/trns/getters.js b/store/trns/getters.js
index 9a27dcc1..95a61818 100644
--- a/store/trns/getters.js
+++ b/store/trns/getters.js
@@ -4,11 +4,7 @@ import { getTrnsIds } from '~/components/trns/getTrns'
export default {
hasTrns(_state, _getters, rootState) {
- if (rootState.trns.items) {
- if (Object.keys(rootState.trns.items).length > 0)
- return true
- }
- return false
+ return rootState.trns.items && Object.keys(rootState.trns.items).length > 0
},
lastCreatedTrnId(_state, getters, rootState) {
@@ -32,17 +28,14 @@ export default {
return
const trnsItems = rootState.trns.items
- const trnsIds = Object.keys(trnsItems)
- .sort((a, b) => trnsItems[b].date - trnsItems[a].date)
- .reverse()
+ const sortedTrnsIds = Object.keys(trnsItems)
+ .sort((a, b) => trnsItems[a].date - trnsItems[b].date)
- return trnsIds[0]
+ return sortedTrnsIds[0]
},
firstCreatedTrnIdFromSelectedTrns(_state, getters) {
- const trnsIds = [...getters.selectedTrnsIds].reverse()
- if (trnsIds.length)
- return trnsIds[0]
+ return getters.selectedTrnsIds[getters.selectedTrnsIds.length - 1]
},
selectedTrnsIds(_state, getters, rootState) {
diff --git a/store/wallets/actions.js b/store/wallets/actions.js
index f898bec3..c60e7057 100644
--- a/store/wallets/actions.js
+++ b/store/wallets/actions.js
@@ -47,7 +47,7 @@ export default {
updates[`${walletId}/order`] = wallets[walletId]
await updateData(`users/${rootGetters['user/userUid']}/accounts`, updates)
- .then(() => { result.succsess = 'Updated' })
+ .then(() => { result.success = 'Updated' })
.catch((error) => { result.error = error })
return result