Open source personal finance application
feat(Wallets): group wallets by currency
ilkome743c72cece61
diff --git a/components/wallets/Total.vue b/components/wallets/Total.vueindex f74cb768..4ce23fe2 100644--- a/components/wallets/Total.vue+++ b/components/wallets/Total.vue@@ -1,11 +1,17 @@<script setup lang="ts">+import { WalletID, WalletItem } from './types';import useAmount from '~/components/amount/useAmount'+import type { CurrencyCode } from '~/components/currencies/types'const { $store } = useNuxtApp()const { getAmountInBaseRate } = useAmount()+const props = defineProps<{+ walletsItems: Record<WalletID, WalletItem>,+ currencyCode: CurrencyCode+}>()+const totalInWallets = computed(() => {- const walletsItems = $store.state.wallets.itemsconst walletsTotal = $store.getters['wallets/walletsTotal']const total = {counted: 0,@@ -13,22 +19,22 @@ const totalInWallets = computed(() => {credits: 0,}- for (const walletId in walletsItems) {+ for (const walletId in props.walletsItems) {let walletTotal = 0- if (walletsItems[walletId].currency === $store.state.currencies.base) {+ if (props.walletsItems[walletId].currency === props.currencyCode) {walletTotal = walletsTotal[walletId]}else {walletTotal = getAmountInBaseRate({amount: walletsTotal[walletId],- currencyCode: walletsItems[walletId].currency,+ currencyCode: props.walletsItems[walletId].currency,noFormat: true,})}- if (walletsItems[walletId].countTotal)+ if (props.walletsItems[walletId].countTotal)total.counted = total.counted + walletTotal- else if (walletsItems[walletId].isCredit)+ else if (props.walletsItems[walletId].isCredit)total.credits = total.credits + walletTotalelsetotal.savings = total.savings + walletTotal@@ -54,21 +60,21 @@ const counts = computed(() => ({value: totalInWallets.value.counted,icon: 'UiIconWalletWithdrawal',},- total: {- titleId: 'total',- isShow: true,- value: totalInWallets.value.counted + totalInWallets.value.savings,- },withCredit: {titleId: 'withCredit',isShow: totalInWallets.value.credits !== 0,+ value: totalInWallets.value.counted + totalInWallets.value.savings,+ },+ total: {+ titleId: 'total',+ isShow: true,value: totalInWallets.value.counted + totalInWallets.value.savings - Math.abs(totalInWallets.value.credits),},}))</script><template lang="pug">-.px-2.py-1.bg-skin-item-main-bg.rounded-md(+.px-3.py-1.bg-skin-item-main-bg.rounded-md(v-if="$store.getters['wallets/hasWallets']")template(v-for="item in counts")@@ -80,7 +86,7 @@ const counts = computed(() => ({.text-skin-item-baseAmount(- :currencyCode="$store.state.currencies.base"+ :currencyCode="currencyCode":amount="item.value")</template>@@ -90,14 +96,14 @@ const counts = computed(() => ({"en": {"withdrawal": "Withdrawal","credits": "Credits",- "withCredit": "Total with credit",+ "withCredit": "Total without credit","savings": "Savings","total": "Total"},"ru": {"withdrawal": "Доступные","credits": "Кредиты",- "withCredit": "Всего с учетом кредита",+ "withCredit": "Всего без учета кредита","savings": "Вложения","total": "Всего"}diff --git a/components/wallets/page/List.vue b/components/wallets/page/List.vueindex 8d210e4e..6cc1aa83 100644--- a/components/wallets/page/List.vue+++ b/components/wallets/page/List.vue@@ -3,7 +3,26 @@ import useWallets from '~/components/wallets/useWallets'const { $store } = useNuxtApp()const activeTab = computed(() => $store.state.ui.activeTab)-const { walletsCurrencies } = useWallets()+const { walletsCurrencies, walletsItemsSorted } = useWallets()++const walletsCurrenciesTabs = reactive({+ active: 'all',+ currencyCode: computed(() => {+ if (walletsCurrenciesTabs.active === 'all')+ return $store.state.currencies.base+ return walletsCurrenciesTabs.active+ }),+ onSelect: v => walletsCurrenciesTabs.active = v,+ wallets: computed(() => {+ if (walletsCurrenciesTabs.active === 'all')+ return walletsItemsSorted.value++ const array = Object+ .entries(walletsItemsSorted.value)+ .filter(([_key, value]) => value.currency === walletsCurrenciesTabs.active)+ return Object.fromEntries(array)+ })+})</script><script lang="ts">@@ -27,67 +46,67 @@ UiPageUiHeaderLink(@click="$router.push('/wallets/new')")UiIconAdd.w-5.h-5.group-hover_text-white- .pb-6.px-2(v-if="walletsCurrencies.length > 1")+ //- Base currency+ .pt-4.pb-12.px-2(v-if="walletsCurrencies.length > 1")+ .pb-2.text-md.leading-none.font-nunito.font-semibold.text-skin-item-base {{ $t('currenciesBase') }}WalletsCurrenciesChanger- .pb-12.px-2- WalletsTotal+ //- Currencies+ .px-2+ .pb-2.text-md.leading-none.font-nunito.font-semibold.text-skin-item-base {{ $t('list') }}++ //- Tabs+ .pb-4.px-2(v-if="walletsCurrencies.length > 1")+ UiTabs+ UiTabsItem(+ :isActive="walletsCurrenciesTabs.active === 'all'"+ @click="walletsCurrenciesTabs.onSelect('all')"+ ) All+ UiTabsItem(+ v-for="currency in walletsCurrencies"+ :isActive="walletsCurrenciesTabs.active === currency"+ @click="walletsCurrenciesTabs.onSelect(currency)"+ :key="currency"+ ) {{ currency }}//- Total- .pb-4.px-2(v-if="$store.getters['user/isDevUser']")- .flex- .cursor-pointer.p-1.px-3.flex.items-center.gap-3.rounded-md.bg-skin-item-main-bg.hocus_bg-skin-item-main-hover(- @click="$router.push('/wallets/total')"- )- .mdi.mdi-poll.text-xl- .text-xs.leading-none.text-skin-item-base Total details- .mdi.mdi-chevron-right.text-lg.leading-none.text-skin-item-base-down+ .pb-4.px-2+ WalletsTotal(+ :walletsItems="walletsCurrenciesTabs.wallets"+ :currencyCode="walletsCurrenciesTabs.currencyCode"+ )//- List//---------------------------------- WalletsList(#default="{ walletsItemsSorted }")- .pb-12.px-2.grid.gap-y-1.gap-x-6.md_grid-cols-2- //- Wallet- .cursor-pointer.flex.items-center.py-2.px-3.rounded-md.bg-skin-item-main-bg.hocus_bg-skin-item-main-hover(- v-for="(walletItem, walletId) in walletsItemsSorted"- :key="walletId"- @click="$router.push(`/wallets/${walletId}`)"- )- .grow.gap-x-3.flex.items-center- .grow.flex-center.gap-x-3- //- Icon- .w-6.h-6.rounded-md.flex-center.text-skin-icon-base.text-xs.leading-none(- :style="{ background: walletItem.color }"- class="mt-[2px]"- ) {{ walletItem.name.substring(0, 2) }}- .grow.flex.items-center.gap-3- .text-sm.text-skin-item-base {{ walletItem.name }}- UiIconWalletWithdrawal.w-4.h-4.text-skin-item-base-down(- v-if="walletItem.countTotal"- )- UiIconWalletSavings.w-4.h-4.text-skin-item-base-down(- v-if="!walletItem.countTotal && !walletItem.isCredit"- )-- //- Amount- Amount(- :amount="walletItem.amount"- :currencyCode="walletItem.currency"- )-- template(#bottom)- .pb-4.px-2.flex.justify-evenly.gap-6- //- Sort- .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]"- @click="$store.dispatch('ui/setActiveTab', 'walletsSort')"- ) {{ $t('base.sort') }}-- //- Create- .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]"- @click="$router.push('/wallets/new')"- ) {{ $t('wallets.new') }}+ .pb-12.px-2.grid.gap-y-1.gap-x-6.md_grid-cols-2+ //- Wallet+ .cursor-pointer.flex.items-center.py-2.px-3.rounded-md.bg-skin-item-main-bg.hocus_bg-skin-item-main-hover(+ v-for="(walletItem, walletId) in walletsCurrenciesTabs.wallets"+ :key="walletId"+ @click="$router.push(`/wallets/${walletId}`)"+ )+ .grow.gap-x-3.flex.items-center+ .grow.flex-center.gap-x-3+ //- Icon+ .w-6.h-6.rounded-md.flex-center.text-skin-icon-base.text-xs.leading-none(+ :style="{ background: walletItem.color }"+ class="mt-[2px]"+ ) {{ walletItem.name.substring(0, 2) }}+ .grow.flex.items-center.gap-3+ .text-sm.text-skin-item-base {{ walletItem.name }}+ UiIconWalletWithdrawal.w-4.h-4.text-skin-item-base-down(+ v-if="walletItem.countTotal"+ )+ UiIconWalletSavings.w-4.h-4.text-skin-item-base-down(+ v-if="!walletItem.countTotal && !walletItem.isCredit"+ )++ //- Amount+ Amount(+ :amount="walletItem.amount"+ :currencyCode="walletItem.currency"+ )+//- Sort//-----------------------------------@@ -126,3 +145,17 @@ UiPage//- @closeModal="close"//- )</template>++<i18n lang="json5">+ {+ "en": {+ "list": "List",+ "currenciesBase": "Base currency",+ },++ "ru": {+ "list": "Список",+ "currenciesBase": "Основная валюта",+ }+ }+ </i18n>diff --git a/components/wallets/useWallets.ts b/components/wallets/useWallets.tsindex 300990e4..264b5dcf 100644--- a/components/wallets/useWallets.ts+++ b/components/wallets/useWallets.ts@@ -14,10 +14,9 @@ export default function useWallets() {* Wallets items sorted**/- const walletsItemsSorted = computed<Record<WalletID, WalletItemWithAmount>>(() => {+ const walletsItemsSorted: ComputedRef<Record<WalletID, WalletItemWithAmount>> = computed(() => {const walletsIdsSorted: WalletID[] = $store.getters['wallets/walletsSortedIds']- // TODO: check Areturn walletsIdsSorted.reduce((acc, id) => {acc[id] ??= []acc[id] = {@@ -31,7 +30,7 @@ export default function useWallets() {/*** Wallets currencies*/- const walletsCurrencies = computed(() => {+ const walletsCurrencies: ComputedRef<WalletID[]> = computed(() => {const walletsIdsSorted: WalletID[] = $store.getters['wallets/walletsSortedIds']const walletsItems: Record<WalletID, WalletItem> = $store.state.wallets.items