Skip to content

Open source personal finance application

refactor: enhance wallets page with advanced grouping and filtering

Ilya Komichevc4f66c32bd8d
diff --git a/app/components/bottomSheet/BottomSheet.vue b/app/components/bottomSheet/BottomSheet.vue
index cba56aa6..11fb692b 100644
--- a/app/components/bottomSheet/BottomSheet.vue
+++ b/app/components/bottomSheet/BottomSheet.vue
@@ -278,7 +278,7 @@ async function onDragEnd() {
const isNeedClose
= nextCurrentY.value >= settings.pixelsNeedToDrugForClose
- && direction.value === 'down'
+ && direction.value === 'down'
if (isNeedClose) {
close()
diff --git a/app/components/stat/categories/Section.vue b/app/components/stat/categories/Section.vue
index 4ea6d1a5..50a46712 100644
--- a/app/components/stat/categories/Section.vue
+++ b/app/components/stat/categories/Section.vue
@@ -62,21 +62,21 @@ function getBiggestCatNumber(categories: CategoryWithData[]) {
}
}
-type CategoryState = {
- categories?: CategoryStateInside
- show: boolean
-}
-
type CategoryStateInside = Record<CategoryId, { show: boolean }>
+type CategoryState = { categories?: CategoryStateInside, show: boolean }
type CategoriesState = Record<CategoryId, CategoryState>
+function createInitialChildState(childIds?: CategoryId[]): CategoryStateInside {
+ return (childIds ?? []).reduce((acc, childId) => {
+ acc[childId] = { show: false }
+ return acc
+ }, {} as CategoryStateInside)
+}
+
function createInitialState(storeCategories: Categories): CategoriesState {
return Object.entries(storeCategories).reduce((acc, [id, cat]) => {
acc[id] = {
- categories: (cat.childIds ?? []).reduce((childAcc, childId) => {
- childAcc[childId] = { show: false }
- return childAcc
- }, {} as CategoryStateInside),
+ categories: createInitialChildState(cat.childIds),
show: false,
}
return acc
@@ -88,28 +88,32 @@ const categoriesOpened = useStorage<CategoriesState>(
createInitialState(categoriesStore.items ?? {}),
)
+function getChildState(cat: CategoryWithData): CategoryStateInside {
+ return Object.values(cat.categories ?? {}).reduce((acc, child) => {
+ acc[child.id] = { show: categoriesOpened.value[cat.id]?.categories?.[child.id]?.show ?? false }
+ return acc
+ }, {} as CategoryStateInside)
+}
+
function getCurrentState(categories: CategoryWithData[]): CategoriesState {
- return Object.values(categories).reduce((acc, cat) => {
+ return categories.reduce((acc, cat) => {
acc[cat.id] = {
- categories: Object.values(cat.categories ?? {}).reduce((childAcc, child) => {
- childAcc[child.id] = { show: categoriesOpened.value[cat.id]?.categories?.[child.id]?.show ?? false }
- return childAcc
- }, {} as CategoryStateInside),
+ categories: getChildState(cat),
show: categoriesOpened.value[cat.id]?.show ?? false,
}
-
return acc
}, {} as CategoriesState)
}
const currentState = computed(() => getCurrentState(categoriesWithData.value))
+
const openedStatus = computed(() => {
- const categories = Object.values(currentState.value)
+ const cats = Object.values(currentState.value)
return {
- isAllChildOpen: categories.every(cat => Object.values(cat.categories ?? {}).every(c => c.show)),
- isAllRootOpen: categories.every(cat => cat.show),
- isAnyChildOpen: categories.some(cat => Object.values(cat.categories ?? {}).some(c => c.show)),
- isAnyRootOpen: categories.some(cat => cat.show),
+ isAllChildOpen: cats.every(cat => Object.values(cat.categories ?? {}).every(c => c.show)),
+ isAllRootOpen: cats.every(cat => cat.show),
+ isAnyChildOpen: cats.some(cat => Object.values(cat.categories ?? {}).some(c => c.show)),
+ isAnyRootOpen: cats.some(cat => cat.show),
}
})
@@ -118,28 +122,23 @@ function toggleOpened() {
updateState(currentState.value, { childShow: true })
return
}
-
if (openedStatus.value.isAnyRootOpen) {
updateState(currentState.value, { childShow: false, parentShow: false })
return
}
-
updateState(currentState.value, { parentShow: true })
}
function toggleRoot(id: CategoryId) {
const root = currentState.value[id]
const allOpen = Object.values(root?.categories ?? {}).some(c => c.show)
-
if (root?.show && allOpen) {
categoriesOpened.value[id].categories = Object.keys(currentState.value[id]?.categories ?? {}).reduce((childAcc, childId) => {
childAcc[childId] = { show: false }
return childAcc
}, {} as CategoryStateInside)
-
return
}
-
categoriesOpened.value[id].show = !categoriesOpened.value[id]?.show
}
@@ -147,29 +146,21 @@ function toggleChild(id: CategoryId, childId: CategoryId) {
categoriesOpened.value[id].categories[childId].show = !categoriesOpened.value[id]?.categories?.[childId]?.show
}
-// Combined update function
-function updateState(
- state: CategoriesState,
- options: { childShow?: boolean, parentShow?: boolean },
-) {
+function updateState(state: CategoriesState, options: { childShow?: boolean, parentShow?: boolean }) {
const { childShow, parentShow } = options
-
- categoriesOpened.value = defu(
- Object.entries(state).reduce((acc, [id, cat]) => {
- acc[id] = {
- ...cat,
- ...(parentShow !== undefined && { show: parentShow }),
- ...(childShow !== undefined && {
- categories: Object.fromEntries(
- Object.keys(cat.categories ?? {})
- .map(childId => [childId, { show: childShow }]),
- ),
- }),
- }
- return acc
- }, {} as CategoriesState),
- categoriesOpened.value,
- )
+ const newState = Object.entries(state).reduce((acc, [id, cat]) => {
+ acc[id] = { ...cat }
+ if (parentShow !== undefined) {
+ acc[id].show = parentShow
+ }
+ if (childShow !== undefined) {
+ acc[id].categories = Object.fromEntries(
+ Object.keys(cat.categories ?? {}).map(childId => [childId, { show: childShow }]),
+ )
+ }
+ return acc
+ }, {} as CategoriesState)
+ categoriesOpened.value = defu(newState, categoriesOpened.value)
}
</script>
@@ -183,7 +174,7 @@ function updateState(
v-if="statConfig.config.value.vertical.isShow"
:storageKey="`${storageKey}-${type}-vertical`"
:initStatus="true"
- class="@3xl/page:p-3 rounded-xl border border-item-4 bg-item-2 p-2 md:max-w-lg"
+ class="@3xl/page:p-3 border-item-4 bg-item-2 rounded-xl border p-2 md:max-w-lg"
>
<template #header="{ toggle, isShown }">
<div class="flex items-center justify-between md:max-w-lg">
@@ -275,7 +266,7 @@ function updateState(
v-if="statConfig.config.value.catsRound.isShow"
:storageKey="`${storageKey}-${type}-rounds`"
:initStatus="true"
- class="@3xl/page:p-3 rounded-xl border border-item-4 bg-item-2 p-2 md:max-w-lg"
+ class="@3xl/page:p-3 border-item-4 bg-item-2 rounded-xl border p-2 md:max-w-lg"
>
<template #header="{ toggle, isShown }">
<div class="flex items-center justify-between md:max-w-lg">
@@ -357,7 +348,7 @@ function updateState(
v-if="statConfig.config.value.catsList.isShow"
:storageKey="`${storageKey}-${type}-list`"
:initStatus="true"
- class="@3xl/page:p-3 rounded-xl border border-item-4 bg-item-2 p-2 md:max-w-lg"
+ class="@3xl/page:p-3 border-item-4 bg-item-2 rounded-xl border p-2 md:max-w-lg"
>
<template #header="{ toggle, isShown }">
<div class="flex items-center justify-between md:max-w-lg">
@@ -374,15 +365,15 @@ function updateState(
@click="toggleOpened"
>
<Icon
- v-if="openedStatus.isAllRootOpen && !openedStatus.isAllChildOpen"
+ v-if="openedStatus.isAnyRootOpen && !openedStatus.isAllChildOpen"
name="lucide:folder-open"
/>
<Icon
- v-if="openedStatus.isAllRootOpen && openedStatus.isAllChildOpen"
+ v-if="openedStatus.isAnyRootOpen && openedStatus.isAllChildOpen"
name="lucide:folder-kanban"
/>
<Icon
- v-if="!openedStatus.isAllRootOpen"
+ v-if="!openedStatus.isAnyRootOpen && !openedStatus.isAllRootOpen"
name="lucide:folder"
/>
</UiItem1>
diff --git a/app/components/trns/Item.vue b/app/components/trns/Item.vue
index 976ed162..14b2f2b7 100644
--- a/app/components/trns/Item.vue
+++ b/app/components/trns/Item.vue
@@ -37,7 +37,7 @@ const { t } = useI18n()
<template v-if="alt">
<div
v-if="date"
- class="text-2xs min-w-10 truncate leading-none"
+ class="min-w-10 truncate text-2xs leading-none"
>
{{ date }}
</div>
@@ -51,7 +51,7 @@ const { t } = useI18n()
:color="props.trnItem.category?.color"
size="16"
/>
- <div class="text-2 flex items-center gap-2 text-xs leading-none">
+ <div class="flex items-center gap-2 text-xs leading-none text-2">
{{ trnItem.category.name }}
</div>
</div>
@@ -63,7 +63,7 @@ const { t } = useI18n()
>
<div
v-if="!alt"
- class="text-3 grid grow gap-0.5"
+ class="grid grow gap-0.5 text-3"
>
<CategoriesName
v-if="trnItem.type !== TrnType.Transfer"
@@ -77,7 +77,7 @@ const { t } = useI18n()
v-if="trnItem.wallet"
class="flex items-center gap-2"
>
- <div class="text-4 text-xs leading-none">
+ <div class="text-xs leading-none text-4">
{{ trnItem.wallet.name }}
</div>
</div>
@@ -101,7 +101,7 @@ const { t } = useI18n()
v-if="trnItem.type === 2"
class="grid gap-1"
>
- <div class="text-3 flex gap-1 text-sm leading-none">
+ <div class="flex gap-1 text-sm leading-none text-3">
{{ t('transfer.from') }} <span class="font-semibold">{{ trnItem.expenseWallet.name }}</span>
{{ t('transfer.to') }} <span class="font-semibold">{{ trnItem.incomeWallet.name }}</span>
</div>
diff --git a/app/components/ui/Header.vue b/app/components/ui/Header.vue
index 96ec217b..ed02a413 100644
--- a/app/components/ui/Header.vue
+++ b/app/components/ui/Header.vue
@@ -1,6 +1,6 @@
<template>
- <div class="mb-2 grid min-h-12 max-w-7xl items-center border-b border-item-4 px-2 sm:min-h-14 lg:px-4 2xl:px-8">
- <div class="flex grow items-center gap-2">
+ <div class="mb-2 grid max-w-7xl items-center border-b border-item-4 px-2 sm:min-h-14 lg:px-4 2xl:px-8">
+ <div class="flex min-h-12 grow items-center gap-2 pl-1">
<slot />
<div v-if="$slots.actions" class="ml-auto flex items-center">
diff --git a/app/components/ui/TabsItem1.vue b/app/components/ui/TabsItem1.vue
index bd1e3b4f..93cb0f43 100644
--- a/app/components/ui/TabsItem1.vue
+++ b/app/components/ui/TabsItem1.vue
@@ -10,7 +10,7 @@ const emit = defineEmits(['click'])
<template>
<div
- :class="[getStyles('item', ['minh2']), {
+ :class="[getStyles('item', ['minh3']), {
'!bg-item-4': isActive,
}]"
class="flex flex-1 grow select-none items-center justify-center gap-1 text-nowrap rounded-lg px-2 text-sm text-3 hocus:bg-item-5"
diff --git a/app/components/ui/Title8.vue b/app/components/ui/Title8.vue
index 9140675e..5d3860ef 100644
--- a/app/components/ui/Title8.vue
+++ b/app/components/ui/Title8.vue
@@ -13,7 +13,7 @@ const emit = defineEmits<{
<template>
<div
:class="getStyles('item', ['link', 'center', 'padding3', 'minh2', 'minw1', 'rounded'])"
- class="flex grow items-center gap-2 pb-0 !font-tertiary !text-lg font-bold leading-none !text-3"
+ class="flex grow items-center gap-2 pb-0 !font-tertiary !text-lg font-bold leading-none !text-1"
@click="emit('click')"
>
<div><slot /></div>
diff --git a/app/components/ui/TitleDropRight.vue b/app/components/ui/TitleDropRight.vue
index eb9424fd..8d669c93 100644
--- a/app/components/ui/TitleDropRight.vue
+++ b/app/components/ui/TitleDropRight.vue
@@ -12,14 +12,14 @@ const emit = defineEmits<{
<template>
<div
:class="getStyles('item', ['link', 'center', 'padding3', 'minh2', 'minw1', 'rounded'])"
- class="flex grow items-center gap-2 pb-0 font-tertiary text-base font-semibold leading-none !text-3"
+ class="flex grow items-center gap-2 pb-0"
@click="emit('click')"
>
<Icon
:name="props.isShown ? 'lucide:chevron-down' : 'lucide:chevron-right'"
size="22"
- class="-ml-1"
+ class="!text-4 -ml-1"
/>
- <div><slot /></div>
+ <slot />
</div>
</template>
diff --git a/app/components/ui/Toggle3.vue b/app/components/ui/Toggle3.vue
index e85f6721..de957cce 100644
--- a/app/components/ui/Toggle3.vue
+++ b/app/components/ui/Toggle3.vue
@@ -1,6 +1,7 @@
<script setup lang="ts">
const props = defineProps<{
isShown: boolean
+ lineWidth?: number
openPadding?: string
}>()
@@ -27,5 +28,11 @@ const emit = defineEmits<{
:toggle="() => emit('click', !props.isShown)"
/>
</div>
+
+ <div
+ v-if="lineWidth && !isShown"
+ class="mx-2 h-px bg-item-5 group-last:hidden"
+ :class="{ 'ml-12': lineWidth === 3, 'ml-11': lineWidth === 2 }"
+ />
</div>
</template>
diff --git a/app/components/ui/Toggle2.vue b/app/components/ui/ToggleWithStorage.vue
similarity index 100%
rename from app/components/ui/Toggle2.vue
rename to app/components/ui/ToggleWithStorage.vue
diff --git a/app/components/wallets/Currencies.vue b/app/components/wallets/Currencies.vue
new file mode 100644
index 00000000..b3b25e9c
--- /dev/null
+++ b/app/components/wallets/Currencies.vue
@@ -0,0 +1,62 @@
+<script lang="ts" setup>
+import type { CurrencyCode } from '~/components/currencies/types'
+import type { WalletsCurrencyFiltered } from '~/components/wallets/types'
+
+import { useWalletsStore } from '~/components/wallets/useWalletsStore'
+
+defineProps<{
+ currencyFiltered: WalletsCurrencyFiltered
+}>()
+
+const emit = defineEmits<{
+ onSelectFilterCurrency: [code: CurrencyCode]
+}>()
+
+const { t } = useI18n()
+const walletsStore = useWalletsStore()
+</script>
+
+<template>
+ <UiToggleWithStorage
+ :initStatus="true"
+ :lineWidth="0"
+ class="@xl/page:grid @xl/page:max-w-xl @3xl/page:p-3 _border border-item-4 bg-item-2 rounded-xl p-2 md:max-w-lg"
+ storageKey="finapp-wallets-currencies"
+ >
+ <template #header="{ toggle, isShown }">
+ <UiTitle8
+ :isShown
+ @click="toggle"
+ >
+ {{ t('filterByCurrency') }}
+ {{ (currencyFiltered !== 'all' && !isShown) ? currencyFiltered : '' }}
+ </UiTitle8>
+ </template>
+
+ <UiTabs2 class="@xl/page:px-0 flex gap-1 px-2">
+ <UiTabsItem1
+ :isActive="currencyFiltered === 'all'"
+ @click="emit('onSelectFilterCurrency', 'all')"
+ >
+ {{ t('common.all') }}
+ </UiTabsItem1>
+
+ <UiTabsItem1
+ v-for="currency in walletsStore.currenciesUsed"
+ :key="currency"
+ :isActive="currencyFiltered === currency"
+ @click="emit('onSelectFilterCurrency', currency)"
+ >
+ {{ currency }}
+ </UiTabsItem1>
+ </UiTabs2>
+ </UiToggleWithStorage>
+</template>
+
+<i18n lang="yaml">
+ en:
+ filterByCurrency: Filter by
+
+ ru:
+ filterByCurrency: Валюты кошельков
+ </i18n>
diff --git a/app/components/wallets/Item.vue b/app/components/wallets/Item.vue
index 6456eb5c..ad9fe146 100644
--- a/app/components/wallets/Item.vue
+++ b/app/components/wallets/Item.vue
@@ -12,6 +12,7 @@ const props = defineProps<{
alt?: boolean
insideClasses?: string
isShowBaseRate?: boolean
+ isShowCreditLimit?: boolean
isShowIcon?: boolean
isShowRate?: boolean
isSort?: boolean
@@ -80,9 +81,11 @@ if (!props.isSort) {
<!-- Main -->
<template v-if="!props.alt">
<div class="grid grow gap-1">
- <div class="text-sm leading-none text-3">
+ <div class="text-3 text-sm leading-none">
{{ wallet.name }}
</div>
+
+ <!-- Rate -->
<div
v-if="props.isShowRate && wallet.currency !== currenciesStore.base && wallet.rate"
class="opacity-90"
@@ -97,6 +100,33 @@ if (!props.isSort) {
class="text-xs opacity-70"
/>
</div>
+
+ <div
+ v-if="props.isShowCreditLimit && wallet.type === 'credit' && wallet.creditLimit"
+ class="flex items-center gap-0.5"
+ >
+ <Amount
+ :amount="wallet.creditLimit - Math.abs(wallet.amount)"
+ :currencyCode="wallet.currency"
+ :isShowBaseRate="false"
+ :isShowSymbol="false"
+ align="left"
+ variant="2xs"
+ />
+
+ <div class="text-2xs opacity-70">
+ /
+ </div>
+
+ <Amount
+ :amount="wallet.creditLimit"
+ :currencyCode="wallet.currency"
+ :isShowBaseRate="false"
+ :isShowSymbol="false"
+ align="left"
+ variant="2xs"
+ />
+ </div>
</div>
<div
@@ -124,6 +154,10 @@ if (!props.isSort) {
<!-- Alternative -->
<template v-if="props.alt">
<div class="grid grow gap-0.5">
+ <div class="text-3 whitespace-nowrap text-sm leading-none">
+ {{ wallet.name }}
+ </div>
+
<div v-if="!isSort">
<Amount
v-if="wallet.creditLimit"
@@ -144,15 +178,11 @@ if (!props.isSort) {
variant="2xs"
/>
</div>
-
- <div class="whitespace-nowrap text-sm leading-none text-3">
- {{ wallet.name }}
- </div>
</div>
<div
v-if="isSort"
- class="sortHandle flex-center absolute right-0 h-full rounded-md px-3 group-hocus:bg-item-5"
+ class="sortHandle flex-center group-hocus:bg-item-5 absolute right-0 h-full rounded-md px-3"
>
<Icon name="lucide:grip-vertical" size="20" />
</div>
diff --git a/app/components/wallets/Statistics.vue b/app/components/wallets/Statistics.vue
new file mode 100644
index 00000000..ebf1d4b3
--- /dev/null
+++ b/app/components/wallets/Statistics.vue
@@ -0,0 +1,89 @@
+<script setup lang="ts">
+import type { CurrencyCode } from '~/components/currencies/types'
+
+const props = defineProps<{
+ activeType?: string | false
+ counts: Record<string, {
+ id: string
+ isShow: boolean
+ secondValue?: number
+ value: number
+ }>
+ currencyCode: CurrencyCode
+ storageKey: string
+}>()
+
+const emit = defineEmits<{
+ click: [v: string]
+}>()
+
+const { t } = useI18n()
+
+const itemsGrouped = computed(() => [
+ [props.counts.all, props.counts.withdrawal, props.counts.available, props.counts.excludeInTotal, props.counts.archived].filter(i => i.isShow),
+ [props.counts.cash, props.counts.cashless, props.counts.deposit, props.counts.credit, props.counts.crypto, props.counts.debt].filter(i => i.isShow),
+])
+</script>
+
+<template>
+ <UiToggleWithStorage
+ :initStatus="true"
+ :lineWidth="0"
+ :storageKey="props.storageKey"
+ class="@3xl/page:p-3 border-item-4 bg-item-2 _border mb-2 rounded-xl p-2 pb-3 md:max-w-lg"
+ >
+ <template #header="{ toggle, isShown }">
+ <div class="flex grow items-center justify-between">
+ <UiTitle8 :isShown @click="toggle">
+ {{ t('statistics.title') }}
+ </UiTitle8>
+ </div>
+ </template>
+
+ <div class="grid gap-6">
+ <div
+ v-for="(items, idx) in itemsGrouped"
+ :key="idx"
+ class="py-px"
+ >
+ <UiElement
+ v-for="item in items"
+ :key="item.id"
+ :isActive="props.activeType === item.id"
+ :lineWidth="5"
+ class="group"
+ insideClasses="!min-h-[44px]"
+ @click="emit('click', item.id)"
+ >
+ <div class="text-2 grow pl-1 text-sm leading-none">
+ <div>
+ {{ $t(`money.types.${item.id}`) }}
+ </div>
+
+ <div
+ v-if="item.secondValue"
+ class="flex items-center gap-1 pt-1 opacity-90"
+ >
+ <Amount
+ :amount="item.secondValue - Math.abs(item.value)"
+ :currencyCode="currencyCode"
+ />
+ <div>/</div>
+ <Amount
+ :amount="item.secondValue"
+ :currencyCode="currencyCode"
+ />
+ </div>
+ </div>
+
+ <div class="pr-1 opacity-90">
+ <Amount
+ :amount="item.value"
+ :currencyCode="currencyCode"
+ />
+ </div>
+ </UiElement>
+ </div>
+ </div>
+ </UiToggleWithStorage>
+</template>
diff --git a/app/components/wallets/Total.vue b/app/components/wallets/Total.vue
deleted file mode 100644
index 6d04fdd0..00000000
--- a/app/components/wallets/Total.vue
+++ /dev/null
@@ -1,41 +0,0 @@
-<script setup lang="ts">
-import type { CurrencyCode } from '~/components/currencies/types'
-
-const props = defineProps<{
- activeType?: string
- currencyCode: CurrencyCode
- items: {
- id: string
- value: number
- }[]
-}>()
-
-const emit = defineEmits<{
- click: [v: string]
-}>()
-</script>
-
-<template>
- <div class="py-px">
- <UiElement
- v-for="item in items"
- :key="item.id"
- :isActive="props.activeType === item.id"
- :lineWidth="5"
- class="group"
- insideClasses="!min-h-[44px]"
- @click="emit('click', item.id)"
- >
- <div class="grow pl-1 text-sm leading-none text-2">
- {{ $t(`money.types.${item.id}`) }}
- </div>
-
- <div class="pr-1 opacity-90">
- <Amount
- :amount="item.value"
- :currencyCode="currencyCode"
- />
- </div>
- </UiElement>
- </div>
-</template>
diff --git a/app/components/wallets/page/List.vue b/app/components/wallets/page/List.vue
index ac904a56..8abb36e1 100644
--- a/app/components/wallets/page/List.vue
+++ b/app/components/wallets/page/List.vue
@@ -1,14 +1,12 @@
<script setup lang="ts">
import { useStorage } from '@vueuse/core'
-import { groupBy } from 'es-toolkit'
import type { CurrencyCode } from '~/components/currencies/types'
-import type { WalletId, WalletItem, WalletViewTypes, WalletViewTypesObj } from '~/components/wallets/types'
+import type { WalletId, WalletItem, WalletsCurrencyFiltered, WalletsGroupedBy, WalletType, WalletViewTypes } from '~/components/wallets/types'
import { useAmount } from '~/components/amount/useAmount'
import { useAppNav } from '~/components/app/useAppNav'
import { useCurrenciesStore } from '~/components/currencies/useCurrenciesStore'
-import { viewTypes } from '~/components/wallets/types'
import { useWalletsStore } from '~/components/wallets/useWalletsStore'
const { t } = useI18n()
@@ -25,58 +23,49 @@ const { isModalOpen, openModal } = useAppNav()
const { getAmountInBaseRate } = useAmount()
const isShowBaseCurrencyModal = ref(false)
+const currencyFiltered = useStorage<WalletsCurrencyFiltered>('finapp-wallets-active-currency', 'all')
+const walletViewType = useStorage<WalletViewTypes | 'all'>('finapp-wallets-active-type', 'all')
-const currencyFiltered = useStorage('finapp-wallets-active-currency', 'all')
-const activeType = useStorage<WalletViewTypes | 'all'>(
- 'finapp-wallets-active-type',
- 'all',
-)
-const groupedBy = useStorage<'list' | 'currencies' | 'type'>(
- 'finapp-wallets-groupedBy',
- 'list',
-)
-
-function setActiveType(v: WalletViewTypes | 'all') {
- activeType.value = v
+function setWalletViewType(v: WalletType | 'all') {
+ walletViewType.value = v
}
-const groupedOptions = useStorage('finapp-wallets-groupedOptions', {
- currencies: 0,
- type: 0,
+const groupedBy = useStorage<WalletsGroupedBy>('finapp-wallets-groupedBy', 'none')
+const groupedBySecondary = useStorage('finapp-wallets-groupedBySecondary', {
+ currency: false,
+ type: false,
})
-const selectedWallets = computed(() => {
- return Object.fromEntries(
- Object.entries(walletsStore.itemsComputed).filter(([_key, wallet]) => {
- const isCurrencyMatch = currencyFiltered.value === 'all' || currencyFiltered.value === wallet.currency
- if (!isCurrencyMatch)
- return false
-
- if (activeType.value === 'all')
- return !wallet.isArchived
-
- const typeChecks: WalletViewTypesObj = {
- archived: wallet.isArchived ?? false,
- available: (checkIsAvailable(wallet) && !wallet.isArchived) ?? false,
- cash: wallet.type === 'cash' && !wallet.isArchived,
- cashless: wallet.type === 'cashless' && !wallet.isArchived,
- credit: wallet.type === 'credit' && !wallet.isArchived,
- creditPossible: wallet.type === 'credit' && wallet.creditLimit > 0,
- crypto: wallet.type === 'crypto' && !wallet.isArchived,
- debt: wallet.type === 'debt' && !wallet.isArchived,
- deposit: wallet.type === 'deposit' && !wallet.isArchived,
- withdrawal: (wallet.isWithdrawal ?? false) && !wallet.isArchived,
- }
+const selectedWalletsIdsWithCurrency = computed<WalletId[]>(() => {
+ return Object.keys(walletsStore.itemsComputed).filter((id) => {
+ const wallet = walletsStore.itemsComputed[id]
+ if (groupedBy.value === 'currency')
+ return true
+ return currencyFiltered.value === 'all' || currencyFiltered.value === wallet?.currency
+ })
+})
+
+const selectedWalletsIds = computed<WalletId[]>(() => {
+ return selectedWalletsIdsWithCurrency.value.filter((id) => {
+ const wallet = walletsStore.itemsComputed[id]!
+
+ if (walletViewType.value === 'isWithdrawal')
+ return wallet.isWithdrawal && !wallet.isArchived
- if (activeType.value === 'available')
- return checkIsAvailable(wallet) && !wallet.isArchived
+ if (walletViewType.value === 'isExcludeInTotal')
+ return wallet.isExcludeInTotal && !wallet.isArchived
- if (activeType.value === 'archived' && wallet.isArchived)
- return true
+ if (walletViewType.value === 'isArchived')
+ return wallet.isArchived
- return typeChecks[activeType.value]
- }),
- )
+ if (walletViewType.value === 'isAvailable')
+ return (wallet.type === 'credit' || wallet.isWithdrawal) && !wallet.isArchived
+
+ if (walletViewType.value === 'all')
+ return !wallet.isArchived
+
+ return wallet.type === walletViewType.value && !wallet.isArchived
+ })
})
const isShowCurrencyFilter = ref(false)
@@ -85,66 +74,28 @@ function onSelectFilterCurrency(code: CurrencyCode, toggle?: () => void) {
if (currencyFiltered.value === code && toggle)
toggle()
- activeType.value = 'all'
+ walletViewType.value = 'all'
currencyFiltered.value = code
isShowCurrencyFilter.value = false
}
-const groupedWalletsByCurrency = computed(() => {
- const grouped: Record<string, WalletId[]> = Object.fromEntries(
- walletsStore.currenciesUsed.map(currency => [currency, []]),
- )
-
- return walletsStore.sortedIds.reduce((grouped, id) => {
- const wallet = walletsStore.items?.[id]
- if (wallet?.currency && !wallet.isArchived)
- grouped[wallet.currency]?.push(id)
- return grouped
- }, grouped)
-})
-
-const groupedWalletsByType = computed(() => {
- return viewTypes.reduce((acc, type) => {
- acc[type] = walletsStore.sortedIds.filter((id) => {
- const wallet = walletsStore.items?.[id]
- if (!wallet)
- return false
-
- const isCurrencyFiltered = currencyFiltered.value === 'all' || wallet.currency === currencyFiltered.value
- const isAvailable = checkIsAvailable(wallet)
-
- switch (type) {
- case 'available':
- return isAvailable && isCurrencyFiltered && !wallet.isArchived
- case 'archived':
- return isCurrencyFiltered && wallet.isArchived
- default:
- return wallet.type === type && isCurrencyFiltered && !wallet.isArchived
- }
- })
-
- return acc
- }, {} as Record<CurrencyCode, WalletId[]>)
-})
-
-const groupedWalletsByTypeOnly = computed(() => {
- return Object.fromEntries(Object.entries(groupedWalletsByType.value).filter(([_, walletsIds]) => walletsIds.length > 0))
-})
-
-const totalInWallets = computed(() => {
+const counts = computed(() => {
const sum = {
archived: 0,
+ available: 0,
cash: 0,
cashless: 0,
credit: 0,
creditPossible: 0,
+ crypto: 0,
debt: 0,
deposit: 0,
+ excludeInTotal: 0,
total: 0,
withdrawal: 0,
}
- for (const walletId in walletsStore.itemsComputed) {
+ for (const walletId of selectedWalletsIdsWithCurrency.value) {
const wallet = walletsStore.itemsComputed[walletId]
if (!wallet)
continue
@@ -158,11 +109,10 @@ const totalInWallets = computed(() => {
noFormat: true,
})
- if (currencyFiltered.value !== 'all' && wallet.currency !== currencyFiltered.value) {
- continue
+ if (wallet.isExcludeInTotal) {
+ sum.excludeInTotal += itemValue
}
-
- if (!wallet.isExcludeInTotal) {
+ else {
sum.total += itemValue
}
@@ -171,6 +121,8 @@ const totalInWallets = computed(() => {
if (wallet.type === 'cashless')
sum.cashless += itemValue
+ if (wallet.type === 'crypto')
+ sum.crypto += itemValue
if (wallet.type === 'deposit')
sum.deposit += itemValue
@@ -181,14 +133,12 @@ const totalInWallets = computed(() => {
if (wallet.type === 'credit')
sum.credit += itemValue
- if (wallet.creditLimit) {
- sum.creditPossible
- = sum.creditPossible
- + +getAmountInBaseRate({
- amount: wallet.creditLimit ?? 0,
- currencyCode: wallet.currency ?? 'USD',
- noFormat: true,
- })
+ if (wallet.type === 'credit' && wallet.creditLimit) {
+ sum.creditPossible = sum.creditPossible + +getAmountInBaseRate({
+ amount: wallet.creditLimit ?? 0,
+ currencyCode: wallet.currency ?? 'USD',
+ noFormat: true,
+ })
}
if (wallet.isWithdrawal)
@@ -199,22 +149,324 @@ const totalInWallets = computed(() => {
}
}
- return sum
+ return {
+ all: {
+ id: 'all',
+ isShow: true,
+ value: sum.total,
+ },
+ available: {
+ id: 'isAvailable',
+ isShow: sum.withdrawal !== 0,
+ value: sum.withdrawal - Math.abs(sum.credit),
+ },
+ // eslint-disable-next-line perfectionist/sort-objects
+ cash: {
+ id: 'cash',
+ isShow: Object.keys(walletsStore.itemsComputed).length > 1 && sum.cash !== 0,
+ value: sum.cash,
+ },
+ // eslint-disable-next-line perfectionist/sort-objects
+ cashless: {
+ id: 'cashless',
+ isShow: sum.cashless !== 0,
+ value: sum.cashless,
+ },
+ // eslint-disable-next-line perfectionist/sort-objects
+ credit: {
+ id: 'credit',
+ isShow: sum.credit !== 0,
+ secondValue: sum.creditPossible,
+ value: sum.credit,
+ },
+ // eslint-disable-next-line perfectionist/sort-objects
+ crypto: {
+ id: 'crypto',
+ isShow: sum.crypto !== 0,
+ value: sum.crypto,
+ },
+ // eslint-disable-next-line perfectionist/sort-objects
+ debt: {
+ id: 'debt',
+ isShow: sum.debt !== 0,
+ value: sum.debt,
+ },
+ // eslint-disable-next-line perfectionist/sort-objects
+ deposit: {
+ id: 'deposit',
+ isShow: sum.deposit !== 0,
+ value: sum.deposit,
+ },
+ // eslint-disable-next-line perfectionist/sort-objects
+ withdrawal: {
+ id: 'isWithdrawal',
+ isShow: sum.withdrawal !== 0,
+ value: sum.withdrawal,
+ },
+ // eslint-disable-next-line perfectionist/sort-objects
+ excludeInTotal: {
+ id: 'isExcludeInTotal',
+ isShow: sum.excludeInTotal !== 0,
+ value: sum.excludeInTotal,
+ },
+ // eslint-disable-next-line perfectionist/sort-objects
+ archived: {
+ id: 'isArchived',
+ isShow: selectedWalletsIdsWithCurrency.value.some(wallet => walletsStore.itemsComputed[wallet]?.isArchived),
+ value: sum.archived,
+ },
+ }
+})
+
+type WalletsGroupedByExcludedNone = Exclude<WalletsGroupedBy, 'none'>
+type WalletGroup = {
+ groups?: Record<string, WalletId[]>
+ ids: WalletId[]
+}
+type GroupToggleState = {
+ groups?: Record<string, boolean>
+ show?: boolean
+}
+type ToggleMapByGroup = Record<string, GroupToggleState>
+type WalletsToggleMap = Partial<Record<WalletsGroupedByExcludedNone, ToggleMapByGroup>>
+type GroupedWallets = Record<string, WalletGroup>
+
+// Update the storage definition with proper type and default value
+const walletsToggledMap = useStorage<WalletsToggleMap>('finapp-wallets-toggle-map', {} as WalletsToggleMap, localStorage, {
+ mergeDefaults: true,
+})
+
+// Helper functions to improve readability
+function groupWalletsByStrategy(ids: WalletId[], strategy: keyof WalletItem): Record<string, WalletId[]> {
+ return Object.groupBy(ids, (id) => {
+ const wallet = walletsStore.itemsComputed[id]
+ return wallet ? String(wallet[strategy] || '') : ''
+ }) as Record<string, WalletId[]>
+}
+
+function createPrimaryGroups(grouped: Record<string, WalletId[]>): GroupedWallets {
+ return Object.entries(grouped).reduce<GroupedWallets>((acc, [key, ids]) => {
+ acc[key] = { groups: {}, ids }
+ return acc
+ }, {})
+}
+
+function createSecondaryGroups(grouped: Record<string, WalletId[]>, secondaryStrategy: keyof WalletItem): GroupedWallets {
+ return Object.entries(grouped).reduce<GroupedWallets>((acc, [key, ids]) => {
+ acc[key] = {
+ groups: groupWalletsByStrategy(ids, secondaryStrategy),
+ ids,
+ }
+ return acc
+ }, {})
+}
+
+const groupedWalletsWithIds = computed<GroupedWallets | false>(() => {
+ if (groupedBy.value === 'none')
+ return false
+
+ const groupingStrategies = {
+ currency: {
+ primary: 'currency',
+ secondary: 'type',
+ },
+ type: {
+ primary: 'type',
+ secondary: 'currency',
+ },
+ } as const
+
+ const strategy = groupingStrategies[groupedBy.value as WalletsGroupedByExcludedNone]
+ if (!strategy)
+ return false
+
+ const ids = selectedWalletsIds.value
+ const primaryGrouped = groupWalletsByStrategy(ids, strategy.primary)
+
+ let useSecondaryGrouping = false
+ if (groupedBy.value === 'currency') {
+ useSecondaryGrouping = !!groupedBySecondary.value.currency
+ }
+ else if (groupedBy.value === 'type') {
+ useSecondaryGrouping = !!groupedBySecondary.value.type
+ }
+
+ return useSecondaryGrouping
+ ? createSecondaryGroups(primaryGrouped, strategy.secondary)
+ : createPrimaryGroups(primaryGrouped)
})
-function groupByWalletType(id: WalletId) {
- return walletsStore.items?.[id]?.type
+function toggleMap(groupPrimary: string, groupSecondary?: string) {
+ const currentGroup = groupedBy.value
+ if (currentGroup === 'none')
+ return
+
+ const currentToggleMap = { ...walletsToggledMap.value }
+ currentToggleMap[currentGroup] ??= {}
+
+ if (!currentToggleMap[currentGroup]![groupPrimary])
+ currentToggleMap[currentGroup]![groupPrimary] = { groups: {} }
+
+ if (groupSecondary) {
+ const primaryGroup = currentToggleMap[currentGroup]![groupPrimary]
+ primaryGroup.groups ??= {}
+
+ // Toggle the secondary group
+ const currentValue = primaryGroup.groups[groupSecondary]
+ primaryGroup.groups[groupSecondary] = currentValue === undefined ? false : !currentValue
+ }
+ // Handle primary group toggle
+ else {
+ const primaryGroup = currentToggleMap[currentGroup]![groupPrimary]
+ primaryGroup.groups ??= {}
+ primaryGroup.show = primaryGroup.show === undefined ? false : !primaryGroup.show
+ }
+
+ walletsToggledMap.value = currentToggleMap
}
-function groupByWalletCurrency(id: WalletId) {
- const wallet = walletsStore.items?.[id]
- return wallet?.currency
+const typeGroupsStatus = computed(() => {
+ const currentGroup = groupedBy.value
+ if (currentGroup === 'none' || !walletsToggledMap.value[currentGroup])
+ return { isAllOpen: false, isAllOpenInside: false, isAnyOpen: false, isAnyOpenInside: false }
+
+ const groups = walletsToggledMap.value[currentGroup] || {}
+
+ return {
+ isAllOpen: Object.values(groups).every(group => !!group.show),
+ isAllOpenInside: Object.values(groups).every(group =>
+ Object.values(group.groups || {}).every(isOpen => !!isOpen),
+ ),
+ isAnyOpen: Object.values(groups).some(group => !!group.show),
+ isAnyOpenInside: Object.values(groups).some(group =>
+ Object.values(group.groups || {}).some(isOpen => !!isOpen),
+ ),
+ }
+})
+
+function toggleOpened() {
+ const currentGroup = groupedBy.value
+ if (currentGroup === 'none' || !groupedWalletsWithIds.value)
+ return
+
+ const currentToggleMap = { ...walletsToggledMap.value }
+ currentToggleMap[currentGroup] ??= {}
+
+ const { isAllOpen, isAllOpenInside } = typeGroupsStatus.value
+ const groupPrimaries = Object.keys(groupedWalletsWithIds.value)
+
+ // We know groupedWalletsWithIds.value is not false at this point
+ const groupedWallets = groupedWalletsWithIds.value as GroupedWallets
+
+ // Check if we're using secondary grouping
+ let hasSecondaryGrouping = false
+ if (currentGroup === 'currency') {
+ hasSecondaryGrouping = !!groupedBySecondary.value.currency
+ }
+ else if (currentGroup === 'type') {
+ hasSecondaryGrouping = !!groupedBySecondary.value.type
+ }
+
+ // If we don't have secondary grouping, just toggle the primary groups' show property
+ if (!hasSecondaryGrouping) {
+ // If all primary groups are open, close them all
+ // Otherwise, open them all
+ const newShowState = !isAllOpen
+
+ groupPrimaries.forEach((groupPrimary) => {
+ const primaryGroup = currentToggleMap[currentGroup]![groupPrimary] || { groups: {} }
+
+ currentToggleMap[currentGroup]![groupPrimary] = {
+ ...primaryGroup,
+ show: newShowState,
+ }
+ })
+ }
+ // If we have secondary grouping, handle the three cases as before
+ else {
+ // Case 1: All primary groups are open but not all inner groups are open
+ // Set all inner groups to true
+ if (isAllOpen && !isAllOpenInside) {
+ groupPrimaries.forEach((groupPrimary) => {
+ const primaryGroup = currentToggleMap[currentGroup]![groupPrimary] || { groups: {}, show: true }
+
+ // Get all secondary groups for this primary group
+ const walletGroup = groupedWallets[groupPrimary]
+ const secondaryGroups = walletGroup && walletGroup.groups ? walletGroup.groups : {}
+
+ // Set all inner groups to true
+ currentToggleMap[currentGroup]![groupPrimary] = {
+ ...primaryGroup,
+ groups: Object.keys(secondaryGroups).reduce((acc, groupSecondary) => {
+ acc[groupSecondary] = true
+ return acc
+ }, { ...primaryGroup.groups }),
+ show: true,
+ }
+ })
+ }
+ // Case 2: All primary groups and all inner groups are open
+ // Set everything to false
+ else if (isAllOpen && isAllOpenInside) {
+ groupPrimaries.forEach((groupPrimary) => {
+ const primaryGroup = currentToggleMap[currentGroup]![groupPrimary] || { groups: {}, show: false }
+
+ // Get all secondary groups for this primary group
+ const walletGroup = groupedWallets[groupPrimary]
+ const secondaryGroups = walletGroup && walletGroup.groups ? walletGroup.groups : {}
+
+ // Set primary show to false and all inner groups to false
+ currentToggleMap[currentGroup]![groupPrimary] = {
+ ...primaryGroup,
+ groups: Object.keys(secondaryGroups).reduce((acc, groupSecondary) => {
+ acc[groupSecondary] = false
+ return acc
+ }, { ...primaryGroup.groups }),
+ show: false,
+ }
+ })
+ }
+ // Case 3: Not all primary groups are open
+ else {
+ groupPrimaries.forEach((groupPrimary) => {
+ const primaryGroup = currentToggleMap[currentGroup]![groupPrimary] || { groups: {} }
+
+ currentToggleMap[currentGroup]![groupPrimary] = {
+ ...primaryGroup,
+ show: true,
+ }
+ })
+ }
+ }
+
+ walletsToggledMap.value = currentToggleMap
}
+const groupTabs = computed(() => {
+ const items: {
+ id: WalletsGroupedBy
+ label: string
+ }[] = [{
+ id: 'none',
+ label: t('none'),
+ }, {
+ id: 'type',
+ label: t('type'),
+ }]
+
+ if (walletsStore.currenciesUsed.length > 1) {
+ items.push({
+ id: 'currency',
+ label: t('currencies'),
+ })
+ }
+
+ return items
+})
+
function countWalletsSum(
walletsIds: WalletId[],
isConvert = true,
- isExcludeInTotal = false,
) {
return walletsIds.reduce((acc, id) => {
const wallet = walletsStore.itemsComputed[id]
@@ -232,73 +484,16 @@ function countWalletsSum(
)
}
- if (isExcludeInTotal && wallet.isExcludeInTotal)
+ if (wallet.isExcludeInTotal)
return acc
return acc + wallet.amount
}, 0)
}
-
-function checkIsAvailable(wallet: WalletItem) {
- return wallet.type === 'credit' || wallet.isWithdrawal
-}
-
-const counts = computed(() => ({
- all: {
- id: 'all',
- isShow: true,
- value: totalInWallets.value.total - totalInWallets.value.credit - totalInWallets.value.debt,
- },
- cashless: {
- id: 'cashless',
- isShow: groupedBy.value === 'list' && totalInWallets.value.cashless !== 0,
- value: totalInWallets.value.cashless,
- },
- // eslint-disable-next-line perfectionist/sort-objects
- cash: {
- id: 'cash',
- isShow: Object.keys(walletsStore.items ?? {}).length > 1 && groupedBy.value === 'list' && totalInWallets.value.cash !== 0,
- value: totalInWallets.value.cash,
- },
- credit: {
- id: 'credit',
- isShow: groupedBy.value === 'list' && totalInWallets.value.credit !== 0,
- value: totalInWallets.value.credit,
- },
- // eslint-disable-next-line perfectionist/sort-objects
- creditPossible: {
- id: 'creditPossible',
- isShow: totalInWallets.value.creditPossible !== 0,
- value: totalInWallets.value.creditPossible + totalInWallets.value.credit,
- },
- // eslint-disable-next-line perfectionist/sort-objects
- debt: {
- id: 'debt',
- isShow: groupedBy.value === 'list' && totalInWallets.value.debt !== 0,
- value: totalInWallets.value.debt,
- },
- // eslint-disable-next-line perfectionist/sort-objects
- deposit: {
- id: 'deposit',
- isShow: groupedBy.value === 'list' && totalInWallets.value.deposit !== 0,
- value: totalInWallets.value.deposit,
- },
- // eslint-disable-next-line perfectionist/sort-objects
- withdrawal: {
- id: 'withdrawal',
- isShow: groupedBy.value === 'list' && totalInWallets.value.withdrawal !== 0,
- value: totalInWallets.value.withdrawal,
- },
- // eslint-disable-next-line perfectionist/sort-objects
- archived: {
- id: 'archived',
- isShow: Object.values(walletsStore.items ?? {}).some(wallet => wallet.isArchived),
- value: totalInWallets.value.archived,
- },
-}))
</script>
<template>
<UiPage>
+ <!-- Header -->
<UiHeader>
<UiHeaderTitle>{{ t('wallets.name') }}</UiHeaderTitle>
<template #actions>
@@ -323,7 +518,7 @@ const counts = computed(() => ({
<UiButtonAccent
@click="router.push('/wallets/new')"
>
- {{ t("wallets.new") }}
+ {{ t('wallets.new') }}
</UiButtonAccent>
</div>
</div>
@@ -331,393 +526,236 @@ const counts = computed(() => ({
<!-- Content -->
<div
v-else
- class="max-w-4xl grow px-2 lg:px-4 2xl:px-8"
+ class="@xl/page:grid-cols-2 @xl/page:gap-6 @3xl/page:gap-12 grid max-w-4xl grow px-2 lg:px-4 2xl:px-8"
>
- <div class="@xl/page:grid-cols-2 @xl/page:gap-12 grid">
- <div class="@xl/page:order-1 @xl/page:gap-4 @xl/page:pt-1 @md/page:pb-2 grid content-start pb-1">
- <div
- v-if="walletsStore.currenciesUsed.length > 1"
- class="@xl/page:hidden grid grid-cols-2 gap-2 pb-2"
- >
- <!-- Currencies -->
- <UiButtonWithRight
- isShort
- @click="isShowCurrencyFilter = true"
- >
- <template #label>
- {{ t('filterByCurrency') }}
- </template>
- <template #value>
- {{ currencyFiltered === 'all' ? t('all') : currencyFiltered }}
- </template>
- </UiButtonWithRight>
+ <!-- Right -->
+ <div class="@xl/page:order-1 @xl/page:gap-4 @xl/page:pt-1 grid content-start gap-3">
+ <!-- Wallets Currencies -->
+ <WalletsCurrencies
+ v-if="walletsStore.currenciesUsed.length > 1 && groupedBy !== 'currency'"
+ :currencyFiltered
+ @onSelectFilterCurrency="code => currencyFiltered = code"
+ />
+
+ <!-- Total -->
+ <WalletsStatistics
+ :storageKey="`finapp-wallets-total-${groupedBy}`"
+ :activeType="walletViewType"
+ :currencyCode="currenciesStore.base"
+ :counts="counts"
+ @click="setWalletViewType"
+ />
+
+ <UiButtonWithRight
+ class="@xl/page:grid hidden grow"
+ @click="isShowBaseCurrencyModal = true"
+ >
+ <template #label>
+ {{ t('currencies.base') }}
+ </template>
+ <template #value>
+ {{ currenciesStore.base }}
+ </template>
+ </UiButtonWithRight>
+ </div>
- <!-- Base -->
- <UiButtonWithRight
- isShort
- @click="isShowBaseCurrencyModal = true"
+ <!-- Left content -->
+ <div>
+ <div class="mb-2 flex min-h-12 items-center gap-2 md:pt-2">
+ <UiTabs2>
+ <UiTabsItem4
+ v-for="item in groupTabs"
+ :key="item.id"
+ :isActive="item.id === groupedBy"
+ @click="groupedBy = item.id"
>
- <template #label>
- {{ t('currencies.base') }}
- </template>
- <template #value>
- {{ currenciesStore.base }}
- </template>
- </UiButtonWithRight>
- </div>
-
- <!-- Wallets Currencies -->
- <UiToggle2
- v-if="walletsStore.currenciesUsed.length > 1 && groupedBy !== 'currencies'"
- :initStatus="true"
- :lineWidth="0"
- class="@xl/page:grid @xl/page:max-w-xl hidden"
- openPadding="!pb-0"
- storageKey="finapp-wallets-currencies"
- >
- <template #header="{ toggle, isShown }">
- <UiTitle8
- :isShown
- @click="toggle"
- >
- {{ t('filterByCurrency') }}
- {{ (currencyFiltered !== 'all' && !isShown) ? currencyFiltered : '' }}
- </UiTitle8>
- </template>
-
- <template #default="{ toggle }">
- <UiTabs2 class="@xl/page:px-0 flex gap-1 px-2">
- <DateLinkItem
- :isActive="currencyFiltered === 'all'"
- @click="onSelectFilterCurrency('all', toggle)"
- >
- {{ t('common.all') }}
- </DateLinkItem>
-
- <DateLinkItem
- v-for="currency in walletsStore.currenciesUsed"
- :key="currency"
- :isActive="currencyFiltered === currency"
- @click="onSelectFilterCurrency(currency, toggle)"
- >
- {{ currency }}
- </DateLinkItem>
- </UiTabs2>
- </template>
- </UiToggle2>
-
- <!-- Total -->
- <UiToggle2
- :initStatus="true"
- :lineWidth="0"
- :storageKey="`finapp-wallets-total-${groupedBy}`"
- class="@xl/page:grid hidden pb-3"
- openPadding="!pb-4"
- >
- <template #header="{ toggle, isShown }">
- <div class="flex grow items-center justify-between">
- <UiTitle8 :isShown @click="toggle">
- {{ t('statistics.title') }}
- </UiTitle8>
- </div>
- </template>
+ {{ item.label }}
+ </UiTabsItem4>
+ </UiTabs2>
- <WalletsTotal
- :activeType="groupedBy === 'list' ? activeType : false"
- :currencyCode="currenciesStore.base"
- :items="Object.values(counts).filter((item) => item.isShow)"
- @click="setActiveType"
- />
- </UiToggle2>
-
- <UiButtonWithRight
- class="@xl/page:grid hidden grow"
- @click="isShowBaseCurrencyModal = true"
+ <div
+ v-if="groupedBy !== 'none'"
+ class="ml-auto flex items-center gap-1"
>
- <template #label>
- {{ t('currencies.base') }}
- </template>
- <template #value>
- {{ currenciesStore.base }}
- </template>
- </UiButtonWithRight>
- </div>
-
- <div>
- <div class="mb-2 flex items-center gap-2 md:pt-2">
- <UiTabs2>
- <UiTabsItem4
- :isActive="groupedBy === 'list'"
- @click="groupedBy = 'list'"
- >
- {{ t('list') }}
- </UiTabsItem4>
- <UiTabsItem4
- :isActive="groupedBy === 'type'"
- @click="groupedBy = 'type'"
- >
- {{ t('type') }}
- </UiTabsItem4>
-
- <UiTabsItem4
- v-if="walletsStore.currenciesUsed.length > 1"
- :isActive="groupedBy === 'currencies'"
- @click="groupedBy = 'currencies'"
- >
- {{ t('currencies') }}
- </UiTabsItem4>
- <UiTabsItem4
- v-if="groupedBy !== 'list'"
- class="ml-auto grow-0 px-5"
- @click="groupedOptions[groupedBy] = groupedOptions[groupedBy] === 0 ? 1 : 0"
- >
- <Icon
- :name="groupedOptions[groupedBy] === 0 ? 'lucide:folder-tree' : 'lucide:network'"
- size="18"
- />
- </UiTabsItem4>
- </UiTabs2>
+ <UiItem1
+ @click="
+ groupedBy === 'currency'
+ ? groupedBySecondary.currency = !groupedBySecondary.currency
+ : groupedBy === 'type'
+ ? groupedBySecondary.type = !groupedBySecondary.type
+ : null
+ "
+ >
+ <Icon
+ :name="
+ (groupedBy === 'currency' && groupedBySecondary.currency)
+ || (groupedBy === 'type' && groupedBySecondary.type)
+ ? 'lucide:network'
+ : 'lucide:folder-tree'
+ "
+ size="18"
+ />
+ </UiItem1>
+
+ <UiItem1 @click="toggleOpened">
+ <Icon
+ v-if="typeGroupsStatus.isAllOpen"
+ name="lucide:folder-open"
+ />
+ <Icon
+ v-else-if="typeGroupsStatus.isAnyOpen"
+ name="lucide:folder-open-dot"
+ />
+ <Icon
+ v-else
+ name="lucide:folder"
+ />
+ </UiItem1>
</div>
+ </div>
- <!-- Statistics -->
- <UiToggle2
- :initStatus="true"
- :lineWidth="0"
- :storageKey="`finapp-wallets-total-${groupedBy}`"
- class="@xl/page:hidden pb-3"
- openPadding="!pb-4"
- >
- <template #header="{ toggle, isShown }">
- <div class="flex grow items-center justify-between">
- <UiTitle8 :isShown @click="toggle">
- {{ t('statistics.title') }}
- </UiTitle8>
- </div>
- </template>
-
- <WalletsTotal
- :activeType="groupedBy === 'list' ? activeType : false"
- :currencyCode="currenciesStore.base"
- :items="Object.values(counts).filter((item) => item.isShow)"
- @click="setActiveType"
- />
- </UiToggle2>
-
- <!-- List -->
+ <!-- Wallets List -->
+ <div class="@xl/page:max-w-lg md:max-w-lg">
+ <!-- No grouping -->
<div
- v-if="groupedBy === 'list'"
- class="@xl/page:max-w-lg"
+ v-if="groupedBy === 'none'"
+ class="border-item-4 bg-item-2 rounded-xl md:max-w-lg"
>
<WalletsItem
- v-for="(walletItem, walletId) in selectedWallets"
+ v-for="walletId in selectedWalletsIds"
:key="walletId"
- :wallet="walletItem"
+ :wallet="walletsStore.itemsComputed[walletId]!"
:walletId
:lineWidth="2"
class="group"
isShowBaseRate
isShowIcon
isShowRate
+ isShowCreditLimit
@click="router.push(`/wallets/${walletId}`)"
/>
</div>
- <!-- By currencies -->
- <template v-if="groupedBy === 'currencies'">
- <UiToggle2
- v-for="(walletsIds, currency) in groupedWalletsByCurrency"
- :key="currency"
- :storageKey="`finapp-wallets-show-${currency}`"
- :initStatus="true"
- :lineWidth="1"
- openPadding="!pb-3"
+ <!-- Grouping -->
+ <div
+ v-if="groupedBy !== 'none' && groupedWalletsWithIds"
+ class="grid gap-4"
+ >
+ <UiToggle3
+ v-for="(content, groupPrimary) in groupedWalletsWithIds"
+ :key="groupPrimary"
+ :class="{
+ 'bg-item-2 rounded': Object.keys(content.groups ?? {}).length === 0,
+ }"
+ :isShown="
+ walletsToggledMap[groupedBy]?.[groupPrimary]?.show ?? true
+ "
>
- <template #header="{ toggle, isShown }">
- <div
- class="flex grow items-center justify-between pr-3"
- @click="toggle"
+ <template #header="{ isShown }">
+ <UiTitleDropRight
+ :isShown
+ @click="toggleMap(groupPrimary)"
>
- <UiTitleDropRight :isShown>
- {{ currency }} {{ !isShown ? walletsIds.length : '' }}
- </UiTitleDropRight>
-
- <div class="py-2">
- <Amount
- :amount="countWalletsSum(walletsIds, false, true)"
- :currencyCode="currency"
- />
+ <div class="font-tertiary !text-3 text-base font-semibold leading-none">
+ {{ groupedBy === 'type' ? t(`money.types.${groupPrimary}`) : groupPrimary }}
</div>
- </div>
- </template>
- <div class="ml-5 -translate-x-px border-l border-item-4 pl-3">
- <template v-if="groupedOptions.currencies === 0">
- <WalletsItem
- v-for="walletId in walletsIds"
- :key="walletId"
- :wallet="walletsStore.itemsComputed[walletId]"
- :walletId
- :lineWidth="2"
- isShowBaseRate
- isShowIcon
- isShowRate
- class="group"
- @click="router.push(`/wallets/${walletId}`)"
- />
- </template>
-
- <template v-if="groupedOptions.currencies === 1">
- <UiToggle2
- v-for="(groupedWalletsIds, grouped) in groupBy(walletsIds, groupByWalletType)"
- :key="grouped"
- :initStatus="true"
- :lineWidth="1"
- :storageKey="`finapp-wallets-show-${currency}-${grouped}`"
- openPadding="!pb-3"
- >
- <template #header="{ isShown, toggle }">
- <div
- class="flex grow items-center justify-between pr-3"
- @click="toggle"
- >
- <UiTitleDropRight :isShown>
- {{ t(`money.types.${grouped}`) }}
- </UiTitleDropRight>
- <div class="py-2">
- <Amount
- :amount="countWalletsSum(groupedWalletsIds, false)"
- :currencyCode="currency"
- />
- </div>
- </div>
- </template>
-
- <div class="ml-5 -translate-x-px border-l border-item-4 pl-3">
- <WalletsItem
- v-for="walletId in groupedWalletsIds"
- :key="walletId"
- :lineWidth="2"
- :wallet="walletsStore.itemsComputed[walletId]"
- :walletId
- class="group"
- isShowBaseRate
- isShowIcon
- isShowRate
- @click="router.push(`/wallets/${walletId}`)"
- />
- </div>
- </UiToggle2>
- </template>
- </div>
- </UiToggle2>
- </template>
-
- <!-- By Type -->
- <template v-if="groupedBy === 'type'">
- <UiToggle2
- v-for="(walletsIds, type) in groupedWalletsByTypeOnly"
- :key="type"
- :storageKey="`finapp-wallets-show-${type}`"
- :initStatus="true"
- :lineWidth="1"
- openPadding="!pb-3"
- >
- <template #header="{ toggle, isShown }">
- <div
- class="flex grow items-center justify-between pr-3"
- @click="toggle"
- >
- <UiTitleDropRight :isShown>
- {{ t(`money.types.${type}`) }} {{ walletsIds.length }}
- </UiTitleDropRight>
-
- <div class="py-2">
+ <div class="ml-auto">
<Amount
- :amount="countWalletsSum(walletsIds)"
+ :amount="countWalletsSum(content.ids)"
:currencyCode="currenciesStore.base"
+ :isShowBaseRate="false"
+ />
+ <Amount
+ v-if="groupedBy === 'currency' && currenciesStore.base !== groupPrimary"
+ :amount="countWalletsSum(content.ids, false)"
+ :currencyCode="groupPrimary"
+ :isShowBaseRate="false"
+ variant="2xs"
/>
</div>
- </div>
+ </UiTitleDropRight>
</template>
- <div class="ml-5 -translate-x-px border-l border-item-4 pl-3">
- <template v-if="groupedOptions.type === 0">
+ <div
+ v-if="Object.keys(content.groups ?? {}).length > 0"
+ class="grid gap-2"
+ >
+ <UiToggle3
+ v-for="(ids, groupSecondary) in content.groups"
+ :key="groupSecondary"
+ :isShown="
+ walletsToggledMap[groupedBy]?.[groupPrimary]?.groups?.[groupSecondary] ?? true
+ "
+ class="border-item-4 bg-item-2 _border group grid gap-1 rounded-xl"
+ >
+ <template #header="{ isShown }">
+ <UiTitleDropRight
+ :isShown
+ @click="toggleMap(groupPrimary, groupSecondary)"
+ >
+ <div class="font-tertiary !text-3 text-base font-semibold leading-none">
+ {{ groupedBy === 'currency' ? t(`money.types.${groupSecondary}`) : groupSecondary }}
+ </div>
+ <div class="ml-auto">
+ <Amount
+ :amount="countWalletsSum(ids)"
+ :currencyCode="currenciesStore.base"
+ :isShowBaseRate="false"
+ />
+ <Amount
+ v-if="groupedBy === 'currency' && currenciesStore.base !== groupPrimary"
+ :amount="countWalletsSum(ids, false)"
+ :currencyCode="groupPrimary"
+ :isShowBaseRate="false"
+ variant="2xs"
+ />
+ </div>
+ </UiTitleDropRight>
+ </template>
+
<WalletsItem
- v-for="walletId in walletsIds"
+ v-for="walletId in ids"
:key="walletId"
:lineWidth="2"
- :wallet="walletsStore.itemsComputed[walletId]"
+ :wallet="walletsStore.itemsComputed[walletId]!"
:walletId
class="group"
isShowBaseRate
+ isShowCreditLimit
isShowIcon
isShowRate
@click="router.push(`/wallets/${walletId}`)"
/>
- </template>
-
- <template v-if="groupedOptions.type === 1">
- <UiToggle2
- v-for="(groupedWalletsIds, currency) in groupBy(walletsIds, groupByWalletCurrency)"
- :key="currency"
- :storageKey="`finapp-wallets-show-${type}-${currency}`"
- :initStatus="true"
- :lineWidth="1"
- openPadding="!pb-3"
- >
- <template #header="{ toggle, isShown }">
- <div
- class="flex grow items-center justify-between pr-3"
- @click="toggle"
- >
- <UiTitleDropRight :isShown>
- {{ currency }}
- </UiTitleDropRight>
-
- <div class="py-2">
- <Amount
- :amount="countWalletsSum(groupedWalletsIds)"
- :currencyCode="currenciesStore.base"
- :isShowBaseRate="false"
- />
- <Amount
- v-if="currenciesStore.base !== currency"
- :amount="countWalletsSum(groupedWalletsIds, false)"
- :currencyCode="currency"
- :isShowBaseRate="false"
- variant="2xs"
- />
- </div>
- </div>
- </template>
-
- <div class="ml-5 -translate-x-px border-l border-item-4 pl-3">
- <WalletsItem
- v-for="walletId in groupedWalletsIds"
- :key="walletId"
- :lineWidth="2"
- :wallet="walletsStore.itemsComputed[walletId]"
- :walletId
- class="group"
- isShowBaseRate
- isShowIcon
- isShowRate
- @click="router.push(`/wallets/${walletId}`)"
- />
- </div>
- </UiToggle2>
- </template>
+ </UiToggle3>
</div>
- </UiToggle2>
- </template>
+
+ <template v-else>
+ <WalletsItem
+ v-for="walletId in content.ids"
+ :key="walletId"
+ :lineWidth="2"
+ :wallet="walletsStore.itemsComputed[walletId]!"
+ :walletId
+ class="group"
+ isShowBaseRate
+ isShowCreditLimit
+ isShowIcon
+ isShowRate
+ @click="router.push(`/wallets/${walletId}`)"
+ />
+ </template>
+ </UiToggle3>
+ </div>
</div>
</div>
</div>
</UiPage>
- <!-- Sort -->
+ <!-- Sort Modal -->
<WalletsSortModal v-if="isModalOpen('walletsSort')" />
+ <!-- Base Currency Modal -->
<CurrenciesModal
v-if="isShowBaseCurrencyModal"
:activeCode="currenciesStore.base"
@@ -725,6 +763,7 @@ const counts = computed(() => ({
@onClose="isShowBaseCurrencyModal = false"
/>
+ <!-- Currency Filter Modal -->
<CurrenciesModal
v-if="walletsStore.currenciesUsed.length > 1 && isShowCurrencyFilter"
:activeCode="currencyFiltered"
@@ -738,13 +777,11 @@ const counts = computed(() => ({
<i18n lang="yaml">
en:
currencies: Currencies
- filterByCurrency: Filter by
- list: List
+ none: List
type: Type
ru:
currencies: Валюты
- filterByCurrency: Валюты кошельков
- list: Список
+ none: Список
type: Тип
</i18n>
diff --git a/app/components/wallets/page/id/Index.vue b/app/components/wallets/page/id/Index.vue
index dfeb5c62..857a71f5 100644
--- a/app/components/wallets/page/id/Index.vue
+++ b/app/components/wallets/page/id/Index.vue
@@ -40,6 +40,9 @@ const maxRange = computed(() => trnsStore.getRange(trnsIds.value))
const statConfig = useStatConfig({
props: {
isShowEmptyCategories: true,
+ wallets: {
+ isShow: false,
+ },
},
storageKey: storageKey.value,
})
diff --git a/app/components/wallets/types.ts b/app/components/wallets/types.ts
index 123e0953..5e3776d4 100644
--- a/app/components/wallets/types.ts
+++ b/app/components/wallets/types.ts
@@ -12,20 +12,17 @@ export const types = [
] as const
export const viewTypes = [
- 'available',
...types,
- 'creditPossible',
- 'withdrawal',
- 'archived',
+ 'isAvailable',
+ 'isWithdrawal',
+ 'isArchived',
+ 'isExcludeInTotal',
] as const
export type WalletId = string
export type WalletType = typeof types[number]
export type WalletViewTypes = typeof viewTypes[number]
-export type WalletViewTypesObj = {
- [K in WalletViewTypes]: boolean
-}
export const icons: Record<WalletType, string> = {
cash: 'lucide:banknote',
@@ -87,3 +84,6 @@ export type WalletItemComputed = WalletItem & {
}
export type WalletsComputed = Record<WalletId, WalletItemComputed>
+
+export type WalletsGroupedBy = 'type' | 'currency' | 'none'
+export type WalletsCurrencyFiltered = 'all' | CurrencyCode
diff --git a/app/pages/dev.vue b/app/pages/dev.vue
index 93d10535..09854331 100644
--- a/app/pages/dev.vue
+++ b/app/pages/dev.vue
@@ -180,9 +180,9 @@
UiToggle
</UiToggle>
- <UiToggle2>
- UiToggle2
- </UiToggle2>
+ <UiToggleWithStorage>
+ UiToggleWithStorage
+ </UiToggleWithStorage>
<UiToggle3 isShown>
UiToggle3
diff --git a/eslint.config.js b/eslint.config.js
index 60b409ef..555fa450 100644
--- a/eslint.config.js
+++ b/eslint.config.js
@@ -16,7 +16,6 @@ export default [
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
'import/order': 'off',
'no-console': 'off',
- 'no-extra-semi': 'error',
'perfectionist/sort-array-includes': ['error', { order: 'asc', type: 'natural' }],
'perfectionist/sort-enums': ['error', { order: 'asc', type: 'natural' }],
'perfectionist/sort-exports': ['error', { order: 'asc', type: 'natural' }],
diff --git a/i18n/locales/en-US.js b/i18n/locales/en-US.js
index fdc882ae..f2318b0b 100644
--- a/i18n/locales/en-US.js
+++ b/i18n/locales/en-US.js
@@ -209,8 +209,7 @@ export default {
transfer: 'Transfer',
type: 'Wallet type',
types: {
- all: 'All',
- archived: 'Archived',
+ all: 'Total',
available: 'Available',
cash: 'Cash',
cashless: 'Cashless',
@@ -219,7 +218,10 @@ export default {
crypto: 'Crypto',
debt: 'Debt',
deposit: 'Deposit',
- withdrawal: 'Withdrawal',
+ isArchived: 'Archived',
+ isAvailable: 'Available with credits',
+ isExcludeInTotal: 'Not included in total',
+ isWithdrawal: 'Withdrawal',
},
wallets: 'Wallets',
},
diff --git a/i18n/locales/ru-RU.js b/i18n/locales/ru-RU.js
index 00b487ed..37caef30 100644
--- a/i18n/locales/ru-RU.js
+++ b/i18n/locales/ru-RU.js
@@ -208,8 +208,7 @@ export default {
transfer: 'Перевод',
type: 'Тип кошельки',
types: {
- all: 'Все',
- archived: 'Архивные',
+ all: 'Общий',
available: 'Доступные для снятия',
cash: 'Наличные',
cashless: 'Безнал',
@@ -218,7 +217,10 @@ export default {
crypto: 'Крипта',
debt: 'Долги',
deposit: 'Вклады',
- withdrawal: 'Доступные для снятия',
+ isArchived: 'Архивные',
+ isAvailable: 'Доступные с учетом кредитов',
+ isExcludeInTotal: 'Не учитываемые в общем балансе',
+ isWithdrawal: 'Доступные для снятия',
},
wallets: 'Кошельки',
},
diff --git a/package.json b/package.json
index 80571896..ab98123e 100644
--- a/package.json
+++ b/package.json
@@ -1,8 +1,8 @@
{
"name": "@ilkome/finapp",
"type": "module",
- "version": "6.0.3",
- "packageManager": "[email protected]",
+ "version": "6.1.0",
+ "packageManager": "[email protected]",
"description": "Finapp helps you to control personal finances easily and efficiently.",
"author": "Ilya Komichev @ilkome",
"license": "MIT",