Open source personal finance application
refactor: improve date handling and UI consistency in transaction forms
Ilya Komichev51076f62ac57
diff --git a/app/components/date/useStatDate.ts b/app/components/date/useStatDate.tsindex 963b3621..698e193f 100644--- a/app/components/date/useStatDate.ts+++ b/app/components/date/useStatDate.ts@@ -157,12 +157,14 @@ export function useStatDate({function modifyRange(modification: number) {resetCustomAndMaxRangeParams()- params.value.rangeDuration += modification+ if (params.value.rangeDuration > 1)+ params.value.rangeDuration += modification+params.value.rangeOffset = 0}const plusRange = () => modifyRange(1)- const minusRange = () => params.value.rangeDuration > 1 && modifyRange(-1)+ const minusRange = () => modifyRange(-1)function setInterval({ intervalsBy, intervalsDuration }: Grouped) {resetCustomAndMaxRangeParams()diff --git a/app/components/stat/Average.vue b/app/components/stat/Average.vueindex 1b0a84d6..b59c70fe 100644--- a/app/components/stat/Average.vue+++ b/app/components/stat/Average.vue@@ -61,7 +61,7 @@ const last = computed(() => {</script><template>- <div class="flex items-start gap-4 pb-2 pl-3 md:max-w-lg">+ <div class="grid gap-4 pb-2 pl-3 md:max-w-lg"><div class="grid w-full grow gap-1 pb-[2px]"><UiTitle6 class="text-nowrap !leading-3">{{ t('money.average') }}diff --git a/app/components/stat/Header.vue b/app/components/stat/Header.vueindex 82f69e98..90e71506 100644--- a/app/components/stat/Header.vue+++ b/app/components/stat/Header.vue@@ -77,17 +77,19 @@ const statConfigModal: Ref<StatConfigModal> = ref({</div></template>- <template #after>+ <template #selected><divv-if="props.menu"- class="px-2 sm:pb-1 md:py-1 lg:px-4 2xl:px-8"+ class=""><StatMenu:active="props.menu.active"@click="props.menu.click"/></div>+ </template>+ <template #after><divv-if="filter.isShow?.value || statConfig.config.value.wallets.isShow || $slots.summary"class="grid gap-2 px-2 pb-0 lg:px-4 2xl:px-8"diff --git a/app/components/stat/Menu.vue b/app/components/stat/Menu.vueindex 9744f959..c32548dd 100644--- a/app/components/stat/Menu.vue+++ b/app/components/stat/Menu.vue@@ -57,15 +57,19 @@ watch(() => props.active, () => {</script><template>- <UiTabs2>- <UiTabsItem4+ <div class="flex gap-2">+ <divv-for="item in menu":key="item.id"- :isActive="item.id === props.active"- class="text-nowrap"+ class="text-nowrap rounded-lg px-3 py-1.5 text-sm font-medium"+ :class="[{+ 'rounded-none border-b-2 !border-accent-1 text-1': item.id === props.active,+ 'text-2 hover:bg-item-5': item.id !== props.active,+ },+ ]"@click="onClickStatMenu(item.id)">{{ item.name }}- </UiTabsItem4>- </UiTabs2>+ </div>+ </div></template>diff --git a/app/components/stat/chart/Button.vue b/app/components/stat/chart/Button.vuedeleted file mode 100644index 813c4d26..00000000--- a/app/components/stat/chart/Button.vue+++ /dev/null@@ -1,24 +0,0 @@-<script setup lang="ts">-import { getStyles } from '~/components/ui/getStyles'--const props = defineProps<{- isActive?: boolean-}>()-const emit = defineEmits<{- click: [e: Event]-}>()-</script>--<template>- <div- :class="[- getStyles('item', ['link', 'center2', 'minh3', 'rounded3']), {- '!bg-transparent !text-accent-1': props.isActive,- },- ]"- class="px-2.5 text-2xs"- @click="(e: Event) => emit('click', e)"- >- <slot />- </div>-</template>diff --git a/app/components/stat/chart/Intervals.vue b/app/components/stat/chart/Intervals.vueindex 8c372efd..4117aca5 100644--- a/app/components/stat/chart/Intervals.vue+++ b/app/components/stat/chart/Intervals.vue@@ -44,13 +44,14 @@ const items = computed(() => {v-if="items.length > 1"class="flex min-h-8 gap-0 pl-2">- <StatChartButton+ <DateLinkItemv-for="item in items":key="item.value":isActive="props.period === item.value"+ variant="small"@click="emit('onChangePeriod', item.value)">{{ item.label }}- </StatChartButton>+ </DateLinkItem></div></template>diff --git a/app/components/stat/chart/TypeSelector.vue b/app/components/stat/chart/TypeSelector.vuedeleted file mode 100644index 189d57a7..00000000--- a/app/components/stat/chart/TypeSelector.vue+++ /dev/null@@ -1,28 +0,0 @@-<script setup lang="ts">-import type { ChartType } from '~/components/stat/chart/types'--import { useStatChart } from '~/components/stat/chart/useStatChart'--const props = defineProps<{- chartType: ChartType-}>()--const emit = defineEmits<{- click: [e: ChartType]-}>()--const { chartTypes } = useStatChart()-</script>--<template>- <div class="flex">- <StatChartButton- v-for="item in chartTypes"- :key="item.value"- :isActive="props.chartType === item.value"- @click="emit('click', item.value)"- >- {{ item.label }}- </StatChartButton>- </div>-</template>diff --git a/app/components/trnForm/Bottom.vue b/app/components/trnForm/Bottom.vueindex 2c5581ca..2e7865e0 100644--- a/app/components/trnForm/Bottom.vue+++ b/app/components/trnForm/Bottom.vue@@ -124,7 +124,4 @@ onMounted(init)<div class="trnForm__pagination" /></div></BottomSheet>-- <!-- Modals -->- <LazyTrnFormModalDescription v-if="trnsFormStore.modal.description" /></template>diff --git a/app/components/trnForm/Date.vue b/app/components/trnForm/Date.vueindex 82091355..060d8c5b 100644--- a/app/components/trnForm/Date.vue+++ b/app/components/trnForm/Date.vue@@ -4,13 +4,11 @@ import { addDays, isSameDay, subDays } from 'date-fns'import { useDateFormats } from '~/components/date/useDateFormats'import { useTrnsFormStore } from '~/components/trnForm/useTrnsFormStore'+const { t } = useI18n()const trnsFormStore = useTrnsFormStore()const { formatDate } = useDateFormats()-const formattedDate = computed(() => {- const date = formatDate(trnsFormStore.values.date, 'full')- return `${date.day} ${date.month} <div class="text-2xs font-regular leading-none">${date.weekday}</div>`-})+const formattedDate = computed(() => formatDate(trnsFormStore.values.date, 'full'))const isToday = computed(() => {return isSameDay(new Date(trnsFormStore.values.date), new Date())@@ -27,20 +25,38 @@ function changeDate(way: 'prev' | 'next' | 'today') {trnsFormStore.values.date = newDate}++const isShow = ref(false)</script><template>- <div class="-ml-1 flex gap-1">- <UPopover class="grow">- <div- class="grid gap-1 rounded-md p-2 text-sm font-medium leading-none text-3 hocus:bg-item-5"- v-html="formattedDate"- />-- <template #panel="{ close }">- <TrnFormCalendar :hide="close" />+ <div class="flex gap-1">+ <BottomSheetOrDropdown+ :title="t('common.date')"+ :isOpen="isShow"+ class="grow"+ placement="bottom-end"+ drugClassesCustom="max-w-xs"+ @onOpenModal="isShow = true"+ @onCloseModal="isShow = false"+ >+ <template #trigger>+ <UiItem1 class="grid grow !justify-start p-2 text-2">+ <div class="text-sm text-1">+ {{ formattedDate.day }} {{ formattedDate.month }}+ </div>+ <div class="font-regular text-2xs leading-none">+ {{ formattedDate.weekday }}+ </div>+ </UiItem1>+ </template>++ <template #content="{ close }">+ <div class="min-w-80">+ <TrnFormCalendar :hide="close" />+ </div></template>- </UPopover>+ </BottomSheetOrDropdown><StatDateNav:isShowNavHome="!isToday"diff --git a/app/components/trnForm/Sidebar.vue b/app/components/trnForm/Sidebar.vueindex dff50f5e..e3fb86c3 100644--- a/app/components/trnForm/Sidebar.vue+++ b/app/components/trnForm/Sidebar.vue@@ -92,9 +92,6 @@ watch(isShow, (v) => {</div></div></Transition>-- <!-- Modals -->- <LazyTrnFormModalDescription v-if="trnsFormStore.modal.description" /></template><style scoped>diff --git a/app/components/trnForm/main/ActionSide.vue b/app/components/trnForm/main/ActionSide.vueindex 4db19330..4726b84c 100644--- a/app/components/trnForm/main/ActionSide.vue+++ b/app/components/trnForm/main/ActionSide.vue@@ -30,15 +30,12 @@ async function onClickSubmit() {<template><div:class="{- '!border-transparent !bg-accent-1/80 !text-icon-primary hocus:!bg-accent-1': !isMath && isSubmittable,- '!border-item-3 !text-2': !isSubmittable,- '!text-2': isMath,+ '!hocus:bg-accent-1 !bg-accent-1/80 text-icon-primary': !isMath && isSubmittable,+ 'text-2': !isSubmittable || isMath,}"- class="flex size-full items-center justify-center rounded-xl border border-item-4 p-1 py-4 text-center text-4xl text-1 transition hocus:scale-[1.02] hocus:bg-item-5"+ class="flex size-full items-center justify-center rounded-xl bg-item-4 p-1 py-4 text-center text-4xl text-1 transition hocus:scale-[1.02] hocus:bg-item-5"@click="onClickSubmit">- <Icon v-if="!isMath && isSubmittable" name="mdi:check" />- <Icon v-else-if="isMath" name="mdi:equal" />- <Icon v-else name="mdi:palm-tree" />+ <Icon :name="isMath ? 'lucide:equal' : 'lucide:check'" size="40" /></div></template>diff --git a/app/components/trnForm/main/AmountTransfer.vue b/app/components/trnForm/main/AmountTransfer.vueindex 5a05d07a..a0c63eea 100644--- a/app/components/trnForm/main/AmountTransfer.vue+++ b/app/components/trnForm/main/AmountTransfer.vue@@ -43,24 +43,57 @@ watch(() => trnsFormStore.values.trnType,(trnType) => {if (trnType === TrnType.Transfer) {- incomeWalletId.value && (trnsFormStore.values.incomeWalletId = incomeWalletId.value)- expenseWalletId.value && (trnsFormStore.values.expenseWalletId = expenseWalletId.value)+ if (!trnsFormStore.values.incomeWalletId)+ incomeWalletId.value && (trnsFormStore.values.incomeWalletId = incomeWalletId.value)++ if (!trnsFormStore.values.expenseWalletId)+ expenseWalletId.value && (trnsFormStore.values.expenseWalletId = expenseWalletId.value)++ if (trnsFormStore.values.amount[1] === 0) {+ trnsFormStore.values.amount[1] = trnsFormStore.values.amount[0]+ trnsFormStore.values.amountRaw[1] = trnsFormStore.values.amountRaw[0]+ }}},{ immediate: true },)++function switchWallets() {+ const incomeWalletId = trnsFormStore.values.incomeWalletId+ const expenseWalletId = trnsFormStore.values.expenseWalletId+ const incomeAmount = trnsFormStore.values.amount[1]+ const incomeAmountRaw = trnsFormStore.values.amountRaw[1]+ const expenseAmount = trnsFormStore.values.amount[2]+ const expenseAmountRaw = trnsFormStore.values.amountRaw[2]++ trnsFormStore.values.incomeWalletId = expenseWalletId+ trnsFormStore.values.expenseWalletId = incomeWalletId+ trnsFormStore.values.amount[1] = expenseAmount+ trnsFormStore.values.amountRaw[1] = expenseAmountRaw+ trnsFormStore.values.amount[2] = incomeAmount+ trnsFormStore.values.amountRaw[2] = incomeAmountRaw+}++function copyAmount() {+ const incomeAmount = trnsFormStore.values.amount[1]+ const incomeAmountRaw = trnsFormStore.values.amountRaw[1]++ trnsFormStore.values.amount[2] = incomeAmount+ trnsFormStore.values.amountRaw[2] = incomeAmountRaw+}</script><template>- <div class="pb-2">- <div class="flex flex-col">+ <div class="">+ <template+ v-for="(item, slug) in items"+ :key="slug"+ ><div- v-for="(item, slug) in items"- :key="slug":class="[{- 'border-accent-1': trnsFormStore.values.transferType === item.transferType,+ '!border-accent-1/50': trnsFormStore.values.transferType === item.transferType,}, getStyles('item', ['rounded'])]"- class="overflow-hidden border border-transparent"+ class="-m-1 grid gap-2 overflow-hidden border border-transparent p-2"@click="trnsFormStore.onChangeTransferType(item.transferType)"><div class="flex items-center gap-2 whitespace-nowrap">@@ -99,14 +132,27 @@ watch(:key="item.amountsIdx":amount="trnsFormStore.values.amount[item.amountsIdx]":amountRaw="trnsFormStore.values.amountRaw[item.amountsIdx]"- :highlight="item.transferType === 1 ? 'expense' : 'income'"+ :highlight="item.transferType === 0 ? 'expense' : 'income'":isShowSum="trnsFormStore.getIsShowSum()"isTransfer- class="pb-2 pt-1"@onChange="trnsFormStore.onChangeAmount"/></div>- </div>++ <!-- Actions -->+ <div+ v-if="item.transferType === 0"+ class="flex justify-center gap-1 pb-1 pt-3"+ >+ <UiItem1 @click="switchWallets">+ <Icon name="lucide:arrow-up-down" size="24" />+ </UiItem1>++ <UiItem1 @click="copyAmount">+ <Icon name="lucide:clipboard-paste" size="24" />+ </UiItem1>+ </div>+ </template></div></template>diff --git a/app/components/trnForm/main/Calculator.vue b/app/components/trnForm/main/Calculator.vueindex 964c8389..96307276 100644--- a/app/components/trnForm/main/Calculator.vue+++ b/app/components/trnForm/main/Calculator.vue@@ -90,19 +90,7 @@ onLongPress(</div><div class="grid grid-rows-[auto,1fr] gap-3">- <!-- Description -->- <TrnFormMainCalculatorButton- class="relative"- @click="trnsFormStore.openTrnFormModal('description')"- >- <Icon name="mdi:comment-text-outline" />- <div- v-if="!!trnsFormStore.values.desc"- class="absolute right-1 top-1 aspect-square w-2 rounded-full bg-accent-1"- />- </TrnFormMainCalculatorButton>-- <!-- Action -->+ <TrnFormMainDescription /><TrnFormMainActionSide /></div></div>diff --git a/app/components/trnForm/main/Description.vue b/app/components/trnForm/main/Description.vuenew file mode 100644index 00000000..600ad251--- /dev/null+++ b/app/components/trnForm/main/Description.vue@@ -0,0 +1,57 @@+<script setup lang="ts">+import { useTrnsFormStore } from '~/components/trnForm/useTrnsFormStore'++const { t } = useI18n()+const trnsFormStore = useTrnsFormStore()++const desc = ref('')+onMounted(() => desc.value = trnsFormStore.values.desc ?? '')++function onSave(close: () => void) {+ trnsFormStore.values.desc = desc.value+ close()+}+</script>++<template>+ <BottomSheetOrDropdown+ :title="t('trnForm.description.title')"+ :isOpen="trnsFormStore.modal.description"+ class="grow"+ placement="bottom-end"+ drugClassesCustom="max-w-md"+ @onOpenModal="trnsFormStore.openTrnFormModal('description')"+ @onCloseModal="trnsFormStore.closeTrnFormModal('description')"+ >+ <template #trigger>+ <TrnFormMainCalculatorButton class="relative">+ <Icon name="lucide:message-square" size="26" />+ <div+ v-if="!!trnsFormStore.values.desc"+ class="absolute right-1 top-1 aspect-square w-2 rounded-full bg-accent-1"+ />+ </TrnFormMainCalculatorButton>+ </template>++ <template #content="{ close }">+ <div class="grid min-w-80 gap-4">+ <div class="px-2">+ <FormTextarea+ :value="desc"+ :placeholder="t('trnForm.description.placeholder')"+ @updateValue="(value: string) => desc = value"+ />+ </div>++ <div class="flex-center px-2 pb-4 md:pb-0">+ <UiButtonAccent+ rounded+ @click="onSave(close)"+ >+ {{ t('base.save') }}+ </UiButtonAccent>+ </div>+ </div>+ </template>+ </BottomSheetOrDropdown>+</template>diff --git a/app/components/trnForm/modal/Description.vue b/app/components/trnForm/modal/Description.vuedeleted file mode 100644index 19a059c0..00000000--- a/app/components/trnForm/modal/Description.vue+++ /dev/null@@ -1,49 +0,0 @@-<script setup lang="ts">-import { useTrnsFormStore } from '~/components/trnForm/useTrnsFormStore'--const { t } = useI18n()-const trnsFormStore = useTrnsFormStore()--const desc = ref('')-onMounted(() => desc.value = trnsFormStore.values.desc ?? '')--function onSave(close: () => void) {- trnsFormStore.values.desc = desc.value- close()-}-</script>--<template>- <Teleport to="body">- <BottomSheet- isShow- drugClassesCustom="bottomSheetDrugClassesCustom"- @closed="trnsFormStore.closeTrnFormModal('description')"- >- <template #handler="{ close }">- <BottomSheetHandler />- <BottomSheetClose @onClick="close" />- </template>-- <template #default="{ close }">- <div class="bottomSheetContent">- <UiTitleModal>{{ t('trnForm.description.title') }}</UiTitleModal>-- <div class="px-2">- <FormTextarea- :value="desc"- :placeholder="t('trnForm.description.placeholder')"- @updateValue="(value: string) => desc = value"- />- </div>-- <div class="flex-center p-2">- <UiButtonAccent @click="onSave(close)">- {{ t('base.save') }}- </UiButtonAccent>- </div>- </div>- </template>- </BottomSheet>- </Teleport>-</template>diff --git a/app/components/trnForm/useTrnsFormStore.ts b/app/components/trnForm/useTrnsFormStore.tsindex f3085592..0f0dc4f4 100644--- a/app/components/trnForm/useTrnsFormStore.ts+++ b/app/components/trnForm/useTrnsFormStore.ts@@ -56,12 +56,7 @@ export const useTrnsFormStore = defineStore('trnForm', () => {})const modal = ref({- categories: false,description: false,- transferFrom: false,- transferTo: false,- trn: false,- wallets: false,})function closeTrnFormModal(name: keyof typeof modal.value) {diff --git a/app/components/ui/Header.vue b/app/components/ui/Header.vueindex 4c7788ee..a3000b0a 100644--- a/app/components/ui/Header.vue+++ b/app/components/ui/Header.vue@@ -1,5 +1,5 @@<template>- <div class="mb-2 flex min-h-12 max-w-7xl items-center border-b border-item-4 px-2 sm:min-h-14 lg:px-4 2xl:px-8">+ <div class="mb-2 grid min-h-12 max-w-7xl items-center border-b border-item-4 px-2 sm:min-h-14 lg:px-4 2xl:px-8"><div class="flex grow items-center gap-2"><slot />@@ -7,10 +7,9 @@<slot name="actions" /></div></div>-<divv-if="$slots.selected"- class="py-1"+ class=""><slot name="selected" /></div>@@ -18,7 +17,7 @@<divv-if="$slots.after"- class="grid gap-2 pb-1"+ class="grid gap-2 pb-2 pt-1"><slot name="after" /></div>diff --git a/app/components/ui/Item1.vue b/app/components/ui/Item1.vueindex 683b7af3..a8081386 100644--- a/app/components/ui/Item1.vue+++ b/app/components/ui/Item1.vue@@ -2,7 +2,7 @@import { getStyles } from '~/components/ui/getStyles'const { variant = 'icon' } = defineProps<{- variant: 'icon' | 'text'+ variant?: 'icon' | 'text'}>()const emit = defineEmits<{diff --git a/app/layouts/default.vue b/app/layouts/default.vueindex a41b0656..7151b063 100644--- a/app/layouts/default.vue+++ b/app/layouts/default.vue@@ -140,7 +140,7 @@ watch(shift_d!, (v) => {to="body"><TrnFormBottom v-if="width < 767" />- <TrnFormSidebar v-if="width > 767" />+ <TrnFormSidebar v-if="width >= 767" /></Teleport></div></template>diff --git a/i18n/locales/ru-RU.js b/i18n/locales/ru-RU.jsindex d4bf8de8..25fdf6c3 100644--- a/i18n/locales/ru-RU.js+++ b/i18n/locales/ru-RU.js@@ -313,7 +313,7 @@ export default {calcTrnButton: 'Посчитать результат',createTrn: 'Создать транзакцию',description: {- placeholder: 'Напишите описание...',+ placeholder: 'Напишите...',title: 'Описание',},filterAll: 'Все',