Open source personal finance application
feat: add options to show archived wallets and include them in statistics
Ilya Komichev34b671dc9741
diff --git a/app/components/wallets/Statistics.vue b/app/components/wallets/Statistics.vueindex 71cd7216..0a4ab929 100644--- a/app/components/wallets/Statistics.vue+++ b/app/components/wallets/Statistics.vue@@ -38,11 +38,9 @@ const itemsGrouped = computed(() => [class="bg-item-2 mb-2 rounded-xl md:max-w-lg"><template #header="{ toggle, isShown }">- <div class="flex grow items-center justify-between">- <UiTitleCollapse :isShown @click="toggle">- {{ t('statistics.title') }}- </UiTitleCollapse>- </div>+ <UiTitleCollapse :isShown @click="toggle">+ {{ t('statistics.title') }}+ </UiTitleCollapse></template><div class="grid gap-6">diff --git a/app/components/wallets/constants.ts b/app/components/wallets/constants.tsindex b17f913e..afc08cc6 100644--- a/app/components/wallets/constants.ts+++ b/app/components/wallets/constants.ts@@ -6,5 +6,7 @@ export const WALLET_STORAGE_KEYS = {groupedBySecondary: 'finapp-wallets-groupedBySecondary',selectorCurrency: 'finapp-wallets-selector-currency',toggleMap: 'finapp-wallets-toggle-map',+ showArchived: 'finapp-wallets-show-archived',+ includeArchivedInStats: 'finapp-wallets-include-archived-in-stats',totalPrefix: 'finapp-wallets-total-',} as constdiff --git a/app/components/wallets/counts.ts b/app/components/wallets/counts.tsindex 7fa45672..c2e9422d 100644--- a/app/components/wallets/counts.ts+++ b/app/components/wallets/counts.ts@@ -12,12 +12,13 @@ type CountItem = {export function computeWalletCounts(params: {baseCurrency?: CurrencyCode+ includeArchivedInStats?: booleanrates?: RatestotalWalletsCount: numberwalletIds: WalletId[]wallets: Record<WalletId, WalletItemComputed>}): Record<string, CountItem> {- const { baseCurrency, rates, totalWalletsCount, walletIds, wallets } = params+ const { baseCurrency, includeArchivedInStats = false, rates, totalWalletsCount, walletIds, wallets } = paramsfunction convert(amount: number, currencyCode: CurrencyCode): number {return getAmountInRate({ amount, baseCurrencyCode: baseCurrency, currencyCode, rates })@@ -49,7 +50,8 @@ export function computeWalletCounts(params: {if (wallet.isArchived) {sum.archived += amounthasArchivedWallet = true- continue+ if (!includeArchivedInStats)+ continue}if (wallet.isExcludeInTotal)diff --git a/app/components/wallets/filters.ts b/app/components/wallets/filters.tsindex d34df6b7..cf033b15 100644--- a/app/components/wallets/filters.ts+++ b/app/components/wallets/filters.ts@@ -15,19 +15,24 @@ export function filterWalletsByViewType(walletIds: WalletId[],wallets: Record<WalletId, WalletItemComputed>,viewType: WalletViewTypes | 'total',+ showArchived = false,): WalletId[] {return walletIds.filter((id) => {const wallet = wallets[id]if (!wallet)return false+ if (viewType === 'isArchived')+ return wallet.isArchived++ const archivedFilter = showArchived || !wallet.isArchived+switch (viewType) {- case 'isWithdrawal': return wallet.isWithdrawal && !wallet.isArchived- case 'isExcludeInTotal': return wallet.isExcludeInTotal && !wallet.isArchived- case 'isArchived': return wallet.isArchived- case 'isAvailable': return (wallet.type === 'credit' || wallet.isWithdrawal) && !wallet.isArchived- case 'total': return !wallet.isArchived- default: return wallet.type === viewType && !wallet.isArchived+ case 'isWithdrawal': return wallet.isWithdrawal && archivedFilter+ case 'isExcludeInTotal': return wallet.isExcludeInTotal && archivedFilter+ case 'isAvailable': return (wallet.type === 'credit' || wallet.isWithdrawal) && archivedFilter+ case 'total': return archivedFilter+ default: return wallet.type === viewType && archivedFilter}})}diff --git a/app/components/wallets/page/List.vue b/app/components/wallets/page/List.vueindex de7fcba2..6c4a5f28 100644--- a/app/components/wallets/page/List.vue+++ b/app/components/wallets/page/List.vue@@ -32,6 +32,8 @@ const {} = useWalletDelete()const groupedBy = useStorage<WalletsGroupedBy>(WALLET_STORAGE_KEYS.groupedBy, 'none')+const showArchived = useStorage<boolean>(WALLET_STORAGE_KEYS.showArchived, false)+const includeArchivedInStats = useStorage<boolean>(WALLET_STORAGE_KEYS.includeArchivedInStats, false)const {currencyFiltered,@@ -39,12 +41,12 @@ const {selectedWalletsIdsWithCurrency,setWalletViewType,walletViewType,-} = useWalletsFilter(groupedBy)+} = useWalletsFilter(groupedBy, showArchived)const {counts,countWalletsSum,-} = useWalletsCounts(selectedWalletsIdsWithCurrency)+} = useWalletsCounts(selectedWalletsIdsWithCurrency, includeArchivedInStats)const {groupedWalletsWithIds,@@ -96,6 +98,19 @@ function hasGroups(groups: Record<string, unknown> | undefined) {>{{ t('wallets.sortTitle') }}</UiHeaderLink>++ <div class="pt-2">+ <UiSwitchItem+ :checkboxValue="showArchived"+ :title="t('wallets.options.showArchived')"+ @click="showArchived = !showArchived"+ />+ <UiSwitchItem+ :checkboxValue="includeArchivedInStats"+ :title="t('wallets.options.includeArchivedInStats')"+ @click="includeArchivedInStats = !includeArchivedInStats"+ />+ </div></div></template></BottomSheetOrDropdown>@@ -262,7 +277,7 @@ function hasGroups(groups: Record<string, unknown> | undefined) {<divv-if="hasGroups(content.groups)"- class="grid gap-2"+ class="grid gap-2 pl-6"><UiToggleControlledv-for="(ids, groupSecondary) in content.groups"@@ -306,14 +321,14 @@ function hasGroups(groups: Record<string, unknown> | undefined) {</UiToggleControlled></div>- <template v-else>+ <div v-else><WalletsPageListItemv-for="walletId in content.ids":key="walletId":walletId@delete="requestDelete"/>- </template>+ </div></UiToggleControlled></div></div>diff --git a/app/components/wallets/useWalletsCounts.ts b/app/components/wallets/useWalletsCounts.tsindex 7edb9d25..f47c88fe 100644--- a/app/components/wallets/useWalletsCounts.ts+++ b/app/components/wallets/useWalletsCounts.ts@@ -1,4 +1,4 @@-import type { ComputedRef } from 'vue'+import type { ComputedRef, Ref } from 'vue'import type { WalletId } from '~/components/wallets/types'@@ -8,12 +8,14 @@ import { useWalletsStore } from '~/components/wallets/useWalletsStore'export function useWalletsCounts(selectedWalletsIdsWithCurrency: ComputedRef<WalletId[]>,+ includeArchivedInStats: Ref<boolean>,) {const walletsStore = useWalletsStore()const currenciesStore = useCurrenciesStore()const counts = computed(() => computeWalletCounts({baseCurrency: currenciesStore.base,+ includeArchivedInStats: includeArchivedInStats.value,rates: currenciesStore.rates,totalWalletsCount: Object.values(walletsStore.itemsComputed).filter(w => !w.isArchived).length,walletIds: selectedWalletsIdsWithCurrency.value,diff --git a/app/components/wallets/useWalletsFilter.ts b/app/components/wallets/useWalletsFilter.tsindex b91ada04..1120a0eb 100644--- a/app/components/wallets/useWalletsFilter.ts+++ b/app/components/wallets/useWalletsFilter.ts@@ -8,7 +8,7 @@ import { WALLET_STORAGE_KEYS } from '~/components/wallets/constants'import { filterWalletsByCurrency, filterWalletsByViewType } from '~/components/wallets/filters'import { useWalletsStore } from '~/components/wallets/useWalletsStore'-export function useWalletsFilter(groupedBy: Ref<WalletsGroupedBy>) {+export function useWalletsFilter(groupedBy: Ref<WalletsGroupedBy>, showArchived: Ref<boolean>) {const walletsStore = useWalletsStore()const currencyFiltered = useStorage<WalletsCurrencyFiltered>(WALLET_STORAGE_KEYS.activeCurrency, 'all')@@ -23,12 +23,12 @@ export function useWalletsFilter(groupedBy: Ref<WalletsGroupedBy>) {)const selectedWalletsIds = computed<WalletId[]>(() =>- filterWalletsByViewType(selectedWalletsIdsWithCurrency.value, walletsStore.itemsComputed, walletViewType.value),+ filterWalletsByViewType(selectedWalletsIdsWithCurrency.value, walletsStore.itemsComputed, walletViewType.value, showArchived.value),)watch(selectedWalletsIds, (ids) => {if (ids.length === 0 && walletViewType.value !== 'total') {- const totalIds = filterWalletsByViewType(selectedWalletsIdsWithCurrency.value, walletsStore.itemsComputed, 'total')+ const totalIds = filterWalletsByViewType(selectedWalletsIdsWithCurrency.value, walletsStore.itemsComputed, 'total', showArchived.value)if (totalIds.length > 0)walletViewType.value = 'total'}diff --git a/i18n/locales/en-US.js b/i18n/locales/en-US.jsindex 7ca59dfe..c7d59ae1 100644--- a/i18n/locales/en-US.js+++ b/i18n/locales/en-US.js@@ -456,6 +456,10 @@ export default {},name: 'Wallets',new: 'New wallet',+ options: {+ includeArchivedInStats: 'Include archived in statistics',+ showArchived: 'Show archived wallets',+ },page: {currencies: 'Currencies',none: 'List',diff --git a/i18n/locales/ru-RU.js b/i18n/locales/ru-RU.jsindex b8bc55a9..920bd55c 100644--- a/i18n/locales/ru-RU.js+++ b/i18n/locales/ru-RU.js@@ -232,7 +232,7 @@ export default {},type: 'Тип кошельки',types: {- available: 'Доступные для снятия',+ available: 'Доступные',cash: 'Наличные',cashless: 'Безнал',credit: 'Кредит',@@ -456,6 +456,10 @@ export default {},name: 'Кошельки',new: 'Новый кошелек',+ options: {+ includeArchivedInStats: 'Учитывать архивные в статистике',+ showArchived: 'Показывать архивные кошельки',+ },page: {currencies: 'Валюты',none: 'Список',