Skip to content

Open source personal finance application

2025.01.18-22:56

Ilya Komichev9949492d7eb4
diff --git a/app/components/date/LinkItem.vue b/app/components/date/LinkItem.vue
index 7d47233e..4de20f1a 100644
--- a/app/components/date/LinkItem.vue
+++ b/app/components/date/LinkItem.vue
@@ -1,9 +1,12 @@
<script setup lang="ts">
import { getStyles } from '~/components/ui/getStyles'
-const props = defineProps<{
+export type DateLinkItemProps = {
isActive?: boolean
-}>()
+ variant?: 'small'
+}
+
+const props = defineProps<DateLinkItemProps>()
const emit = defineEmits<{
click: [e: Event]
}>()
@@ -12,10 +15,10 @@ const emit = defineEmits<{
<template>
<div
:class="[
- getStyles('item', ['link', '_bg', 'padding2', 'center2', 'minh3', 'minw4', 'rounded3']),
- {
- 'text-accent-1': props.isActive,
- },
+ getStyles('item', ['link', props.variant === 'small' ? '' : 'alt', 'center2', 'minh3', 'rounded4']),
+ { 'text-accent-1': props.isActive },
+ { 'px-2 text-2xs': props.variant === 'small' },
+ { 'px-3': props.variant !== 'small' },
]"
class="text-nowrap rounded-full font-primary text-xs leading-none"
@click="(e: Event) => emit('click', e)"
diff --git a/app/components/date/Ranges.vue b/app/components/date/Ranges.vue
index 45db6f9d..fea670b1 100644
--- a/app/components/date/Ranges.vue
+++ b/app/components/date/Ranges.vue
@@ -1,62 +1,171 @@
<script setup lang="ts">
+import type { DateLinkItemProps } from '~/components/date/LinkItem.vue'
import type { IntervalGroupedLabel, StatDateProvider } from '~/components/date/types'
+const props = defineProps<{
+ isShowMaxRange?: boolean
+ isShowRangeAdjust?: boolean
+ itemProps?: Partial<DateLinkItemProps>
+ statDate: StatDateProvider
+ view: 'periods' | 'presets' | 'maximum'
+}>()
+
const emit = defineEmits<{
onClose: []
}>()
-const statDate = inject('statDate') as StatDateProvider
-
const { t } = useI18n()
-const intervalGroups = computed<IntervalGroupedLabel[]>(() => [
- {
- intervalsBy: 'day',
- intervalsDuration: 1,
- label: t('dates.day.simple'),
- rangeBy: 'day',
- rangeDuration: 1,
- },
- {
- intervalsBy: 'day',
- intervalsDuration: 1,
- label: t('dates.week.simple'),
- rangeBy: 'week',
- rangeDuration: 1,
- },
- {
- intervalsBy: 'day',
- intervalsDuration: 1,
- label: t('dates.month.simple'),
- rangeBy: 'month',
- rangeDuration: 1,
- },
- {
- intervalsBy: 'month',
- intervalsDuration: 1,
- label: t('dates.year.simple'),
- rangeBy: 'year',
- rangeDuration: 1,
- },
-])
+const items = computed(() => {
+ if (props.view === 'maximum')
+ return false
+
+ const elements: Record<Exclude<typeof props.view, 'maximum'>, IntervalGroupedLabel[]> = {
+ periods: [{
+ intervalsBy: 'day',
+ intervalsDuration: 1,
+ label: t('dates.day.simple'),
+ rangeBy: 'day',
+ rangeDuration: 1,
+ }, {
+ intervalsBy: 'day',
+ intervalsDuration: 1,
+ label: t('dates.week.simple'),
+ rangeBy: 'week',
+ rangeDuration: 1,
+ }, {
+ intervalsBy: 'day',
+ intervalsDuration: 1,
+ label: t('dates.month.simple'),
+ rangeBy: 'month',
+ rangeDuration: 1,
+ }, {
+ intervalsBy: 'month',
+ intervalsDuration: 1,
+ label: t('dates.year.simple'),
+ rangeBy: 'year',
+ rangeDuration: 1,
+ }],
+
+ presets: [{
+ intervalsBy: 'day',
+ intervalsDuration: 1,
+ label: `7${t('dates.day.short')}`,
+ rangeBy: 'day',
+ rangeDuration: 7,
+ }, {
+ intervalsBy: 'day',
+ intervalsDuration: 1,
+ label: `14${t('dates.day.short')}`,
+ rangeBy: 'day',
+ rangeDuration: 14,
+ }, {
+ intervalsBy: 'day',
+ intervalsDuration: 1,
+ label: `30${t('dates.day.short')}`,
+ rangeBy: 'day',
+ rangeDuration: 30,
+ }, {
+ intervalsBy: 'week',
+ intervalsDuration: 1,
+ label: `3${t('dates.month.short')}`,
+ rangeBy: 'month',
+ rangeDuration: 3,
+ }, {
+ intervalsBy: 'month',
+ intervalsDuration: 1,
+ label: `6${t('dates.month.short')}`,
+ rangeBy: 'month',
+ rangeDuration: 6,
+ }, {
+ intervalsBy: 'month',
+ intervalsDuration: 1,
+ label: `12${t('dates.month.short')}`,
+ rangeBy: 'month',
+ rangeDuration: 12,
+ }],
+ }
+
+ return elements[props.view]
+})
function isRangeSelected(rd: IntervalGroupedLabel) {
- return rd.rangeDuration === statDate.params.value.rangeDuration && rd.rangeBy === statDate.params.value.rangeBy
+ return rd.rangeDuration === props.statDate.params.value.rangeDuration && rd.rangeBy === props.statDate.params.value.rangeBy
}
function selectRange(igl: IntervalGroupedLabel) {
- statDate.setRangeByPeriod(igl)
+ props.statDate.setRangeByPeriod(igl)
+ emit('onClose')
+}
+
+function selectMaxRange(isSkipEmpty = false) {
+ props.statDate.setMaxRange(isSkipEmpty)
emit('onClose')
}
</script>
<template>
- <DateLinkItem
- v-for="igl in intervalGroups"
- :key="igl.label"
- :isActive="isRangeSelected(igl)"
- @click="selectRange(igl)"
+ <div
+ class="flex overflow-hidden"
+ :class="{
+ 'gap-1': props.itemProps?.variant !== 'small',
+ }"
>
- {{ igl.label }}
- </DateLinkItem>
+ <template v-if="(view === 'periods' || view === 'presets') && items">
+ <DateLinkItem
+ v-for="igl in items"
+ v-bind="props.itemProps"
+ :key="igl.label"
+ :isActive="isRangeSelected(igl)"
+ @click="selectRange(igl)"
+ >
+ {{ igl.label }}
+ </DateLinkItem>
+ </template>
+
+ <template v-if="props.isShowRangeAdjust">
+ <DateLinkItem
+ v-bind="props.itemProps"
+ @click="props.statDate.minusRange"
+ >
+ -
+ </DateLinkItem>
+ <DateLinkItemNoBg>
+ {{ props.statDate.params.value.rangeDuration }}
+ </DateLinkItemNoBg>
+ <DateLinkItem
+ v-bind="props.itemProps"
+ @click="props.statDate.plusRange"
+ >
+ +
+ </DateLinkItem>
+ </template>
+
+ <template v-if="props.view === 'maximum'">
+ <DateLinkItem
+ v-bind="props.itemProps"
+ :isActive="props.statDate.params.value.isShowMaxRange && !props.statDate.params.value.isSkipEmpty"
+ @click="selectMaxRange(false)"
+ >
+ {{ t('all') }}
+ </DateLinkItem>
+ <DateLinkItem
+ v-bind="props.itemProps"
+ :isActive="props.statDate.params.value.isShowMaxRange && props.statDate.params.value.isSkipEmpty"
+ @click="selectMaxRange(true)"
+ >
+ {{ t('allSkipEmpty') }}
+ </DateLinkItem>
+ </template>
+ </div>
</template>
+
+<i18n lang="yaml">
+ en:
+ all: All
+ allSkipEmpty: Maximum
+
+ ru:
+ all: Все
+ allSkipEmpty: Максимально
+</i18n>
diff --git a/app/components/date/Ranges2.vue b/app/components/date/Ranges2.vue
deleted file mode 100644
index aff97bcf..00000000
--- a/app/components/date/Ranges2.vue
+++ /dev/null
@@ -1,68 +0,0 @@
-<script setup lang="ts">
-import type { IntervalGroupedLabel, StatDateProvider } from '~/components/date/types'
-
-const emit = defineEmits<{
- onClose: []
-}>()
-
-const statDate = inject('statDate') as StatDateProvider
-const { t } = useI18n()
-
-const intervalGroups = computed<IntervalGroupedLabel[]>(() => [{
- intervalsBy: 'day',
- intervalsDuration: 1,
- label: `7${t('dates.day.short')}`,
- rangeBy: 'day',
- rangeDuration: 7,
-}, {
- intervalsBy: 'day',
- intervalsDuration: 1,
- label: `14${t('dates.day.short')}`,
- rangeBy: 'day',
- rangeDuration: 14,
-}, {
- intervalsBy: 'day',
- intervalsDuration: 1,
- label: `30${t('dates.day.short')}`,
- rangeBy: 'day',
- rangeDuration: 30,
-}, {
- intervalsBy: 'week',
- intervalsDuration: 1,
- label: `3${t('dates.month.short')}`,
- rangeBy: 'month',
- rangeDuration: 3,
-}, {
- intervalsBy: 'month',
- intervalsDuration: 1,
- label: `6${t('dates.month.short')}`,
- rangeBy: 'month',
- rangeDuration: 6,
-}, {
- intervalsBy: 'month',
- intervalsDuration: 1,
- label: `12${t('dates.month.short')}`,
- rangeBy: 'month',
- rangeDuration: 12,
-}])
-
-function isRangeSelected(rd: IntervalGroupedLabel) {
- return rd.rangeDuration === statDate.params.value.rangeDuration && rd.rangeBy === statDate.params.value.rangeBy
-}
-
-function selectRange(igl: IntervalGroupedLabel) {
- statDate.setRangeByPeriod(igl)
- emit('onClose')
-}
-</script>
-
-<template>
- <DateLinkItem
- v-for="igl in intervalGroups"
- :key="igl.label"
- :isActive="isRangeSelected(igl)"
- @click="selectRange(igl)"
- >
- {{ igl.label }}
- </DateLinkItem>
-</template>
diff --git a/app/components/date/useStatDate.ts b/app/components/date/useStatDate.ts
index 6399fdee..963b3621 100644
--- a/app/components/date/useStatDate.ts
+++ b/app/components/date/useStatDate.ts
@@ -162,7 +162,7 @@ export function useStatDate({
}
const plusRange = () => modifyRange(1)
- const minusRange = () => modifyRange(-1)
+ const minusRange = () => params.value.rangeDuration > 1 && modifyRange(-1)
function setInterval({ intervalsBy, intervalsDuration }: Grouped) {
resetCustomAndMaxRangeParams()
diff --git a/app/components/stat/Item.vue b/app/components/stat/Item.vue
index baae123f..9a6675ee 100644
--- a/app/components/stat/Item.vue
+++ b/app/components/stat/Item.vue
@@ -216,7 +216,7 @@ function getIntervalsData(trnsIds: TrnId[], intervalsInRange: Range[]) {
<StatDateQuick v-if="statConfig.config.value.date.isShowQuick" />
</StatChartWrap>
- <div class="grid pb-5 md:max-w-lg">
+ <div class="grid pb-3 md:max-w-lg">
<StatDateNavigation />
</div>
diff --git a/app/components/stat/date/Quick.vue b/app/components/stat/date/Quick.vue
index a5049b56..43b65711 100644
--- a/app/components/stat/date/Quick.vue
+++ b/app/components/stat/date/Quick.vue
@@ -29,89 +29,39 @@ onMounted(() => {
touchStartPreventDefault: false,
})
})
-
-function setMaxRange(isSkipEmpty = false) {
- emit('onClose')
- statDate.setMaxRange(isSkipEmpty)
-}
</script>
<template>
<div class="relative overflow-hidden">
<div ref="sliderRef" class="swiper-container">
<div class="swiper-wrapper">
- <!-- Recent -->
<div class="swiper-slide">
- <div class="flex overflow-hidden">
- <DateRanges @onClose="emit('onClose')" />
-
- <div class="flex">
- <DateLinkItem @click="statDate.minusRange">
- -
- </DateLinkItem>
- <DateLinkItemNoBg>
- {{ statDate.params.value.rangeDuration }}
- </DateLinkItemNoBg>
- <DateLinkItem @click="statDate.plusRange">
- +
- </DateLinkItem>
- </div>
- </div>
+ <DateRanges
+ :itemProps="{ variant: 'small' }"
+ :statDate
+ view="periods"
+ @onClose="emit('onClose')"
+ />
</div>
<div class="swiper-slide">
- <div class="flex overflow-hidden">
- <DateRanges2 @onClose="emit('onClose')" />
- </div>
+ <DateRanges
+ :itemProps="{ variant: 'small' }"
+ :statDate
+ view="presets"
+ @onClose="emit('onClose')"
+ />
</div>
<div class="swiper-slide">
- <div class="flex overflow-hidden">
- <DateLinkItem
- :isActive="statDate.params.value.isShowMaxRange && !statDate.params.value.isSkipEmpty"
- @click="() => setMaxRange(false)"
- >
- {{ t('all') }}
- </DateLinkItem>
- <DateLinkItem
- :isActive="statDate.params.value.isShowMaxRange && statDate.params.value.isSkipEmpty"
- @click="() => setMaxRange(true)"
- >
- {{ t('allSkipEmpty') }}
- </DateLinkItem>
- </div>
+ <DateRanges
+ :itemProps="{ variant: 'small' }"
+ :statDate
+ view="maximum"
+ @onClose="emit('onClose')"
+ />
</div>
</div>
</div>
</div>
</template>
-
-<i18n lang="yaml">
-en:
- all: All
- allSkipEmpty: Maximum
- calendar: Calendar
- intervalsGrouped: Grouped by
- ranges: Ranges
- presets: Presets
- last: Last
- 7Days: 7d
- 14Days: 14d
- 30Days: 30d
- 12Months: 12m
- mini: mini
-
-ru:
- all: Все
- allSkipEmpty: Максимально
- calendar: Календарь
- intervalsGrouped: Группировка по
- ranges: Диапазоны
- presets: Пресеты
- last: Последние
- 7Days: 7д
- 14Days: 14д
- 30Days: 30д
- 12Months: 12м
- mini: мини
-</i18n>
diff --git a/app/components/stat/date/Selector.vue b/app/components/stat/date/Selector.vue
index dd275164..bbe67c5c 100644
--- a/app/components/stat/date/Selector.vue
+++ b/app/components/stat/date/Selector.vue
@@ -55,60 +55,45 @@ function selectInterval(grouped: Grouped) {
</UiTabsItem1>
</UiTabs1>
- <div v-if="tabs.selected.value === 'presets'">
- <div class="pb-4 pt-1">
- <!-- Presets -->
- <div class="grid gap-2">
- <div class="flex flex-wrap gap-1">
- <DateRanges @onClose="emit('onClose')" />
-
- <div class="flex">
- <DateLinkItem @click="statDate.minusRange">
- -
- </DateLinkItem>
- <DateLinkItemNoBg>
- {{ statDate.params.value.rangeDuration }}
- </DateLinkItemNoBg>
- <DateLinkItem @click="statDate.plusRange">
- +
- </DateLinkItem>
- </div>
- </div>
+ <div
+ v-if="tabs.selected.value === 'presets'"
+ class="grid gap-6"
+ >
+ <!-- Presets -->
+ <div class="grid gap-2">
+ <div class="flex flex-wrap gap-1">
+ <DateRanges
+ :statDate
+ view="periods"
+ isShowRangeAdjust
+ @onClose="emit('onClose')"
+ />
+ </div>
- <div class="flex flex-wrap gap-1">
- <DateRanges2 @onClose="emit('onClose')" />
- </div>
+ <div class="flex flex-wrap gap-1">
+ <DateRanges
+ :statDate
+ view="presets"
+ @onClose="emit('onClose')"
+ />
+ </div>
- <div class="flex flex-wrap gap-1">
- <DateLinkItem
- :isActive="statDate.params.value.isShowMaxRange && !statDate.params.value.isSkipEmpty"
- @click="() => setMaxRange(false)"
- >
- {{ t('all') }}
- </DateLinkItem>
- <DateLinkItem
- :isActive="statDate.params.value.isShowMaxRange && statDate.params.value.isSkipEmpty"
- @click="() => setMaxRange(true)"
- >
- {{ t('allSkipEmpty') }}
- </DateLinkItem>
- </div>
+ <div class="flex flex-wrap gap-1">
+ <DateRanges
+ :statDate
+ view="maximum"
+ @onClose="emit('onClose')"
+ />
</div>
</div>
<!-- Grouped by -->
- <UiToggle2
- storageKey="finapp-date-modal-grouped"
- :initStatus="false"
- :lineWidth="1"
- >
- <template #header="{ toggle, isShown }">
- <UiTitleDropRight :isShown @click="toggle">
- {{ t('intervalsGrouped') }}
- </UiTitleDropRight>
- </template>
+ <div class="grid gap-3">
+ <UiTitleOption class="px-1">
+ {{ t('intervalsGrouped') }}
+ </UiTitleOption>
- <div class="grid gap-2 px-2">
+ <div class="grid gap-2">
<div class="flex flex-wrap gap-1">
<DateLinkItem
v-for="item in intervals"
@@ -118,6 +103,7 @@ function selectInterval(grouped: Grouped) {
>
{{ t(`dates.${item.intervalsBy}.simple`) }}
</DateLinkItem>
+
<div class="flex">
<DateLinkItem @click="statDate.delInterval">
-
@@ -131,7 +117,7 @@ function selectInterval(grouped: Grouped) {
</div>
</div>
</div>
- </UiToggle2>
+ </div>
</div>
<DatePicker
@@ -167,7 +153,7 @@ ru:
all: Все
allSkipEmpty: Максимально
calendar: Календарь
- intervalsGrouped: Группировка по
+ intervalsGrouped: Группировка
ranges: Диапазоны
presets: Пресеты
last: Последние
diff --git a/app/components/trnForm/Main.vue b/app/components/trnForm/Main.vue
index d661bd08..9c0240a7 100644
--- a/app/components/trnForm/Main.vue
+++ b/app/components/trnForm/Main.vue
@@ -54,7 +54,7 @@ const items = computed(() => ({
}
},
icon: 'mdi:content-copy',
- localeKey: 'base.duplicate',
+ label: t('base.duplicate'),
},
// eslint-disable-next-line perfectionist/sort-objects
delete: {
@@ -62,7 +62,7 @@ const items = computed(() => ({
showModalConfirm.value = true
},
icon: 'mdi:delete-empty-outline',
- localeKey: 'base.delete',
+ label: t('base.delete'),
},
}))
@@ -72,7 +72,7 @@ const actions = computed(() => ({
showModalConfirm.value = false
},
icon: 'mdi:close',
- localeKey: 'base.no',
+ label: t('base.no'),
},
yes: {
@@ -81,7 +81,7 @@ const actions = computed(() => ({
trnsFormStore.onClose()
},
icon: 'mdi:check',
- localeKey: 'base.yes',
+ label: t('base.yes'),
},
}))
</script>
@@ -135,7 +135,7 @@ const actions = computed(() => ({
</template>
<div class="leading-none text-2">
- {{ t(item.localeKey) }}
+ {{ item.label }}
</div>
</UiElement>
</div>
@@ -143,10 +143,11 @@ const actions = computed(() => ({
</div>
<!-- Trn actions -->
- <div class="flex gap-2 pt-2">
- <DateLinkItem
+ <div class="flex pt-2">
+ <UiItem1
v-for="(item, slug) in items"
:key="slug"
+ variant="text"
@click="item.click"
>
<template #leftIcon>
@@ -157,9 +158,9 @@ const actions = computed(() => ({
</template>
<div class="leading-none text-2">
- {{ t(item.localeKey) }}
+ {{ t(item.label) }}
</div>
- </DateLinkItem>
+ </UiItem1>
</div>
</div>
diff --git a/app/components/ui/Item1.vue b/app/components/ui/Item1.vue
index b47a4811..683b7af3 100644
--- a/app/components/ui/Item1.vue
+++ b/app/components/ui/Item1.vue
@@ -1,6 +1,10 @@
<script setup lang="ts">
import { getStyles } from '~/components/ui/getStyles'
+const { variant = 'icon' } = defineProps<{
+ variant: 'icon' | 'text'
+}>()
+
const emit = defineEmits<{
click: [e: Event]
}>()
@@ -8,8 +12,15 @@ const emit = defineEmits<{
<template>
<div
- :class="getStyles('item', ['link', '_bg', 'center', 'minh2', 'minw1', 'rounded'])"
- class="justify-center text-xl group-data-[headlessui-state='open']:!bg-item-4"
+ class="justify-center group-data-[headlessui-state=open]:!bg-item-4" :class="[
+ getStyles('item', ['link', 'center', 'minh2', 'minw1', 'rounded']),
+ {
+ 'text-xl': variant === 'icon',
+ },
+ {
+ 'px-3 text-sm text-1': variant === 'text',
+ },
+ ]"
@click="(e: Event) => emit('click', e)"
>
<slot />