Open source personal finance application
refactor: extract components, eliminate duplication, cache computations
Ilya Komichevc8e154427f6c
diff --git a/app/assets/css/utility.css b/app/assets/css/utility.cssindex 5b79e25f..9f562e1a 100644--- a/app/assets/css/utility.css+++ b/app/assets/css/utility.css@@ -10,7 +10,7 @@@apply @xl/page:max-w-2xl grow px-3 @md/page:px-4;}-@utility bottomSheetDrugClassesCustom {+@utility bottomSheetDragClassesCustom {@apply bg-default max-w-md rounded-xl;}diff --git a/app/components/bottomSheet/BottomSheet.vue b/app/components/bottomSheet/BottomSheet.vueindex 75b0ff33..90aaf440 100644--- a/app/components/bottomSheet/BottomSheet.vue+++ b/app/components/bottomSheet/BottomSheet.vue@@ -2,8 +2,8 @@import { useBottomSheetDrag } from './useBottomSheetDrag'const props = defineProps<{- drugClassesCustom?: string- drugStyle?: Record<string, string>+ dragClassesCustom?: string+ dragStyle?: Record<string, string>isShow?: boolean}>()@@ -14,20 +14,20 @@ const emit = defineEmits<{// Settingsconst settings = {pixelOffsetToStartClosing: 20,- pixelsNeedToDrugForClose: 60,+ pixelsNeedToDragForClose: 60,}// Ref Elements-const drug = ref<HTMLElement | null>(null)+const drag = ref<HTMLElement | null>(null)const containerRef = ref<HTMLElement | null>(null)const handlerRef = ref<HTMLElement | null>(null)-const { height: drugHeight } = useElementSize(drug)+const { height: dragHeight } = useElementSize(drag)const { height: windowHeight } = useWindowSize()const {close,- drugStyles,+ dragStyles,init,isDragging,opened,@@ -37,8 +37,8 @@ const {wrapClasses,} = useBottomSheetDrag({containerRef,- drug,- drugStyle: toRef(() => props.drugStyle),+ drag,+ dragStyle: toRef(() => props.dragStyle),emit,handlerRef,settings,@@ -54,10 +54,10 @@ const isBodyLocked = import.meta.client ? useScrollLock(document.body) : ref(fal*/watch(() => props.isShow,- async (value) => {+ (value) => {if (value) {isBodyLocked.value = true- await init()+ init()}if (!value) {@@ -77,17 +77,14 @@ onBeforeUnmount(() => {removeEvents()})-/**- * Height- */-const drugClasses = computed(() => [+const dragClasses = computed(() => [{- 'pointer-events-none': isDragging.value && drugStyles.value.transform,- 'rounded-tl-xl rounded-tr-xl': drugHeight.value < windowHeight.value,+ 'pointer-events-none': isDragging.value && dragStyles.value.transform,+ 'rounded-tl-xl rounded-tr-xl': dragHeight.value < windowHeight.value,'transition-opacity transition-transform duration-100':!isDragging.value && opened.value,},- props.drugClassesCustom,+ props.dragClassesCustom,])</script>@@ -105,12 +102,12 @@ const drugClasses = computed(() => [@click="close()"/>- <!-- Drug -->+ <!-- Drag --><div- ref="drug"- :class="drugClasses"- :style="drugStyles"- class="drug pointer-events-auto absolute bottom-0 left-1/2 z-10 w-full -translate-x-1/2 translate-y-0 overflow-hidden"+ ref="drag"+ :class="dragClasses"+ :style="dragStyles"+ class="drag pointer-events-auto absolute bottom-0 left-1/2 z-10 w-full -translate-x-1/2 translate-y-0 overflow-hidden"@click.stop=""><div ref="handlerRef">diff --git a/app/components/bottomSheet/BottomSheetModal.vue b/app/components/bottomSheet/BottomSheetModal.vuenew file mode 100644index 00000000..26320c13--- /dev/null+++ b/app/components/bottomSheet/BottomSheetModal.vue@@ -0,0 +1,26 @@+<script setup lang="ts">+defineEmits<{+ closed: []+}>()+</script>++<template>+ <Teleport to="body">+ <BottomSheet+ isShow+ dragClassesCustom="bottomSheetDragClassesCustom"+ @closed="$emit('closed')"+ >+ <template #handler="{ close }">+ <BottomSheetHandler />+ <BottomSheetClose @click="close" />+ </template>++ <template #default="{ close }">+ <div class="bottomSheetContent">+ <slot :close="close" />+ </div>+ </template>+ </BottomSheet>+ </Teleport>+</template>diff --git a/app/components/bottomSheet/BottomSheetOrDropdown.vue b/app/components/bottomSheet/BottomSheetOrDropdown.vueindex b30cfa91..af344478 100644--- a/app/components/bottomSheet/BottomSheetOrDropdown.vue+++ b/app/components/bottomSheet/BottomSheetOrDropdown.vue@@ -1,7 +1,7 @@<script setup lang="ts">const props = defineProps<{bottomSheetStyle?: Record<string, string>- drugClassesCustom?: string+ dragClassesCustom?: stringisOpen?: booleanisShowCloseBtn?: booleantitle?: string@@ -64,8 +64,8 @@ const open = ref(false)<BottomSheetv-if="props.isOpen"isShow- :drugClassesCustom="`${props.drugClassesCustom ?? ''} bottomSheetDrugClassesCustom`"- :drugStyle="props.bottomSheetStyle"+ :dragClassesCustom="`${props.dragClassesCustom ?? ''} bottomSheetDragClassesCustom`"+ :dragStyle="props.bottomSheetStyle"@closed="emit('closeModal')"><template #default="{ close }">diff --git a/app/components/bottomSheet/useBottomSheetDrag.ts b/app/components/bottomSheet/useBottomSheetDrag.tsindex 8e2fc2d0..25046b78 100644--- a/app/components/bottomSheet/useBottomSheetDrag.ts+++ b/app/components/bottomSheet/useBottomSheetDrag.ts@@ -3,165 +3,147 @@ import type { Ref } from 'vue'type Event = TouchEvent | MouseEventconst PERCENT_BASE = 100-const EDGE_PADDING = 10const INIT_DELAY_MS = 10type UseBottomSheetDragParams = {containerRef: Ref<HTMLElement | null>- drug: Ref<HTMLElement | null>- drugStyle: Ref<Record<string, string> | undefined>+ drag: Ref<HTMLElement | null>+ dragStyle: Ref<Record<string, string> | undefined>emit: (event: 'closed') => voidhandlerRef: Ref<HTMLElement | null>settings: {pixelOffsetToStartClosing: number- pixelsNeedToDrugForClose: number+ pixelsNeedToDragForClose: number}}+function getClientY(event: Event): number {+ return 'touches' in event+ ? Math.round(event.touches[0].clientY)+ : event.clientY+}++function calcVisiblePercent(+ containerHeight: number,+ handlerHeight: number,+ dragDistance: number,+): number {+ if (containerHeight === 0)+ return 0+ return Math.round(+ (containerHeight + handlerHeight - dragDistance)+ / (containerHeight / PERCENT_BASE),+ )+}++function calcOverlayOpacity(visiblePercent: number): number {+ return Math.min(1, Math.max(0, visiblePercent / PERCENT_BASE))+}++function shouldClose(dragDistance: number, threshold: number, direction: 'down' | 'up'): boolean {+ return dragDistance >= threshold && direction === 'down'+}+export function useBottomSheetDrag({containerRef,- drug,- drugStyle,+ drag,+ dragStyle,emit,handlerRef,settings,}: UseBottomSheetDragParams) {- // State- const initialHeight = ref(0)const initialY = ref(0)const clientY = ref(0)+ // Must start as `true` so the visiblePercent watcher skips during init().+ // Without this, setInitialY() → visiblePercent=0 → watcher sets disabled=true,+ // undoing the disabled=false that init() sets right after.const isDragging = ref(true)const direction = ref<'down' | 'up'>('up')const isHandler = ref(false)const disabled = ref(true)const opened = ref(false)- const isEventsAdded = ref(false)- /**- * Next current y- */- const nextCurrentY = computed(() => clientY.value - initialY.value)+ const dragDistance = computed(() => clientY.value - initialY.value)- /**- * Set direction- */- watch(nextCurrentY, (current, prev) => {- direction.value = current > prev ? 'down' : 'up'- })-- /**- * Debounce drug- */- const debounce = computed(() =>+ const dragOffset = computed(() =>disabled.value || isHandler.value ? 0 : settings.pixelOffsetToStartClosing,)- /**- * Diff height- */- const diffHeight = computed(() => {- const containerHeight = drug.value?.clientHeight ?? 0- const handlerHeight = handlerRef.value?.clientHeight ?? 0- return Math.round(- (containerHeight + handlerHeight - nextCurrentY.value)- / (containerHeight / PERCENT_BASE),- )+ watch(dragDistance, (current, prev) => {+ direction.value = current > prev ? 'down' : 'up'})- /**- * Diff height with debounce- */- const diffHeightWithDebounce = computed(() => {- const containerHeight = drug.value?.clientHeight ?? 0- const handlerHeight = handlerRef.value?.clientHeight ?? 0- return Math.round(- (containerHeight + handlerHeight - nextCurrentY.value + debounce.value)- / (containerHeight / PERCENT_BASE),- )- })+ const visiblePercent = computed(() =>+ calcVisiblePercent(+ drag.value?.clientHeight ?? 0,+ handlerRef.value?.clientHeight ?? 0,+ dragDistance.value,+ ),+ )++ const visiblePercentWithOffset = computed(() =>+ calcVisiblePercent(+ drag.value?.clientHeight ?? 0,+ handlerRef.value?.clientHeight ?? 0,+ dragDistance.value - dragOffset.value,+ ),+ )- /**- * Overlay Opacity- */const overlayStyles = computed(() => {- if (nextCurrentY.value <= debounce.value)+ if (dragDistance.value <= dragOffset.value)returnlet opacity = 1- if (diffHeight.value < 0 || diffHeight.value > PERCENT_BASE) {- opacity = nextCurrentY.value <= PERCENT_BASE ? 1 : 0+ if (visiblePercent.value < 0 || visiblePercent.value > PERCENT_BASE) {+ opacity = dragDistance.value <= PERCENT_BASE ? 1 : 0}else {- opacity = Number(- diffHeightWithDebounce.value >= PERCENT_BASE- ? 1- : diffHeightWithDebounce.value >= EDGE_PADDING- ? `0.${diffHeightWithDebounce.value}`- : `0.0${diffHeightWithDebounce.value}`,- )- }- return {- opacity,+ opacity = visiblePercentWithOffset.value >= PERCENT_BASE+ ? 1+ : calcOverlayOpacity(visiblePercentWithOffset.value)}++ return { opacity }})- /**- * Drug styles- */- const drugStyles = computed(() => {+ const dragStyles = computed(() => {if (!opened.value) {return {- ...drugStyle.value,+ ...dragStyle.value,opacity: 0,transform: 'translateY(30px)',}}- if (nextCurrentY.value <= debounce.value) {+ if (dragDistance.value <= dragOffset.value) {return {- ...drugStyle.value,+ ...dragStyle.value,opacity: 1,transform: '',}}return {- ...drugStyle.value,- transform: `translateY(${nextCurrentY.value - debounce.value}px)`,+ ...dragStyle.value,+ transform: `translateY(${dragDistance.value - dragOffset.value}px)`,}})- /**- * Get client Y- */- function getClientY(event: Event): number {- return 'touches' in event- ? Math.round(event.touches[0].clientY)- : event.clientY- }+ function contentHasScroll(event: Event): boolean {+ const swiperSlide = drag.value?.querySelector('.swiper-slide-active')+ const scrollerInSlide = swiperSlide?.querySelector('.scrollerBlock')+ if (scrollerInSlide)+ return scrollerInSlide.scrollTop > 0 && event.type.includes('touch')- /**- * Content has scroll- */- function contentHasScroll(event: Event) {- // Handle scroll inside slider- const swiperSlideActive = drug.value?.querySelector('.swiper-slide-active')- if (swiperSlideActive) {- const scrollerBlock = swiperSlideActive.querySelector('.scrollerBlock')- if (scrollerBlock)- return scrollerBlock.scrollTop > 0 && event.type.includes('touch')- }+ const scroller = drag.value?.querySelector('.scrollerBlock')+ if (!swiperSlide && scroller)+ return scroller.scrollTop > 0 && event.type.includes('touch')- const scrollerBlock = drug.value?.querySelector('.scrollerBlock')- if (!swiperSlideActive && scrollerBlock)- return scrollerBlock.scrollTop > 0 && event.type.includes('touch')+ return false}- /**- * Drag start- */function onDragStart(event: Event): void {- if (event.target instanceof Element && event?.target?.closest('.sortHandle'))+ if (event.target instanceof Element && event.target.closest('.sortHandle'))returnif (disabled.value)@@ -169,10 +151,10 @@ export function useBottomSheetDrag({if (event.target instanceof Element) {isHandler.value = event.target.classList.contains('handler')- const isTarget = event.target.closest('.drug')- const isHasScroll = contentHasScroll(event)+ const isTarget = event.target.closest('.drag')+ const hasScroll = contentHasScroll(event)- if ((!isTarget || isHasScroll) && !isHandler.value) {+ if ((!isTarget || hasScroll) && !isHandler.value) {isDragging.value = falsereturn}@@ -183,16 +165,11 @@ export function useBottomSheetDrag({}}- /**- * Dragging- */function onDragging(event: Event): void {if (disabled.value || !isDragging.value)return- const isHasScroll = contentHasScroll(event)-- if (isHasScroll && !isHandler.value) {+ if (contentHasScroll(event) && !isHandler.value) {isDragging.value = falseinitialY.value = 0clientY.value = 0@@ -203,154 +180,110 @@ export function useBottomSheetDrag({clientY.value = getClientY(event)}- /**- * Drag end- */- async function onDragEnd() {+ function onDragEnd() {if (disabled.value || !isDragging.value)return- const isNeedClose- = nextCurrentY.value >= settings.pixelsNeedToDrugForClose- && direction.value === 'down'-- if (isNeedClose) {+ if (shouldClose(dragDistance.value, settings.pixelsNeedToDragForClose, direction.value))close()- }- else {+ elseopen()- }}- /**- * Clear- */- function clear() {+ function resetDrag() {clientY.value = 0isDragging.value = false}function setInitialY() {initialY.value = -(- (drug.value?.clientHeight ?? 0) + (handlerRef.value?.clientHeight ?? 0)+ (drag.value?.clientHeight ?? 0) + (handlerRef.value?.clientHeight ?? 0))}- /**- * Close modal- */function close() {- clear()+ resetDrag()setInitialY()}- /**- * Open modal- */function open() {- clear()+ resetDrag()opened.value = trueinitialY.value = 0}- /**- * On close modal- */- function onClose() {- // Scroll up all scroller blocks- const scrollerBlocks = drug.value?.querySelectorAll('.scrollerBlock')+ let stopTransitionListener: (() => void) | null = null++ function onTransitionEnd() {+ const scrollerBlocks = drag.value?.querySelectorAll('.scrollerBlock')scrollerBlocks?.forEach(el => (el.scrollTop = 0))- drug.value?.removeEventListener('transitionend', onClose)+ stopTransitionListener?.()+ stopTransitionListener = nullopened.value = falseemit('closed')}- /**- * Add events listeners- */+ // Event listener management+ let stopListeners: (() => void) | null = null+function addEvents() {- if (isEventsAdded.value)+ if (stopListeners)return- isEventsAdded.value = true-- // Touch- if (containerRef.value) {- containerRef.value.addEventListener('touchstart', onDragStart)- containerRef.value.addEventListener('touchmove', onDragging)- containerRef.value.addEventListener('touchend', onDragEnd)- containerRef.value.addEventListener('mousedown', onDragStart)- containerRef.value.addEventListener('mouseup', onDragEnd)-- document.addEventListener('mousemove', onDragging)- document.addEventListener('mouseleave', onDragEnd)+ const stops = [+ useEventListener(containerRef, 'touchstart', onDragStart),+ useEventListener(containerRef, 'touchmove', onDragging),+ useEventListener(containerRef, 'touchend', onDragEnd),+ useEventListener(containerRef, 'mousedown', onDragStart),+ useEventListener(containerRef, 'mouseup', onDragEnd),+ useEventListener(document, 'mousemove', onDragging),+ useEventListener(document, 'mouseleave', onDragEnd),+ ]++ stopListeners = () => {+ stops.forEach(fn => fn())+ stopListeners = null}}- /**- * Remove events listeners- */function removeEvents() {- isEventsAdded.value = false- if (containerRef.value) {- containerRef.value.removeEventListener('touchstart', onDragStart)- containerRef.value.removeEventListener('touchmove', onDragging)- containerRef.value.removeEventListener('touchend', onDragEnd)- containerRef.value.removeEventListener('mousedown', onDragStart)- containerRef.value.removeEventListener('mouseup', onDragEnd)-- document.removeEventListener('mousemove', onDragging)- document.removeEventListener('mouseleave', onDragEnd)- }+ stopListeners?.()}- /**- * Watch for diff height- */- watch(diffHeight, () => {+ watch(visiblePercent, () => {if (isDragging.value)return- if (diffHeight.value === 0) {+ if (visiblePercent.value === 0) {disabled.value = true- useEventListener(drug, 'transitionend', onClose, { passive: true })+ stopTransitionListener?.()+ stopTransitionListener = useEventListener(drag, 'transitionend', onTransitionEnd, { passive: true })return}disabled.value = false})- /**- * Init modal- */- async function init() {- initialHeight.value = drug.value?.clientHeight ?? 0-- setTimeout(async () => {+ function init() {+ setTimeout(() => {setInitialY()disabled.value = falseaddEvents()- setTimeout(() => {- open()- }, INIT_DELAY_MS)+ setTimeout(() => open(), INIT_DELAY_MS)}, INIT_DELAY_MS)}return {close,- drugStyles,+ dragStyles,init,isDragging,-opened,- // Computed classesoverflowClasses: computed(() => ({'transition-opacity duration-100': !isDragging.value && opened.value,})),overlayStyles,-removeEvents,-wrapClasses: computed<Record<string, boolean>>(() => ({'pointer-events-none invisible opacity-0': !opened.value,})),diff --git a/app/components/categories/Form.vue b/app/components/categories/Form.vueindex d0f5e05b..231b2086 100644--- a/app/components/categories/Form.vue+++ b/app/components/categories/Form.vue@@ -181,164 +181,135 @@ async function onSave() {</div></div>- <Teleport to="body">- <!-- Colors -->- <BottomSheet- v-if="modals.colors"- isShow- drugClassesCustom="bottomSheetDrugClassesCustom"- @closed="modals.colors = false"- >- <template #handler="{ close }">- <BottomSheetHandler />- <BottomSheetClose @click="close" />- </template>-- <template #default="{ close }">- <div class="bottomSheetContent">- <div>- <UiTitleModal>{{ t('categories.form.selectColor') }}</UiTitleModal>- <CategoriesItem- :categoryId="props.categoryId"- :category="categoryPlaceholder"- />- </div>+ <!-- Colors -->+ <BottomSheetModal+ v-if="modals.colors"+ @closed="modals.colors = false"+ >+ <template #default="{ close }">+ <div>+ <UiTitleModal>{{ t('categories.form.selectColor') }}</UiTitleModal>+ <CategoriesItem+ :categoryId="props.categoryId"+ :category="categoryPlaceholder"+ />+ </div>- <div class="scrollerBlock bottomSheetContentInside">- <ColorPalette- :activeColor="props.categoryForm.color"- :icon="props.categoryForm.icon"- isCategory- @click="color => emit('update', 'color', color)"- />- </div>+ <div class="scrollerBlock bottomSheetContentInside">+ <ColorPalette+ :activeColor="props.categoryForm.color"+ :icon="props.categoryForm.icon"+ isCategory+ @click="color => emit('update', 'color', color)"+ />+ </div>- <div class="flex-center p-2">- <UiButtonAccent- rounded- @click="close"- >- {{ t('base.apply') }}- </UiButtonAccent>- </div>- </div>- </template>- </BottomSheet>-- <!-- Icon -->- <BottomSheet- v-if="modals.icon"- isShow- drugClassesCustom="bottomSheetDrugClassesCustom"- @closed="modals.icon = false"- >- <template #handler="{ close }">- <BottomSheetHandler />- <BottomSheetClose @click="close" />- </template>-- <template #default="{ close }">- <div class="bottomSheetContent">- <div class="grid gap-3 pt-3 pb-1">- <UiTitleModal>{{ t('categories.form.selectIcon') }}</UiTitleModal>- <CategoriesItem- :categoryId="props.categoryId"- :category="categoryPlaceholder"- />- </div>+ <div class="flex-center p-2">+ <UiButtonAccent+ rounded+ @click="close"+ >+ {{ t('base.apply') }}+ </UiButtonAccent>+ </div>+ </template>+ </BottomSheetModal>- <div class="scrollerBlock bottomSheetContentInside">- <FormElement class="pt-2 pb-4">- <template #label>- {{ t('categories.form.icon.desc') }}- <a- href="https://icones.js.org/collection/mdi"- target="_blank"- class="text-primary hover:underline"- >Material Design Icons</a>- </template>-- <FormInput- :placeholder="t('categories.form.icon.placeholder')"- :modelValue="categoryForm.icon"- @update:modelValue="(value: string) => emit('update', 'icon', value)"- />- </FormElement>-- <div- v-for="iconGroup in icons"- :key="JSON.stringify(iconGroup)"- class="flex flex-wrap gap-3 pb-8 last:placeholder:text-blue-400"- >- <div- v-for="icon in iconGroup"- :key="icon"- :class="cn('flex-center text-icon-primary size-10 cursor-pointer rounded-full border-2 border-transparent',- icon === props.categoryForm.icon && 'border-(--ui-primary)',- )"- :style="{ background: props.categoryForm.color }"- @click="emit('update', 'icon', icon)"- >- <Icon :name="icon" size="20" />- </div>- </div>- </div>+ <!-- Icon -->+ <BottomSheetModal+ v-if="modals.icon"+ @closed="modals.icon = false"+ >+ <template #default="{ close }">+ <div class="grid gap-3 pt-3 pb-1">+ <UiTitleModal>{{ t('categories.form.selectIcon') }}</UiTitleModal>+ <CategoriesItem+ :categoryId="props.categoryId"+ :category="categoryPlaceholder"+ />+ </div>- <div class="bottomSheetContentBottom">- <UiButtonAccent- rounded- @click="close"- >- {{ t('base.apply') }}- </UiButtonAccent>+ <div class="scrollerBlock bottomSheetContentInside">+ <FormElement class="pt-2 pb-4">+ <template #label>+ {{ t('categories.form.icon.desc') }}+ <a+ href="https://icones.js.org/collection/mdi"+ target="_blank"+ class="text-primary hover:underline"+ >Material Design Icons</a>+ </template>++ <FormInput+ :placeholder="t('categories.form.icon.placeholder')"+ :modelValue="categoryForm.icon"+ @update:modelValue="(value: string) => emit('update', 'icon', value)"+ />+ </FormElement>++ <div+ v-for="iconGroup in icons"+ :key="JSON.stringify(iconGroup)"+ class="flex flex-wrap gap-3 pb-8 last:placeholder:text-blue-400"+ >+ <div+ v-for="icon in iconGroup"+ :key="icon"+ :class="cn('flex-center text-icon-primary size-10 cursor-pointer rounded-full border-2 border-transparent',+ icon === props.categoryForm.icon && 'border-(--ui-primary)',+ )"+ :style="{ background: props.categoryForm.color }"+ @click="emit('update', 'icon', icon)"+ >+ <Icon :name="icon" size="20" /></div></div>- </template>- </BottomSheet>-- <!-- Parent -->- <BottomSheet- v-if="modals.parent"- isShow- drugClassesCustom="bottomSheetDrugClassesCustom"- @closed="modals.parent = false"- >- <template #handler="{ close }">- <BottomSheetHandler />- <BottomSheetClose @click="close" />- </template>-- <template #default="{ close }">- <div class="bottomSheetContent">- <UiTitleModal>{{ t('categories.form.selectParent') }}</UiTitleModal>-- <div class="scrollerBlock bottomSheetContentInside">- <UiChipButton- :isActive="props.categoryForm.parentId === 0"- @click="onParentSelect(false, close)"- >- {{ t('categories.form.parent.no') }}- </UiChipButton>-- <CategoriesList- :activeItemId="props.categoryForm.parentId"- :categoriesItemProps="{ class: 'group' }"- :ids="categoriesStore.categoriesForBeParent.filter(id => id !== categoryId)"- class="!gap-x-1"- @click="id => onParentSelect(id, close)"- />- </div>+ </div>- <div class="bottomSheetContentBottom">- <UiButtonAccent- rounded- @click="close"- >- {{ t('base.apply') }}- </UiButtonAccent>- </div>- </div>- </template>- </BottomSheet>- </Teleport>+ <div class="bottomSheetContentBottom">+ <UiButtonAccent+ rounded+ @click="close"+ >+ {{ t('base.apply') }}+ </UiButtonAccent>+ </div>+ </template>+ </BottomSheetModal>++ <!-- Parent -->+ <BottomSheetModal+ v-if="modals.parent"+ @closed="modals.parent = false"+ >+ <template #default="{ close }">+ <UiTitleModal>{{ t('categories.form.selectParent') }}</UiTitleModal>++ <div class="scrollerBlock bottomSheetContentInside">+ <UiChipButton+ :isActive="props.categoryForm.parentId === 0"+ @click="onParentSelect(false, close)"+ >+ {{ t('categories.form.parent.no') }}+ </UiChipButton>++ <CategoriesList+ :activeItemId="props.categoryForm.parentId"+ :categoriesItemProps="{ class: 'group' }"+ :ids="categoriesStore.categoriesForBeParent.filter(id => id !== categoryId)"+ class="!gap-x-1"+ @click="id => onParentSelect(id, close)"+ />+ </div>++ <div class="bottomSheetContentBottom">+ <UiButtonAccent+ rounded+ @click="close"+ >+ {{ t('base.apply') }}+ </UiButtonAccent>+ </div>+ </template>+ </BottomSheetModal></template>diff --git a/app/components/categories/Item.vue b/app/components/categories/Item.vueindex a9e346fd..a0d79c56 100644--- a/app/components/categories/Item.vue+++ b/app/components/categories/Item.vue@@ -1,8 +1,6 @@<script setup lang="ts">import type { CategoryId, CategoryItem } from '~/components/categories/types'-import { useCategoriesStore } from '~/components/categories/useCategoriesStore'-export type CategoryItemProps = {activeItemId?: string | 0 | false | nullalt?: boolean@@ -21,71 +19,35 @@ const emit = defineEmits<{click: [e: Event]filter: [categoryId: CategoryId]}>()--const categoriesStore = useCategoriesStore()--const childCategoriesIds = computed(() => categoriesStore.getChildrenIds(props.categoryId))-const parentCategory = computed(() => categoriesStore.items[props.category?.parentId])</script><template><UContextMenu v-if="props.contextMenuItems" :items="props.contextMenuItems">- <UiElement- v-if="props.category"- :isActive="props.activeItemId === props.categoryId"+ <CategoriesItemBody+ :activeItemId="props.activeItemId"+ :alt="props.alt"+ :category="props.category"+ :categoryId="props.categoryId":class="props.class"+ :insideClasses="props.insideClasses"+ :isShowParent="props.isShowParent":lineWidth="props.lineWidth"- :insideClasses="`min-h-[46px] ${props.insideClasses}`"- @click="(e: Event) => emit('click', e)"- >- <template #leftIcon>- <UiIconBase- :color="props.category.color"- :name="props.category.icon"- invert- @click="emit('filter', props.categoryId ?? '')"- />- </template>-- <div class="grid grow gap-0.5">- <CategoriesName- :alt="props.alt"- :category="props.category"- :parentCategory="parentCategory"- :hasChildren="childCategoriesIds.length > 0"- :showChildrenCount="childCategoriesIds.length"- :isShowParent="props.isShowParent"- />- </div>- </UiElement>+ @click="emit('click', $event)"+ @filter="emit('filter', $event)"+ /></UContextMenu>- <UiElement- v-else-if="props.category"- :isActive="props.activeItemId === props.categoryId"+ <CategoriesItemBody+ v-else+ :activeItemId="props.activeItemId"+ :alt="props.alt"+ :category="props.category"+ :categoryId="props.categoryId":class="props.class"+ :insideClasses="props.insideClasses"+ :isShowParent="props.isShowParent":lineWidth="props.lineWidth"- :insideClasses="`min-h-[46px] ${props.insideClasses}`"- @click="(e: Event) => emit('click', e)"- >- <template #leftIcon>- <UiIconBase- :color="props.category.color"- :name="props.category.icon"- invert- @click="emit('filter', props.categoryId ?? '')"- />- </template>-- <div class="grid grow gap-0.5">- <CategoriesName- :alt="props.alt"- :category="props.category"- :parentCategory="parentCategory"- :hasChildren="childCategoriesIds.length > 0"- :showChildrenCount="childCategoriesIds.length"- :isShowParent="props.isShowParent"- />- </div>- </UiElement>+ @click="emit('click', $event)"+ @filter="emit('filter', $event)"+ /></template>diff --git a/app/components/categories/ItemBody.vue b/app/components/categories/ItemBody.vuenew file mode 100644index 00000000..2a9d8d72--- /dev/null+++ b/app/components/categories/ItemBody.vue@@ -0,0 +1,57 @@+<script setup lang="ts">+import type { CategoryId, CategoryItem } from '~/components/categories/types'++import { useCategoriesStore } from '~/components/categories/useCategoriesStore'++const props = defineProps<{+ activeItemId?: string | 0 | false | null+ alt?: boolean+ category: CategoryItem+ categoryId: CategoryId+ class?: string+ insideClasses?: string+ isShowParent?: boolean+ lineWidth?: number+}>()++const emit = defineEmits<{+ click: [e: Event]+ filter: [categoryId: CategoryId]+}>()++const categoriesStore = useCategoriesStore()++const childCategoriesIds = computed(() => categoriesStore.getChildrenIds(props.categoryId))+const parentCategory = computed(() => categoriesStore.items[props.category?.parentId])+</script>++<template>+ <UiElement+ v-if="props.category"+ :isActive="props.activeItemId === props.categoryId"+ :class="props.class"+ :lineWidth="props.lineWidth"+ :insideClasses="`min-h-[46px] ${props.insideClasses}`"+ @click="(e: Event) => emit('click', e)"+ >+ <template #leftIcon>+ <UiIconBase+ :color="props.category.color"+ :name="props.category.icon"+ invert+ @click="emit('filter', props.categoryId ?? '')"+ />+ </template>++ <div class="grid grow gap-0.5">+ <CategoriesName+ :alt="props.alt"+ :category="props.category"+ :parentCategory="parentCategory"+ :hasChildren="childCategoriesIds.length > 0"+ :showChildrenCount="childCategoriesIds.length"+ :isShowParent="props.isShowParent"+ />+ </div>+ </UiElement>+</template>diff --git a/app/components/categories/SelectorTree.vue b/app/components/categories/SelectorTree.vueindex 3d345cd4..900f0e2b 100644--- a/app/components/categories/SelectorTree.vue+++ b/app/components/categories/SelectorTree.vue@@ -15,6 +15,13 @@ const emit = defineEmits<{const categoriesStore = useCategoriesStore()const opened = ref<CategoryId[]>([])+const childrenMap = computed(() => {+ const map = new Map<CategoryId, CategoryId[]>()+ for (const id of categoriesStore.categoriesRootIds)+ map.set(id, categoriesStore.getChildrenIds(id))+ return map+})+function select(categoryId: CategoryId, isForce: boolean) {if (!isForce && categoriesStore.hasChildren(categoryId)) {if (opened.value.includes(categoryId)) {@@ -30,19 +37,19 @@ function select(categoryId: CategoryId, isForce: boolean) {}function onFilter(id: CategoryId) {- const childs = categoriesStore.getChildrenIds(id)- emit('setCategories', childs)+ emit('setCategories', childrenMap.value.get(id) ?? [])}function isChildsSelected(categoryId: CategoryId) {- return categoriesStore.getChildrenIds(categoryId).some(id => props.selectedIds?.includes(id))+ return (childrenMap.value.get(categoryId) ?? []).some(id => props.selectedIds?.includes(id))}function isEveryChildsSelected(categoryId: CategoryId) {- if (!categoriesStore.getChildrenIds(categoryId).length)+ const children = childrenMap.value.get(categoryId) ?? []+ if (!children.length)return false- return categoriesStore.getChildrenIds(categoryId).every(id => props.selectedIds?.includes(id))+ return children.every(id => props.selectedIds?.includes(id))}onMounted(() => {@@ -79,7 +86,7 @@ onMounted(() => {class="pr-2 pb-2 pl-4"><CategoriesItem- v-for="childCategoryId in categoriesStore.getChildrenIds(categoryId)"+ v-for="childCategoryId in childrenMap.get(categoryId)":key="childCategoryId":activeItemId="props.selectedIds?.includes(childCategoryId) ? childCategoryId : null":category="categoriesStore.items[childCategoryId]"diff --git a/app/components/categories/useCategoriesStore.ts b/app/components/categories/useCategoriesStore.tsindex 6958ff59..6a10dc5c 100644--- a/app/components/categories/useCategoriesStore.ts+++ b/app/components/categories/useCategoriesStore.ts@@ -72,16 +72,16 @@ export const useCategoriesStore = defineStore('categories', (): CategoriesStore.sort((a, b) => compareCategoriesByParentAndName(items.value[a]!, items.value[b]!, items.value))})+ const usedCategoryIds = computed(() =>+ new Set(Object.values(trnsStore.items ?? {}).map(trn => trn.categoryId)),+ )+const categoriesForBeParent = computed(() => {if (!hasItems.value)return []- const usedCategoryIds = new Set(- Object.values(trnsStore.items ?? {}).map(trn => trn.categoryId),- )-return categoriesRootIds.value.filter((id: CategoryId) =>- !usedCategoryIds.has(id) && id !== 'transfer',+ !usedCategoryIds.value.has(id) && id !== 'transfer',)})diff --git a/app/components/currencies/Modal.vue b/app/components/currencies/Modal.vueindex 49def5cf..06baf3a3 100644--- a/app/components/currencies/Modal.vue+++ b/app/components/currencies/Modal.vue@@ -21,29 +21,16 @@ function select(code: CurrencyCode, close: () => void) {</script><template>- <Teleport to="body">- <BottomSheet- isShow- drugClassesCustom="bottomSheetDrugClassesCustom"- @closed="emit('close')"- >- <template #handler="{ close }">- <BottomSheetHandler />- <BottomSheetClose @click="close" />- </template>+ <BottomSheetModal @closed="emit('close')">+ <template #default="{ close }">+ <UiTitleModal>{{ t('currencies.select') }}</UiTitleModal>- <template #default="{ close }">- <div class="bottomSheetContent">- <UiTitleModal>{{ t('currencies.select') }}</UiTitleModal>-- <CurrenciesList- :active="props.activeCode"- :isShowAllButton="props.isShowAllButton"- :isHideUnused="props.isHideUnused"- @select="(c: CurrencyCode) => select(c, close)"- />- </div>- </template>- </BottomSheet>- </Teleport>+ <CurrenciesList+ :active="props.activeCode"+ :isShowAllButton="props.isShowAllButton"+ :isHideUnused="props.isHideUnused"+ @select="(c: CurrencyCode) => select(c, close)"+ />+ </template>+ </BottomSheetModal></template>diff --git a/app/components/stat/Item.vue b/app/components/stat/Item.vueindex 1b76ffd6..10f4b380 100644--- a/app/components/stat/Item.vue+++ b/app/components/stat/Item.vue@@ -166,76 +166,51 @@ function onClickSumItemWrap(type: SeriesSlugSelected) {</div><!-- Quick View Trns -->- <Teleport+ <BottomSheetModalv-if="quickViewTrns?.length > 0"- to="body"+ @closed="quickViewTrns = []">- <BottomSheet- v-if="quickViewTrns?.length > 0"- isShow- drugClassesCustom="bottomSheetDrugClassesCustom"- @closed="quickViewTrns = []"- >- <template #handler="{ close }">- <BottomSheetHandler />- <BottomSheetClose @click="close" />- </template>-- <div class="bottomSheetContent">- <UiTitleModal>- {{ t('trns.title') }} {{ quickViewTrns.length > 0 ? quickViewTrns.length : '' }}- </UiTitleModal>-- <div class="scrollerBlock bottomSheetContentInside pb-2">- <TrnsList- :isShowDates="!isPeriodOneDay"- :isShowGroupSum="!isPeriodOneDay"- :size="50"- :trnsIds="quickViewTrns"- isShowExpense- isShowFilterByDesc- isShowFilterByType- isShowIncome- isShowTransfers- @click="() => quickViewTrns = []"- />- </div>- </div>- </BottomSheet>- </Teleport>-- <Teleport to="body">- <BottomSheet- v-if="isShowTrns"- isShow- drugClassesCustom="bottomSheetDrugClassesCustom"- @closed="isShowTrns = false"- >- <template #handler="{ close }">- <BottomSheetHandler />- <BottomSheetClose @click="close" />- </template>-- <div class="bottomSheetContent">- <UiTitleModal>- {{ t('trns.title') }} {{ selectedAndFilteredTrnsIds.length > 0 ? selectedAndFilteredTrnsIds.length : '' }}- </UiTitleModal>-- <div class="scrollerBlock bottomSheetContentInside">- <TrnsList- :isShowDates="!isPeriodOneDay"- :isShowGroupSum="!isPeriodOneDay"- :size="50"- :trnsIds="selectedAndFilteredTrnsIds"- isShowExpense- isShowFilterByDesc- isShowFilterByType- isShowIncome- isShowTransfers- />- </div>- </div>- </BottomSheet>- </Teleport>+ <UiTitleModal>+ {{ t('trns.title') }} {{ quickViewTrns.length > 0 ? quickViewTrns.length : '' }}+ </UiTitleModal>++ <div class="scrollerBlock bottomSheetContentInside pb-2">+ <TrnsList+ :isShowDates="!isPeriodOneDay"+ :isShowGroupSum="!isPeriodOneDay"+ :size="50"+ :trnsIds="quickViewTrns"+ isShowExpense+ isShowFilterByDesc+ isShowFilterByType+ isShowIncome+ isShowTransfers+ @click="() => quickViewTrns = []"+ />+ </div>+ </BottomSheetModal>++ <BottomSheetModal+ v-if="isShowTrns"+ @closed="isShowTrns = false"+ >+ <UiTitleModal>+ {{ t('trns.title') }} {{ selectedAndFilteredTrnsIds.length > 0 ? selectedAndFilteredTrnsIds.length : '' }}+ </UiTitleModal>++ <div class="scrollerBlock bottomSheetContentInside">+ <TrnsList+ :isShowDates="!isPeriodOneDay"+ :isShowGroupSum="!isPeriodOneDay"+ :size="50"+ :trnsIds="selectedAndFilteredTrnsIds"+ isShowExpense+ isShowFilterByDesc+ isShowFilterByType+ isShowIncome+ isShowTransfers+ />+ </div>+ </BottomSheetModal></div></template>diff --git a/app/components/stat/filter/useFilter.ts b/app/components/stat/filter/useFilter.tsindex 5643989e..8343c707 100644--- a/app/components/stat/filter/useFilter.ts+++ b/app/components/stat/filter/useFilter.ts@@ -4,130 +4,87 @@ import type { WalletId } from '~/components/wallets/types'import { useCategoriesStore } from '~/components/categories/useCategoriesStore'import { useWalletsStore } from '~/components/wallets/useWalletsStore'-export function useFilter() {- const router = useRouter()- const route = useRoute()- const categoriesStore = useCategoriesStore()- const walletsStore = useWalletsStore()-- /**- * Wallets- */- const walletsIds = computed<WalletId[]>(() => Array.isArray(route.query.filterWallets)- ? (route.query.filterWallets as WalletId[]).filter(id => walletsStore.items?.[id])- : route.query.filterWallets- ? [...route.query.filterWallets.split(',')]- : [],- )-- function setWalletId(walletId: WalletId) {- if (walletsIds.value.includes(walletId))+function createQueryFilter<T extends string>(+ route: ReturnType<typeof useRoute>,+ router: ReturnType<typeof useRouter>,+ queryKey: string,+ validateFn?: (id: T) => boolean,+) {+ const ids = computed<T[]>(() => {+ const value = route.query[queryKey]+ if (Array.isArray(value))+ return validateFn ? (value as T[]).filter(validateFn) : (value as T[])+ return value ? [...(value as string).split(',')] as T[] : []+ })++ function setId(id: T) {+ if (ids.value.includes(id))returnrouter.push({query: {...route.query,- filterWallets: [...walletsIds.value, walletId],+ [queryKey]: [...ids.value, id],},})}- function toggleWalletId(walletId: WalletId) {- if (walletsIds.value.includes(walletId)) {- removeWalletId(walletId)- return- }-- setWalletId(walletId)- }-- function setWallets(newWalletsIds: WalletId[]) {+ function setMultiple(newIds: T[]) {router.push({query: {...route.query,- filterWallets: [...new Set(walletsIds.value.concat(newWalletsIds))],+ [queryKey]: [...new Set(ids.value.concat(newIds))],},})}- function removeWalletId(walletId: WalletId) {+ function removeId(id: T) {router.push({query: {...route.query,- filterWallets: [...walletsIds.value.filter(id => id !== walletId)],+ [queryKey]: [...ids.value.filter(i => i !== id)],},})}- /**- * Categories- */- const categoriesIds = computed<CategoryId[]>(() => Array.isArray(route.query.filterCategories)- ? (route.query.filterCategories as CategoryId[]).filter(id => categoriesStore.items[id])- : route.query.filterCategories- ? [...route.query.filterCategories.split(',')]- : [],- )-- function setCategoryId(categoryId: CategoryId) {- if (categoriesIds.value.includes(categoryId))+ function toggleId(id: T) {+ if (ids.value.includes(id)) {+ removeId(id)return+ }- router.push({- query: {- ...route.query,- filterCategories: [...categoriesIds.value, categoryId],- },- })+ setId(id)}- function setCategories(newCategoriesIds: CategoryId[]) {- router.push({- query: {- ...route.query,- filterCategories: [...new Set(categoriesIds.value.concat(newCategoriesIds))],- },- })- }-- function removeCategoryId(categoryId: CategoryId) {- router.push({- query: {- ...route.query,- filterCategories: [...categoriesIds.value.filter(id => id !== categoryId)],- },- })- }+ return { ids, removeId, setId, setMultiple, toggleId }+}- function toggleCategoryId(categoryId: CategoryId) {- if (categoriesIds.value.includes(categoryId)) {- removeCategoryId(categoryId)- return- }+export function useFilter() {+ const router = useRouter()+ const route = useRoute()+ const categoriesStore = useCategoriesStore()+ const walletsStore = useWalletsStore()- setCategoryId(categoryId)- }+ const wallets = createQueryFilter<WalletId>(route, router, 'filterWallets', id => !!walletsStore.items?.[id])+ const categories = createQueryFilter<CategoryId>(route, router, 'filterCategories', id => !!categoriesStore.items[id])- /**- * Clear- */function clearFilter() {router.push({ query: undefined })}- const isShow = computed(() => categoriesIds.value.length > 0 || walletsIds.value.length > 0)+ const isShow = computed(() => categories.ids.value.length > 0 || wallets.ids.value.length > 0)return {- categoriesIds,+ categoriesIds: categories.ids,clearFilter,isShow,- removeCategoryId,- removeWalletId,- setCategories,- setCategoryId,- setWallets,- toggleCategoryId,- toggleWalletId,- walletsIds,+ removeCategoryId: categories.removeId,+ removeWalletId: wallets.removeId,+ setCategories: categories.setMultiple,+ setCategoryId: categories.setId,+ setWallets: wallets.setMultiple,+ toggleCategoryId: categories.toggleId,+ toggleWalletId: wallets.toggleId,+ walletsIds: wallets.ids,}}diff --git a/app/components/stat/useStatItem.ts b/app/components/stat/useStatItem.tsindex 58fd61d9..553682db 100644--- a/app/components/stat/useStatItem.ts+++ b/app/components/stat/useStatItem.ts@@ -55,6 +55,7 @@ export function useStatItem({const selectedTypesMapping = computed(() => getTypesMapping(selectedType.value))const isPeriodOneDay = computed(() => isPeriodOneDayFn(statDate.params.value))+ const isIntervalSelected = computed(() => isIntervalSelected.value)const rangeTrnsIds = computed(() => trnsStore.getStoreTrnsIds({trnsIds: trnsIds.value,@@ -75,7 +76,7 @@ export function useStatItem({const selectedTrnsIds = computed(() => trnsStore.getStoreTrnsIds({sort: true,- trnsIds: statDate.params.value.intervalSelected !== -1+ trnsIds: isIntervalSelected.value? intervalsData.value[statDate.params.value.intervalSelected]?.trnsIds: rangeTrnsIds.value,trnsTypes: selectedTypesMapping.value,@@ -84,14 +85,14 @@ export function useStatItem({const selectedAndFilteredTrnsIds = computed(() => trnsStore.getStoreTrnsIds({categoriesIds: filteredCategoriesIds.value,sort: true,- trnsIds: statDate.params.value.intervalSelected !== -1+ trnsIds: isIntervalSelected.value? intervalsData.value[statDate.params.value.intervalSelected]?.trnsIds: rangeTrnsIds.value,trnsTypes: selectedTypesMapping.value,}))const rangeTotal = computed(() => {- const ids = statDate.params.value.intervalSelected !== -1+ const ids = isIntervalSelected.value? intervalsDataWithFilteredCategories.value[statDate.params.value.intervalSelected]?.trnsIds: rangeTrnsIdsWithFilteredCategories.valuereturn computeTotalForTrnsIds(ids)@@ -103,7 +104,7 @@ export function useStatItem({const sum = filteredType.value === 'netIncome' ? rangeTotal.value.sum : rangeTotal.value[type.value!]- const dateRange = statDate.params.value.intervalSelected !== -1+ const dateRange = isIntervalSelected.value? statDate.selectedInterval.value: statDate.range.valuediff --git a/app/components/trnForm/Bottom.vue b/app/components/trnForm/Bottom.vueindex e040cc7c..be37568a 100644--- a/app/components/trnForm/Bottom.vue+++ b/app/components/trnForm/Bottom.vue@@ -76,7 +76,7 @@ onMounted(init)<template><BottomSheet:isShow="isShow"- drugClassesCustom="max-h-[98dvh] max-w-md"+ dragClassesCustom="max-h-[98dvh] max-w-md"@closed="trnsFormStore.onClose()"><template #handler="{ close }">diff --git a/app/components/trnForm/Main.vue b/app/components/trnForm/Main.vueindex 1a0e54bd..f61e30be 100644--- a/app/components/trnForm/Main.vue+++ b/app/components/trnForm/Main.vue@@ -14,11 +14,9 @@ const { t } = useI18n()const categoriesStore = useCategoriesStore()const trnsFormStore = useTrnsFormStore()const walletsStore = useWalletsStore()-const walletId = computed(() => {- const walletsIds = Object.keys(walletsStore.items ?? {})- const firstWalletId = walletsIds[0]- return trnsFormStore.values.walletId ?? firstWalletId-})+const walletId = computed(() =>+ trnsFormStore.values.walletId ?? walletsStore.sortedIds[0],+)</script><template>diff --git a/app/components/trnForm/SelectorCategory.vue b/app/components/trnForm/SelectorCategory.vueindex 4ae9e4f6..b6c32188 100644--- a/app/components/trnForm/SelectorCategory.vue+++ b/app/components/trnForm/SelectorCategory.vue@@ -20,7 +20,7 @@ const isShow = ref(false):title="props.title":isOpen="isShow":bottomSheetStyle="props.bottomSheetStyle"- drugClassesCustom="h-full max-w-md"+ dragClassesCustom="h-full max-w-md"isShowCloseBtn@openModal="isShow = true"@closeModal="isShow = false"diff --git a/app/components/trnForm/SelectorWallet.vue b/app/components/trnForm/SelectorWallet.vueindex 8a99c380..05eb159d 100644--- a/app/components/trnForm/SelectorWallet.vue+++ b/app/components/trnForm/SelectorWallet.vue@@ -23,7 +23,7 @@ const isShow = ref(false):bottomSheetStyle="props.bottomSheetStyle":isOpen="isShow":title="props.title"- drugClassesCustom="h-full max-w-md"+ dragClassesCustom="h-full max-w-md"isShowCloseBtn@closeModal="isShow = false"@openModal="isShow = true"diff --git a/app/components/trnForm/main/Description.vue b/app/components/trnForm/main/Description.vueindex 087e5679..d9305e01 100644--- a/app/components/trnForm/main/Description.vue+++ b/app/components/trnForm/main/Description.vue@@ -24,7 +24,7 @@ function onSave(close: () => void) {:isOpen="trnsFormStore.modal.description":title="t('trnForm.description.title')"class="grow"- drugClassesCustom="max-w-md"+ dragClassesCustom="max-w-md"isShowCloseBtn@closeModal="trnsFormStore.closeTrnFormModal('description')"@openModal="trnsFormStore.openTrnFormModal('description')"diff --git a/app/components/trns/List.vue b/app/components/trns/List.vueindex b3bb9e26..5d7cd5d5 100644--- a/app/components/trns/List.vue+++ b/app/components/trns/List.vue@@ -146,6 +146,15 @@ const groupedTrns = computed(() => paginatedTrnsIds.valueconst paginatedTotal = computed(() => computeTotalForTrnsIds(paginatedTrnsIds.value))+const groupTotals = computed(() => {+ const map = new Map<string, ReturnType<typeof computeTotalForTrnsIds>>()+ for (const [date, ids] of Object.entries(groupedTrns.value)) {+ if (ids.length > 1)+ map.set(date, computeTotalForTrnsIds(ids))+ }+ return map+})+const trnItemsMap = computed(() => {const map = new Map<TrnId, ReturnType<typeof trnsStore.computeTrnItem>>()for (const trnId of paginatedTrnsIds.value) {@@ -280,8 +289,8 @@ function onOpenTrnForm(date: number) {class="opacity-60"><Amount- v-if="computeTotalForTrnsIds(groupTrnsIds).income !== 0"- :amount="computeTotalForTrnsIds(groupTrnsIds).income"+ v-if="groupTotals.get(String(date))?.income"+ :amount="groupTotals.get(String(date))!.income":currencyCode="currenciesStore.base":isShowBaseRate="false":type="TrnType.Income"@@ -290,8 +299,8 @@ function onOpenTrnForm(date: number) {/><Amount- v-if="computeTotalForTrnsIds(groupTrnsIds).expense !== 0"- :amount="computeTotalForTrnsIds(groupTrnsIds).expense"+ v-if="groupTotals.get(String(date))?.expense"+ :amount="groupTotals.get(String(date))!.expense":currencyCode="currenciesStore.base":isShowBaseRate="false":type="TrnType.Expense"diff --git a/app/components/wallets/Form.vue b/app/components/wallets/Form.vueindex 4d9cdb7c..218e2f27 100644--- a/app/components/wallets/Form.vue+++ b/app/components/wallets/Form.vue@@ -175,48 +175,37 @@ async function onSave() {@close="modals.currencies = false"/>- <Teleport to="body">- <!-- Colors -->- <BottomSheet- v-if="modals.colors"- isShow- drugClassesCustom="bottomSheetDrugClassesCustom"- @closed="modals.colors = false"- >- <template #handler="{ close }">- <BottomSheetHandler />- <BottomSheetClose @click="close" />- </template>-- <template #default="{ close }">- <div class="bottomSheetContent">- <div>- <UiTitleModal>{{ t('color.label') }}</UiTitleModal>- <WalletsItem- :walletId="props.walletId ?? editWalletId"- :wallet="walletPlaceholder"- isShowIcon- />- </div>-- <div class="scrollerBlock bottomSheetContentInside">- <ColorPalette- :activeColor="props.walletForm.color"- isWallet- @click="(color: string) => emit('update', 'color', color)"- />- </div>-- <div class="flex-center py-2">- <UiButtonAccent- rounded- @click="close"- >- {{ t('base.apply') }}- </UiButtonAccent>- </div>- </div>- </template>- </BottomSheet>- </Teleport>+ <!-- Colors -->+ <BottomSheetModal+ v-if="modals.colors"+ @closed="modals.colors = false"+ >+ <template #default="{ close }">+ <div>+ <UiTitleModal>{{ t('color.label') }}</UiTitleModal>+ <WalletsItem+ :walletId="props.walletId ?? editWalletId"+ :wallet="walletPlaceholder"+ isShowIcon+ />+ </div>++ <div class="scrollerBlock bottomSheetContentInside">+ <ColorPalette+ :activeColor="props.walletForm.color"+ isWallet+ @click="(color: string) => emit('update', 'color', color)"+ />+ </div>++ <div class="flex-center py-2">+ <UiButtonAccent+ rounded+ @click="close"+ >+ {{ t('base.apply') }}+ </UiButtonAccent>+ </div>+ </template>+ </BottomSheetModal></template>diff --git a/app/components/wallets/Icon.vue b/app/components/wallets/Icon.vueindex 249251fd..5a11a3b1 100644--- a/app/components/wallets/Icon.vue+++ b/app/components/wallets/Icon.vue@@ -11,10 +11,9 @@ const props = defineProps<{* - If the name is a single word, returns the first two characters of the name.*/function getWalletIconName(name: string) {- return name.split(' ')- .map(word => word[0])- .length > 1- ? name.split(' ').map(word => word[0]).join('').slice(0, 2)+ const words = name.split(' ')+ return words.length > 1+ ? words.map(word => word[0]).join('').slice(0, 2): name.slice(0, 2)}</script>diff --git a/app/components/wallets/Item.vue b/app/components/wallets/Item.vueindex 3dffa00c..292c510a 100644--- a/app/components/wallets/Item.vue+++ b/app/components/wallets/Item.vue@@ -1,10 +1,6 @@<script setup lang="ts">-import { useStorage } from '@vueuse/core'-import type { WalletId, WalletItemComputed } from '~/components/wallets/types'-import { useCurrenciesStore } from '~/components/currencies/useCurrenciesStore'-const props = defineProps<{activeItemId?: WalletId | nullalt?: boolean@@ -23,300 +19,39 @@ const props = defineProps<{const emit = defineEmits<{click: [walletId: WalletId]}>()--const currenciesStore = useCurrenciesStore()--const classes = computed(() => ([- 'relative',- {- 'bg-item-3 rounded-sm': props.alt,- },- {- group: props.isSort,- },-]))--const creditViews = ['debt', 'summary'] as const-const activeCreditView = useStorage<typeof creditViews[number]>(props.walletId, 'debt')--const creditAmount = computed(() => {- switch (activeCreditView.value) {- case 'debt':- return props.wallet?.amount- case 'summary':- return Math.abs(props.wallet.creditLimit ?? 0) - Math.abs(props.wallet.amount)- default:- return 0- }-})--const longPressRef = ref(null)-if (!props.isSort) {- onLongPress(- longPressRef,- () => {- activeCreditView.value = creditViews[creditViews.findIndex(i => i === activeCreditView.value) + 1]- },- )-}</script><template><UContextMenu v-if="props.contextMenuItems" :items="props.contextMenuItems">- <UiElement- v-if="wallet"- ref="longPressRef"- :isActive="activeItemId === props.walletId"- :insideClasses="`${props.insideClasses ?? ''} min-h-[46px]`"+ <WalletsItemBody+ :activeItemId="props.activeItemId"+ :alt="props.alt"+ :insideClasses="props.insideClasses"+ :isShowBaseRate="props.isShowBaseRate"+ :isShowCreditLimit="props.isShowCreditLimit"+ :isShowIcon="props.isShowIcon"+ :isShowRate="props.isShowRate"+ :isSort="props.isSort":lineWidth="props.lineWidth"- :class="classes"- @click="emit('click', props.walletId)"- >- <!-- Icon -->- <template v-if="props.isShowIcon" #leftIcon>- <WalletsIcon- :name="wallet.name"- :color="wallet.color"- />- </template>-- <!-- Main -->- <template v-if="!props.alt">- <div class="grid grow gap-1">- <div class="text-muted text-sm leading-none font-medium tracking-wide text-nowrap">- {{ wallet.name }}- </div>-- <!-- Rate -->- <div- v-if="props.isShowRate && wallet.currency !== currenciesStore.base && wallet.rate"- class="opacity-90"- >- <Amount- :amount="wallet.rate"- :precision="2"- :currencyCode="currenciesStore.base"- :isShowBaseRate="false"- align="left"- variant="2xs"- class="text-xs opacity-70"- />- </div>-- <div- v-if="props.isShowCreditLimit && wallet.type === 'credit' && wallet.creditLimit"- class="flex items-center gap-0.5 opacity-70"- >- <Amount- :amount="wallet.creditLimit - Math.abs(wallet.amount)"- :currencyCode="wallet.currency"- :isShowBaseRate="false"- :isShowSymbol="false"- align="left"- variant="2xs"- />-- <div- v-if="wallet.amount !== 0"- class="text-2xs leading-none opacity-70"- >- /- </div>-- <Amount- v-if="wallet.amount !== 0"- :amount="wallet.creditLimit"- :currencyCode="wallet.currency"- :isShowBaseRate="false"- :isShowSymbol="false"- align="left"- variant="2xs"- />- </div>- </div>-- <div class="pr-1">- <Amount- v-if="wallet.creditLimit"- :amount="creditAmount"- :currencyCode="wallet.currency"- :isShowBaseRate="props.isShowBaseRate"- variant="sm"- />- <Amount- v-else- :amount="wallet.amount"- :currencyCode="wallet.currency"- :isShowBaseRate="props.isShowBaseRate"- variant="sm"- />- </div>- </template>-- <!-- Alternative -->- <template v-if="props.alt">- <div class="grid grow gap-0.5">- <div class="text-2 text-xs leading-none whitespace-nowrap">- {{ wallet.name }}- </div>-- <div v-if="!isSort">- <Amount- v-if="wallet.creditLimit"- :amount="creditAmount"- :currencyCode="wallet.currency"- :isShowBaseRate="false"- :isShowMinus="false"- align="left"- variant="2xs"- />- <Amount- v-else- :amount="wallet.amount"- :currencyCode="wallet.currency"- :isShowBaseRate="props.isShowBaseRate"- :isShowMinus="false"- align="left"- variant="2xs"- />- </div>- </div>-- <div- v-if="isSort"- class="sortHandle flex-center absolute right-0 h-full rounded-md px-3 group-hover:bg-(--item-6)"- >- <Icon name="lucide:grip-vertical" size="20" />- </div>- </template>- </UiElement>+ :wallet="props.wallet"+ :walletId="props.walletId"+ @click="emit('click', $event)"+ /></UContextMenu>- <UiElement- v-else-if="wallet"- ref="longPressRef"- :isActive="activeItemId === props.walletId"- :insideClasses="`${props.insideClasses ?? ''} min-h-[46px]`"+ <WalletsItemBody+ v-else+ :activeItemId="props.activeItemId"+ :alt="props.alt"+ :insideClasses="props.insideClasses"+ :isShowBaseRate="props.isShowBaseRate"+ :isShowCreditLimit="props.isShowCreditLimit"+ :isShowIcon="props.isShowIcon"+ :isShowRate="props.isShowRate"+ :isSort="props.isSort":lineWidth="props.lineWidth"- :class="classes"- @click="emit('click', props.walletId)"- >- <!-- Icon -->- <template v-if="props.isShowIcon" #leftIcon>- <WalletsIcon- :name="wallet.name"- :color="wallet.color"- />- </template>-- <!-- Main -->- <template v-if="!props.alt">- <div class="grid grow gap-1">- <div class="text-muted text-sm leading-none font-medium tracking-wide text-nowrap">- {{ wallet.name }}- </div>-- <!-- Rate -->- <div- v-if="props.isShowRate && wallet.currency !== currenciesStore.base && wallet.rate"- class="opacity-90"- >- <Amount- :amount="wallet.rate"- :precision="2"- :currencyCode="currenciesStore.base"- :isShowBaseRate="false"- align="left"- variant="2xs"- class="text-xs opacity-70"- />- </div>-- <div- v-if="props.isShowCreditLimit && wallet.type === 'credit' && wallet.creditLimit"- class="flex items-center gap-0.5 opacity-70"- >- <Amount- :amount="wallet.creditLimit - Math.abs(wallet.amount)"- :currencyCode="wallet.currency"- :isShowBaseRate="false"- :isShowSymbol="false"- align="left"- variant="2xs"- />-- <div- v-if="wallet.amount !== 0"- class="text-2xs leading-none opacity-70"- >- /- </div>-- <Amount- v-if="wallet.amount !== 0"- :amount="wallet.creditLimit"- :currencyCode="wallet.currency"- :isShowBaseRate="false"- :isShowSymbol="false"- align="left"- variant="2xs"- />- </div>- </div>-- <div class="pr-1">- <Amount- v-if="wallet.creditLimit"- :amount="creditAmount"- :currencyCode="wallet.currency"- :isShowBaseRate="props.isShowBaseRate"- variant="sm"- />- <Amount- v-else- :amount="wallet.amount"- :currencyCode="wallet.currency"- :isShowBaseRate="props.isShowBaseRate"- variant="sm"- />- </div>- </template>-- <!-- Alternative -->- <template v-if="props.alt">- <div class="grid grow gap-0.5">- <div class="text-2 text-xs leading-none whitespace-nowrap">- {{ wallet.name }}- </div>-- <div v-if="!isSort">- <Amount- v-if="wallet.creditLimit"- :amount="creditAmount"- :currencyCode="wallet.currency"- :isShowBaseRate="false"- :isShowMinus="false"- align="left"- variant="2xs"- />- <Amount- v-else- :amount="wallet.amount"- :currencyCode="wallet.currency"- :isShowBaseRate="props.isShowBaseRate"- :isShowMinus="false"- align="left"- variant="2xs"- />- </div>- </div>-- <div- v-if="isSort"- class="sortHandle flex-center absolute right-0 h-full rounded-md px-3 group-hover:bg-(--item-6)"- >- <Icon name="lucide:grip-vertical" size="20" />- </div>- </template>- </UiElement>+ :wallet="props.wallet"+ :walletId="props.walletId"+ @click="emit('click', $event)"+ /></template>diff --git a/app/components/wallets/ItemBody.vue b/app/components/wallets/ItemBody.vuenew file mode 100644index 00000000..c72b1b66--- /dev/null+++ b/app/components/wallets/ItemBody.vue@@ -0,0 +1,191 @@+<script setup lang="ts">+import { useStorage } from '@vueuse/core'++import type { WalletId, WalletItemComputed } from '~/components/wallets/types'++import { useCurrenciesStore } from '~/components/currencies/useCurrenciesStore'++const props = defineProps<{+ activeItemId?: WalletId | null+ alt?: boolean+ insideClasses?: string+ isShowBaseRate?: boolean+ isShowCreditLimit?: boolean+ isShowIcon?: boolean+ isShowRate?: boolean+ isSort?: boolean+ lineWidth?: number+ wallet: WalletItemComputed+ walletId: WalletId+}>()++const emit = defineEmits<{+ click: [walletId: WalletId]+}>()++const currenciesStore = useCurrenciesStore()++const classes = computed(() => ([+ 'relative',+ {+ 'bg-item-3 rounded-sm': props.alt,+ },+ {+ group: props.isSort,+ },+]))++const creditViews = ['debt', 'summary'] as const+const activeCreditView = useStorage<typeof creditViews[number]>(props.walletId, 'debt')++const creditAmount = computed(() => {+ switch (activeCreditView.value) {+ case 'debt':+ return props.wallet?.amount+ case 'summary':+ return Math.abs(props.wallet.creditLimit ?? 0) - Math.abs(props.wallet.amount)+ default:+ return 0+ }+})++const longPressRef = ref(null)+if (!props.isSort) {+ onLongPress(+ longPressRef,+ () => {+ activeCreditView.value = creditViews[creditViews.findIndex(i => i === activeCreditView.value) + 1]+ },+ )+}+</script>++<template>+ <UiElement+ v-if="wallet"+ ref="longPressRef"+ :isActive="activeItemId === props.walletId"+ :insideClasses="`${props.insideClasses ?? ''} min-h-[46px]`"+ :lineWidth="props.lineWidth"+ :class="classes"+ @click="emit('click', props.walletId)"+ >+ <!-- Icon -->+ <template v-if="props.isShowIcon" #leftIcon>+ <WalletsIcon+ :name="wallet.name"+ :color="wallet.color"+ />+ </template>++ <!-- Main -->+ <template v-if="!props.alt">+ <div class="grid grow gap-1">+ <div class="text-muted text-sm leading-none font-medium tracking-wide text-nowrap">+ {{ wallet.name }}+ </div>++ <!-- Rate -->+ <div+ v-if="props.isShowRate && wallet.currency !== currenciesStore.base && wallet.rate"+ class="opacity-90"+ >+ <Amount+ :amount="wallet.rate"+ :precision="2"+ :currencyCode="currenciesStore.base"+ :isShowBaseRate="false"+ align="left"+ variant="2xs"+ class="text-xs opacity-70"+ />+ </div>++ <div+ v-if="props.isShowCreditLimit && wallet.type === 'credit' && wallet.creditLimit"+ class="flex items-center gap-0.5 opacity-70"+ >+ <Amount+ :amount="wallet.creditLimit - Math.abs(wallet.amount)"+ :currencyCode="wallet.currency"+ :isShowBaseRate="false"+ :isShowSymbol="false"+ align="left"+ variant="2xs"+ />++ <div+ v-if="wallet.amount !== 0"+ class="text-2xs leading-none opacity-70"+ >+ /+ </div>++ <Amount+ v-if="wallet.amount !== 0"+ :amount="wallet.creditLimit"+ :currencyCode="wallet.currency"+ :isShowBaseRate="false"+ :isShowSymbol="false"+ align="left"+ variant="2xs"+ />+ </div>+ </div>++ <div class="pr-1">+ <Amount+ v-if="wallet.creditLimit"+ :amount="creditAmount"+ :currencyCode="wallet.currency"+ :isShowBaseRate="props.isShowBaseRate"+ variant="sm"+ />+ <Amount+ v-else+ :amount="wallet.amount"+ :currencyCode="wallet.currency"+ :isShowBaseRate="props.isShowBaseRate"+ variant="sm"+ />+ </div>+ </template>++ <!-- Alternative -->+ <template v-if="props.alt">+ <div class="grid grow gap-0.5">+ <div class="text-2 text-xs leading-none whitespace-nowrap">+ {{ wallet.name }}+ </div>++ <div v-if="!isSort">+ <Amount+ v-if="wallet.creditLimit"+ :amount="creditAmount"+ :currencyCode="wallet.currency"+ :isShowBaseRate="false"+ :isShowMinus="false"+ align="left"+ variant="2xs"+ />+ <Amount+ v-else+ :amount="wallet.amount"+ :currencyCode="wallet.currency"+ :isShowBaseRate="props.isShowBaseRate"+ :isShowMinus="false"+ align="left"+ variant="2xs"+ />+ </div>+ </div>++ <div+ v-if="isSort"+ class="sortHandle flex-center absolute right-0 h-full rounded-md px-3 group-hover:bg-(--item-6)"+ >+ <Icon name="lucide:grip-vertical" size="20" />+ </div>+ </template>+ </UiElement>+</template>diff --git a/app/components/wallets/SortModal.vue b/app/components/wallets/SortModal.vueindex b96033cb..1f7ed445 100644--- a/app/components/wallets/SortModal.vue+++ b/app/components/wallets/SortModal.vue@@ -19,43 +19,30 @@ function saveWalletsOrder(close: () => void) {</script><template>- <Teleport to="body">- <BottomSheet- isShow- drugClassesCustom="bottomSheetDrugClassesCustom"- @closed="emit('close')"- >- <template #handler="{ close }">- <BottomSheetHandler />- <BottomSheetClose @click="close" />- </template>-- <template #default="{ close }">- <div class="bottomSheetContent">- <UiTitleModal>{{ t('wallets.sortTitle') }}</UiTitleModal>-- <div ref="parent" class="scrollerBlock bottomSheetContentInside">- <WalletsItem- v-for="walletId in sortedWalletsIds"- :key="walletId"- :walletId- :wallet="walletsStore.itemsComputed[walletId]!"- alt- isSort- isShowIcon- />- </div>-- <div class="bottomSheetContentBottom">- <UiButtonAccent- rounded- @click="saveWalletsOrder(close)"- >- {{ t('base.save') }}- </UiButtonAccent>- </div>- </div>- </template>- </BottomSheet>- </Teleport>+ <BottomSheetModal @closed="emit('close')">+ <template #default="{ close }">+ <UiTitleModal>{{ t('wallets.sortTitle') }}</UiTitleModal>++ <div ref="parent" class="scrollerBlock bottomSheetContentInside">+ <WalletsItem+ v-for="walletId in sortedWalletsIds"+ :key="walletId"+ :walletId+ :wallet="walletsStore.itemsComputed[walletId]!"+ alt+ isSort+ isShowIcon+ />+ </div>++ <div class="bottomSheetContentBottom">+ <UiButtonAccent+ rounded+ @click="saveWalletsOrder(close)"+ >+ {{ t('base.save') }}+ </UiButtonAccent>+ </div>+ </template>+ </BottomSheetModal></template>diff --git a/app/components/wallets/Statistics.vue b/app/components/wallets/Statistics.vueindex e7f10a92..b75794c9 100644--- a/app/components/wallets/Statistics.vue+++ b/app/components/wallets/Statistics.vue@@ -19,9 +19,12 @@ const emit = defineEmits<{const { t } = useI18n()+const summaryKeys = ['total', 'withdrawal', 'available', 'excludeInTotal', 'archived'] as const+const typeKeys = ['cash', 'cashless', 'deposit', 'credit', 'crypto', 'debt'] as const+const itemsGrouped = computed(() => [- [props.counts.total, 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),+ summaryKeys.map(key => props.counts[key]).filter(i => i.isShow),+ typeKeys.map(key => props.counts[key]).filter(i => i.isShow),])</script>diff --git a/app/components/wallets/grouping.ts b/app/components/wallets/grouping.tsindex c48242a0..12f48e56 100644--- a/app/components/wallets/grouping.ts+++ b/app/components/wallets/grouping.ts@@ -47,9 +47,7 @@ export function buildWalletGroups(if (groupedBy === 'none')return false- const strategy = groupingStrategies[groupedBy as WalletsGroupedByExcludedNone]- if (!strategy)- return false+ const strategy = groupingStrategies[groupedBy]const primaryGrouped = groupWalletsByProperty(ids, wallets, strategy.primary)diff --git a/app/components/wallets/page/List.vue b/app/components/wallets/page/List.vueindex c76bdccb..516168ce 100644--- a/app/components/wallets/page/List.vue+++ b/app/components/wallets/page/List.vue@@ -1,17 +1,14 @@<script setup lang="ts">import { useStorage } from '@vueuse/core'-import type { TrnId } from '~/components/trns/types'-import type { WalletId, WalletsGroupedBy } from '~/components/wallets/types'+import type { WalletsGroupedBy } from '~/components/wallets/types'import { useCurrenciesStore } from '~/components/currencies/useCurrenciesStore'-import { useTrnsStore } from '~/components/trns/useTrnsStore'-import { useWalletContextMenu } from '~/components/wallets/useWalletContextMenu'+import { useWalletDelete } from '~/components/wallets/useWalletDelete'import { useWalletsCounts } from '~/components/wallets/useWalletsCounts'import { useWalletsFilter } from '~/components/wallets/useWalletsFilter'import { useWalletsGrouping } from '~/components/wallets/useWalletsGrouping'import { useWalletsStore } from '~/components/wallets/useWalletsStore'-import { showSuccessToast } from '~/composables/useStoreSync'const { t } = useI18n()const router = useRouter()@@ -23,53 +20,16 @@ useSeoMeta({const walletsStore = useWalletsStore()const currenciesStore = useCurrenciesStore()-const trnsStore = useTrnsStore()const isSortModalOpen = ref(false)-const isOpen = ref(false)-const deleteWalletId = ref<WalletId | null>(null)--const deleteTrnsCount = computed(() => {- if (!deleteWalletId.value)- return 0- return trnsStore.getStoreTrnsIds({- walletsIds: [deleteWalletId.value],- }).length-})--const deleteDescText = computed(() =>- deleteTrnsCount.value > 0 ? t('wallets.form.delete.alertWithTrns') : undefined,-)--const deleteHighlight = computed(() =>- deleteTrnsCount.value > 0 ? t('trns.plural', deleteTrnsCount.value) : undefined,-)--async function onDeleteConfirm() {- if (!deleteWalletId.value)- return-- const walletId = deleteWalletId.value- const trnsIds: TrnId[] = [...trnsStore.getStoreTrnsIds({- walletsIds: [walletId],- })]-- deleteWalletId.value = null- await walletsStore.deleteWallet(walletId, trnsIds)-- setTimeout(() => {- showSuccessToast(trnsIds.length > 0- ? 'wallets.form.delete.okWithTrns'- : 'wallets.form.delete.okWithoutTrns', trnsIds.length > 0- ? { length: trnsIds.length, trns: t('trns.plural', trnsIds.length) }- : undefined)- }, 300)-}--const { getWalletContextMenuItems } = useWalletContextMenu({- onDelete: (walletId: WalletId) => { deleteWalletId.value = walletId },-})+const {+ cancelDelete,+ confirmDelete,+ deleteInfo,+ deleteWalletId,+ requestDelete,+} = useWalletDelete()const groupedBy = useStorage<WalletsGroupedBy>('finapp-wallets-groupedBy', 'none')@@ -87,26 +47,15 @@ const {} = useWalletsCounts(selectedWalletsIdsWithCurrency)const {- groupedBySecondary,groupedWalletsWithIds,groupTabs,+ isSecondaryGroupingActive,toggleMap,toggleOpened,+ toggleSecondaryGrouping,typeGroupsStatus,walletsToggledMap,} = useWalletsGrouping(selectedWalletsIds, groupedBy)--function toggleSecondaryGrouping() {- if (groupedBy.value === 'currency')- groupedBySecondary.currency = !groupedBySecondary.currency- else if (groupedBy.value === 'type')- groupedBySecondary.type = !groupedBySecondary.type-}--const isSecondaryGroupingActive = computed(() =>- (groupedBy.value === 'currency' && groupedBySecondary.currency)- || (groupedBy.value === 'type' && groupedBySecondary.type),-)</script><template>@@ -255,19 +204,11 @@ const isSecondaryGroupingActive = computed(() =>v-if="groupedBy === 'none'"class="border-item-4 bg-item-2 rounded-xl md:max-w-lg">- <WalletsItem+ <WalletsPageListItemv-for="walletId in selectedWalletsIds":key="walletId"- :wallet="walletsStore.itemsComputed[walletId]!":walletId- :contextMenuItems="getWalletContextMenuItems(walletId)"- :lineWidth="2"- class="group"- isShowBaseRate- isShowIcon- isShowRate- isShowCreditLimit- @click="router.push(`/wallets/${walletId}`)"+ @delete="requestDelete"/></div>@@ -350,37 +291,21 @@ const isSecondaryGroupingActive = computed(() =></UiTitleDropRight></template>- <WalletsItem+ <WalletsPageListItemv-for="walletId in ids":key="walletId"- :contextMenuItems="getWalletContextMenuItems(walletId)"- :lineWidth="2"- :wallet="walletsStore.itemsComputed[walletId]!":walletId- class="group"- isShowBaseRate- isShowCreditLimit- isShowIcon- isShowRate- @click="router.push(`/wallets/${walletId}`)"+ @delete="requestDelete"/></UiToggleControlled></div><template v-else>- <WalletsItem+ <WalletsPageListItemv-for="walletId in content.ids":key="walletId"- :contextMenuItems="getWalletContextMenuItems(walletId)"- :lineWidth="2"- :wallet="walletsStore.itemsComputed[walletId]!":walletId- class="group"- isShowBaseRate- isShowCreditLimit- isShowIcon- isShowRate- @click="router.push(`/wallets/${walletId}`)"+ @delete="requestDelete"/></template></UiToggleControlled>@@ -393,10 +318,10 @@ const isSecondaryGroupingActive = computed(() =><LayoutConfirmModalv-if="deleteWalletId":title="t('wallets.form.delete.title')"- :description="deleteDescText"- :highlight="deleteHighlight"- @closed="deleteWalletId = null"- @confirm="onDeleteConfirm"+ :description="deleteInfo.descText"+ :highlight="deleteInfo.highlight"+ @closed="cancelDelete"+ @confirm="confirmDelete"/><!-- Sort Modal -->diff --git a/app/components/wallets/page/ListItem.vue b/app/components/wallets/page/ListItem.vuenew file mode 100644index 00000000..6d42d0d6--- /dev/null+++ b/app/components/wallets/page/ListItem.vue@@ -0,0 +1,36 @@+<script setup lang="ts">+import type { WalletId } from '~/components/wallets/types'++import { useWalletContextMenu } from '~/components/wallets/useWalletContextMenu'+import { useWalletsStore } from '~/components/wallets/useWalletsStore'++const props = defineProps<{+ walletId: WalletId+}>()++const emit = defineEmits<{+ delete: [walletId: WalletId]+}>()++const router = useRouter()+const walletsStore = useWalletsStore()++const { getWalletContextMenuItems } = useWalletContextMenu({+ onDelete: (id: WalletId) => emit('delete', id),+})+</script>++<template>+ <WalletsItem+ :wallet="walletsStore.itemsComputed[props.walletId]!"+ :walletId="props.walletId"+ :contextMenuItems="getWalletContextMenuItems(props.walletId)"+ :lineWidth="2"+ class="group"+ isShowBaseRate+ isShowCreditLimit+ isShowIcon+ isShowRate+ @click="router.push(`/wallets/${props.walletId}`)"+ />+</template>diff --git a/app/components/wallets/useWalletDelete.ts b/app/components/wallets/useWalletDelete.tsnew file mode 100644index 00000000..77f471ba--- /dev/null+++ b/app/components/wallets/useWalletDelete.ts@@ -0,0 +1,61 @@+import type { TrnId } from '~/components/trns/types'+import type { WalletId } from '~/components/wallets/types'++import { useTrnsStore } from '~/components/trns/useTrnsStore'+import { useWalletsStore } from '~/components/wallets/useWalletsStore'+import { showSuccessToast } from '~/composables/useStoreSync'++export function useWalletDelete() {+ const { t } = useI18n()+ const walletsStore = useWalletsStore()+ const trnsStore = useTrnsStore()++ const deleteWalletId = ref<WalletId | null>(null)++ const deleteInfo = computed(() => {+ if (!deleteWalletId.value)+ return { count: 0, descText: undefined as string | undefined, highlight: undefined as string | undefined }++ const count = trnsStore.getStoreTrnsIds({ walletsIds: [deleteWalletId.value] }).length+ return {+ count,+ descText: count > 0 ? t('wallets.form.delete.alertWithTrns') : undefined,+ highlight: count > 0 ? t('trns.plural', count) : undefined,+ }+ })++ function requestDelete(walletId: WalletId) {+ deleteWalletId.value = walletId+ }++ function cancelDelete() {+ deleteWalletId.value = null+ }++ async function confirmDelete() {+ if (!deleteWalletId.value)+ return++ const walletId = deleteWalletId.value+ const trnsIds: TrnId[] = [...trnsStore.getStoreTrnsIds({ walletsIds: [walletId] })]++ deleteWalletId.value = null+ await walletsStore.deleteWallet(walletId, trnsIds)++ setTimeout(() => {+ showSuccessToast(trnsIds.length > 0+ ? 'wallets.form.delete.okWithTrns'+ : 'wallets.form.delete.okWithoutTrns', trnsIds.length > 0+ ? { length: trnsIds.length, trns: t('trns.plural', trnsIds.length) }+ : undefined)+ }, 300)+ }++ return {+ cancelDelete,+ confirmDelete,+ deleteInfo,+ deleteWalletId,+ requestDelete,+ }+}diff --git a/app/components/wallets/useWalletsFilter.ts b/app/components/wallets/useWalletsFilter.tsindex 77316831..adff6014 100644--- a/app/components/wallets/useWalletsFilter.ts+++ b/app/components/wallets/useWalletsFilter.ts@@ -2,7 +2,6 @@ import type { Ref } from 'vue'import { useStorage } from '@vueuse/core'-import type { CurrencyCode } from '~/components/currencies/types'import type { WalletId, WalletsCurrencyFiltered, WalletsGroupedBy, WalletType, WalletViewTypes } from '~/components/wallets/types'import { filterWalletsByCurrency, filterWalletsByViewType } from '~/components/wallets/filters'@@ -26,17 +25,8 @@ export function useWalletsFilter(groupedBy: Ref<WalletsGroupedBy>) {filterWalletsByViewType(selectedWalletsIdsWithCurrency.value, walletsStore.itemsComputed, walletViewType.value),)- function onSelectFilterCurrency(code: CurrencyCode, toggle?: () => void) {- if (currencyFiltered.value === code && toggle)- toggle()-- walletViewType.value = 'total'- currencyFiltered.value = code- }-return {currencyFiltered,- onSelectFilterCurrency,selectedWalletsIds,selectedWalletsIdsWithCurrency,setWalletViewType,diff --git a/app/components/wallets/useWalletsGrouping.ts b/app/components/wallets/useWalletsGrouping.tsindex e3deb837..44ba55c7 100644--- a/app/components/wallets/useWalletsGrouping.ts+++ b/app/components/wallets/useWalletsGrouping.ts@@ -27,11 +27,7 @@ export function useWalletsGrouping(})const groupedWalletsWithIds = computed<GroupedWallets | false>(() => {- let useSecondary = false- if (groupedBy.value === 'currency')- useSecondary = !!groupedBySecondary.value.currency- else if (groupedBy.value === 'type')- useSecondary = !!groupedBySecondary.value.type+ const useSecondary = groupedBy.value !== 'none' && !!groupedBySecondary.value[groupedBy.value]return buildWalletGroups(selectedWalletsIds.value,@@ -89,12 +85,22 @@ export function useWalletsGrouping(return items})+ function toggleSecondaryGrouping() {+ if (groupedBy.value !== 'none')+ groupedBySecondary.value[groupedBy.value] = !groupedBySecondary.value[groupedBy.value]+ }++ const isSecondaryGroupingActive = computed(() =>+ groupedBy.value !== 'none' && !!groupedBySecondary.value[groupedBy.value],+ )+return {- groupedBySecondary,groupedWalletsWithIds,groupTabs,+ isSecondaryGroupingActive,toggleMap,toggleOpened,+ toggleSecondaryGrouping,typeGroupsStatus,walletsToggledMap,}