Open source personal finance application
feat(wallets): add search header, edit modal and delete in selector
Ilya Komichev5f8ad614c925
diff --git a/app/app/components/trnForm/SelectorWallet.vue b/app/app/components/trnForm/SelectorWallet.vueindex d1842b93..1064aaff 100644--- a/app/app/components/trnForm/SelectorWallet.vue+++ b/app/app/components/trnForm/SelectorWallet.vue@@ -50,7 +50,8 @@ const isLaptop = computed(() => width.value >= 766 && pointerType.value === 'mou:activeItemId="props.walletId":disabledIds="props.disabledWalletIds":filterAtTop="isLaptop"- class="min-w-80 px-3"+ withHeader+ class="min-w-80 px-2"@selected="(id: WalletId) => emit('selected', id)"/></template>diff --git a/app/app/components/wallets/EditModal.vue b/app/app/components/wallets/EditModal.vuenew file mode 100644index 00000000..db139224--- /dev/null+++ b/app/app/components/wallets/EditModal.vue@@ -0,0 +1,47 @@+<script setup lang="ts">+import type { WalletId, WalletItem } from '~/components/wallets/types'++import { walletItemSchema } from '~/components/wallets/types'+import { useWalletsStore } from '~/components/wallets/useWalletsStore'++const props = defineProps<{+ walletId?: WalletId+}>()++const emit = defineEmits<{+ closed: []+}>()++const { t } = useI18n()+const walletsStore = useWalletsStore()++const wallet = computed(() =>+ props.walletId ? walletsStore.items[props.walletId] : undefined,+)+const walletForm = ref(+ wallet.value+ ? walletItemSchema.parse(wallet.value)+ : walletItemSchema.parse({ type: 'cash' }),+)++function updateField(key: keyof WalletItem, value: WalletItem[keyof WalletItem]) {+ (walletForm.value as Record<string, unknown>)[key] = value+}+</script>++<template>+ <BottomSheetModal @closed="emit('closed')">+ <template #default="{ close }">+ <UiTitleModal>+ {{ wallet?.name || t('wallets.createNewTitle') }}+ </UiTitleModal>++ <WalletsForm+ :walletId="props.walletId"+ :walletForm+ @update="updateField"+ @afterSave="close"+ />+ </template>+ </BottomSheetModal>+</template>diff --git a/app/app/components/wallets/Selector.vue b/app/app/components/wallets/Selector.vueindex e9120c27..dc55bea6 100644--- a/app/app/components/wallets/Selector.vue+++ b/app/app/components/wallets/Selector.vue@@ -5,6 +5,8 @@ import type { CurrencyCode } from '~/components/currencies/types'import type { WalletId } from '~/components/wallets/types'import { WALLET_STORAGE_KEYS } from '~/components/wallets/constants'+import { useWalletContextMenu } from '~/components/wallets/useWalletContextMenu'+import { useWalletDelete } from '~/components/wallets/useWalletDelete'import { useWalletsStore } from '~/components/wallets/useWalletsStore'const props = defineProps<{@@ -13,74 +15,188 @@ const props = defineProps<{filterAtTop?: booleanhide?: () => voidselectedIds?: WalletId[]+ withHeader?: boolean}>()const emit = defineEmits<{selected: [id: WalletId]}>()+const { t } = useI18n()+const router = useRouter()const walletsStore = useWalletsStore()+const { width } = useWindowSize()+const { pointerType } = usePointer()+const isLaptop = computed(() => width.value >= 766 && pointerType.value === 'mouse')++const search = ref('')+const searchInput = useTemplateRef<HTMLInputElement>('searchInput')+const searchQuery = computed(() => search.value.trim().toLowerCase())++const editingWalletId = ref<WalletId | null>(null)+const isCreatingNewWallet = ref(false)++const {+ cancelDelete,+ confirmDelete,+ deleteInfo,+ deleteWalletId,+ requestDelete,+} = useWalletDelete()+const currencyFiltered = useStorage<CurrencyCode>(WALLET_STORAGE_KEYS.selectorCurrency, 'all')const selectedWalletsIdsWithCurrency = computed<WalletId[]>(() => {+ const q = searchQuery.valuereturn Object.keys(walletsStore.itemsComputed).filter((id) => {const wallet = walletsStore.itemsComputed[id]- return !wallet?.isArchived- && !props.disabledIds?.includes(id)- && (currencyFiltered.value === 'all' || currencyFiltered.value === wallet?.currency)+ if (!wallet || wallet.isArchived || props.disabledIds?.includes(id))+ return false+ if (currencyFiltered.value !== 'all' && currencyFiltered.value !== wallet.currency)+ return false+ if (q && !wallet.name.toLowerCase().includes(q))+ return false+ return true})})+const hasNoMatches = computed(() =>+ !!searchQuery.value && selectedWalletsIdsWithCurrency.value.length === 0,+)++const { getWalletContextMenuItems: getLaptopMenuItems } = useWalletContextMenu({+ excludeOpen: true,+ onDelete: requestDelete,+ returnBackOnSave: true,+})++const { getWalletContextMenuItems: getMobileMenuItems } = useWalletContextMenu({+ excludeOpen: true,+ onDelete: requestDelete,+ onEdit: (id) => {+ editingWalletId.value = id+ },+})++function getWalletContextMenuItems(walletId: WalletId) {+ if (!props.withHeader)+ return undefined+ return isLaptop.value+ ? getLaptopMenuItems(walletId)+ : getMobileMenuItems(walletId)+}+function onClickWallet(walletId: WalletId) {emit('selected', walletId)if (props.hide)props.hide()}++function onClickNew() {+ if (isLaptop.value) {+ router.push('/wallets/new?returnBack=1')+ props.hide?.()+ }+ else {+ isCreatingNewWallet.value = true+ }+}++onMounted(async () => {+ if (!props.withHeader)+ return+ await nextTick()+ searchInput.value?.focus()+})</script><template>- <div class="relative grid h-full overflow-hidden">+ <div class="flex h-full min-h-0 flex-col overflow-hidden"><div- class="scrollerBlock h-full overflow-y-auto py-px"- :class="{- 'pb-16': !props.filterAtTop && walletsStore.currenciesUsed.length > 1,- 'pt-12': props.filterAtTop && walletsStore.currenciesUsed.length > 1,- }"+ v-if="props.withHeader"+ class="bg-default flex items-center gap-2 pt-2 pb-2">- <WalletsItem- v-for="walletId in selectedWalletsIdsWithCurrency"- :key="walletId"- :activeItemId="props.activeItemId || (props.selectedIds?.includes(walletId) ? walletId : null)"- :walletId- :wallet="walletsStore.itemsComputed[walletId]!"- :lineWidth="4"- class="group/item"- isShowIcon- isShowCreditLimit- @click="onClickWallet(walletId)"- />+ <input+ ref="searchInput"+ v-model="search"+ type="text"+ class="bg-elevated/30 placeholder:text-muted hover:bg-elevated/50 focus:bg-elevated/50 focus:border-primary m-0 min-h-[42px] flex-1 rounded-md border border-transparent px-4 py-2 text-base font-normal outline-none"+ :placeholder="t('wallets.search.placeholder')"+ >+ <UiActionButton+ :ariaLabel="t('wallets.new')"+ @click="onClickNew"+ >+ <Icon name="lucide:plus" size="20" />+ </UiActionButton></div>- <template v-if="walletsStore.currenciesUsed.length > 1">- <div- class="pointer-events-none absolute left-0 z-10 h-12 w-full"- :class="props.filterAtTop ? 'top-0' : 'bottom-0'"- :style="props.filterAtTop- ? 'background: linear-gradient(to top, transparent, var(--ui-bg))'- : 'background: linear-gradient(to bottom, transparent, var(--ui-bg))'"- />+ <div class="relative grid min-h-0 flex-1 overflow-hidden"><div- class="pointer-events-none absolute left-0 z-20 w-full px-2"- :class="props.filterAtTop ? 'top-0' : 'bottom-2'"+ class="scrollerBlock h-full overflow-y-auto py-px"+ :class="{+ 'pb-16': !props.filterAtTop && walletsStore.currenciesUsed.length > 1,+ 'pt-12': props.filterAtTop && walletsStore.currenciesUsed.length > 1,+ }">- <div class="border-default/80 bg-default/20 pointer-events-auto rounded-2xl border p-1 shadow-lg backdrop-blur-xl dark:bg-neutral-800/50">- <WalletsCurrencies- :currencyFiltered- @selectFilterCurrency="code => currencyFiltered = code"- />+ <div+ v-if="hasNoMatches"+ class="text-muted p-4 text-center"+ >+ {{ t('search.noResults') }}</div>++ <WalletsItem+ v-for="walletId in selectedWalletsIdsWithCurrency"+ :key="walletId"+ :activeItemId="props.activeItemId || (props.selectedIds?.includes(walletId) ? walletId : null)"+ :contextMenuItems="getWalletContextMenuItems(walletId)"+ :walletId+ :wallet="walletsStore.itemsComputed[walletId]!"+ :lineWidth="4"+ class="group/item"+ isShowIcon+ isShowCreditLimit+ @click="onClickWallet(walletId)"+ /></div>- </template>++ <template v-if="walletsStore.currenciesUsed.length > 1">+ <div+ class="pointer-events-none absolute left-0 z-10 h-12 w-full"+ :class="props.filterAtTop ? 'top-0' : 'bottom-0'"+ :style="props.filterAtTop+ ? 'background: linear-gradient(to top, transparent, var(--ui-bg))'+ : 'background: linear-gradient(to bottom, transparent, var(--ui-bg))'"+ />+ <div+ class="pointer-events-none absolute left-0 z-20 w-full px-2"+ :class="props.filterAtTop ? 'top-0' : 'bottom-2'"+ >+ <div class="border-default/80 bg-default/20 pointer-events-auto rounded-2xl border p-1 shadow-lg backdrop-blur-xl dark:bg-neutral-800/50">+ <WalletsCurrencies+ :currencyFiltered+ @selectFilterCurrency="code => currencyFiltered = code"+ />+ </div>+ </div>+ </template>+ </div>++ <WalletsEditModal+ v-if="props.withHeader && (editingWalletId || isCreatingNewWallet) && !isLaptop"+ :walletId="editingWalletId ?? undefined"+ @closed="editingWalletId = null; isCreatingNewWallet = false"+ />++ <LayoutConfirmModal+ v-if="deleteWalletId"+ :title="t('wallets.form.delete.title')"+ :description="deleteInfo.descText"+ :highlight="deleteInfo.highlight"+ @closed="cancelDelete"+ @confirm="confirmDelete"+ /></div></template>diff --git a/app/app/components/wallets/page/New.vue b/app/app/components/wallets/page/New.vueindex 160bc8e4..fc3d4ba9 100644--- a/app/app/components/wallets/page/New.vue+++ b/app/app/components/wallets/page/New.vue@@ -2,6 +2,7 @@import type { WalletItem } from '~/components/wallets/types'import { walletItemSchema } from '~/components/wallets/types'+import { canGoBack } from '~/composables/useNavigationHistory'const { t } = useI18n()const route = useRoute()@@ -14,6 +15,14 @@ function updateField(key: keyof WalletItem, value: WalletItem[keyof WalletItem])(walletForm.value as Record<string, unknown>)[key] = value}+function onAfterSave() {+ if (route.query.returnBack === '1' && canGoBack.value) {+ router.back()+ return+ }+ router.replace('/dashboard')+}+useHead({title: `${t('base.add')}: ${walletForm.value.name ? walletForm.value.name : t('wallets.form.name.label')}`,})@@ -40,7 +49,7 @@ useHead({<WalletsForm:walletForm="walletForm"- @afterSave="() => router.replace('/dashboard')"+ @afterSave="onAfterSave"@update="updateField"/></UiPage>diff --git a/app/app/components/wallets/page/id/Edit.vue b/app/app/components/wallets/page/id/Edit.vueindex 48275ca7..79f00506 100644--- a/app/app/components/wallets/page/id/Edit.vue+++ b/app/app/components/wallets/page/id/Edit.vue@@ -3,7 +3,7 @@ import type { WalletId, WalletItem } from '~/components/wallets/types'import { walletItemSchema } from '~/components/wallets/types'import { useWalletsStore } from '~/components/wallets/useWalletsStore'-import { navigateAfterSave } from '~/composables/useNavigationHistory'+import { canGoBack, navigateAfterSave } from '~/composables/useNavigationHistory'const { t } = useI18n()const route = useRoute()@@ -24,6 +24,13 @@ function updateField(key: keyof WalletItem, value: WalletItem[keyof WalletItem])(walletForm.value as Record<string, unknown>)[key] = value}+function onAfterSave() {+ if (route.query.returnBack === '1' && canGoBack.value)+ router.back()+ else+ navigateAfterSave(router, `/wallets/${walletId.value}`)+}+useHead({ title: `${t('base.edit')}: ${walletForm.value?.name || t('wallets.form.name.label')}` })</script>@@ -42,7 +49,7 @@ useHead({ title: `${t('base.edit')}: ${walletForm.value?.name || t('wallets.form<WalletsForm:walletId:walletForm- @afterSave="() => navigateAfterSave(router, `/wallets/${walletId}`)"+ @afterSave="onAfterSave"@update="updateField"/></UiPage>diff --git a/app/app/components/wallets/useWalletContextMenu.ts b/app/app/components/wallets/useWalletContextMenu.tsindex 5ff4572d..398ca5da 100644--- a/app/app/components/wallets/useWalletContextMenu.ts+++ b/app/app/components/wallets/useWalletContextMenu.ts@@ -1,27 +1,48 @@import type { WalletId } from '~/components/wallets/types'export function useWalletContextMenu(options?: {+ excludeOpen?: booleanonDelete?: (walletId: WalletId) => void+ onEdit?: (walletId: WalletId) => void+ returnBackOnSave?: boolean}) {const { t } = useI18n()const router = useRouter()function getWalletContextMenuItems(walletId: WalletId) {- const editGroup = [{- icon: 'lucide:pencil',- label: t('base.edit'),- onSelect: () => router.push(`/wallets/${walletId}/edit`),- }]+ const editPath = options?.returnBackOnSave+ ? `/wallets/${walletId}/edit?returnBack=1`+ : `/wallets/${walletId}/edit`- if (!options?.onDelete)- return [editGroup]+ const editGroup = [+ ...(!options?.excludeOpen+ ? [{+ icon: 'lucide:square-arrow-out-up-right',+ label: t('base.open'),+ onSelect: () => router.push(`/wallets/${walletId}`),+ }]+ : []),+ {+ icon: 'lucide:pencil',+ label: t('base.edit'),+ onSelect: () => options?.onEdit+ ? options.onEdit(walletId)+ : router.push(editPath),+ },+ ]- return [editGroup, [{- color: 'error' as const,- icon: 'lucide:trash-2',- label: t('base.delete'),- onSelect: () => options.onDelete!(walletId),- }]]+ const groups: any[][] = [editGroup]++ if (options?.onDelete) {+ groups.push([{+ color: 'error' as const,+ icon: 'lucide:trash-2',+ label: t('base.delete'),+ onSelect: () => options.onDelete!(walletId),+ }])+ }++ return groups}return { getWalletContextMenuItems }diff --git a/app/i18n/locales/en-US.js b/app/i18n/locales/en-US.jsindex 5f204434..96a314c1 100644--- a/app/i18n/locales/en-US.js+++ b/app/i18n/locales/en-US.js@@ -511,6 +511,9 @@ export default {none: 'List',type: 'Type',},+ search: {+ placeholder: 'Search',+ },showAll: 'Show all',showOnly: 'Show only',sortTitle: 'Sort wallets',diff --git a/app/i18n/locales/ru-RU.js b/app/i18n/locales/ru-RU.jsindex 37e10a4c..3bfeb07d 100644--- a/app/i18n/locales/ru-RU.js+++ b/app/i18n/locales/ru-RU.js@@ -511,6 +511,9 @@ export default {none: 'Список',type: 'Тип',},+ search: {+ placeholder: 'Поиск',+ },showAll: 'Показать все',showOnly: 'Показать только',sortTitle: 'Сортировать кошельки',