Skip to content

Open source personal finance application

refactor: improve code readability and structure in StatPage, Index, Header, Menu, Navigation, and UI components

Ilya Komichev343dff2e2744
diff --git a/app/components/categories/StatPage.vue b/app/components/categories/StatPage.vue
index e8c4da16..ee90e63e 100644
--- a/app/components/categories/StatPage.vue
+++ b/app/components/categories/StatPage.vue
@@ -89,7 +89,7 @@ useHead({ title: category.value?.name })
}"
:menu="{
active: activeTab,
- click: id => activeTab = id,
+ click: (id: StatTabSlug) => activeTab = id,
}"
>
<template #title>
diff --git a/app/components/categories/page/id/Index.vue b/app/components/categories/page/id/Index.vue
index c83e766f..4144f76f 100644
--- a/app/components/categories/page/id/Index.vue
+++ b/app/components/categories/page/id/Index.vue
@@ -142,9 +142,13 @@ async function onDeleteConfirm() {
<template>
<UiPage v-if="category">
<StatHeader
- :config="{ isShowCategories: true }"
- :filter="{ isShow: true, isShowCategories: true }"
- :menu="{ active: activeTab, click: id => activeTab = id }"
+ :config="{
+ isShowCategories: true,
+ }"
+ :filter="{
+ isShow: true,
+ isShowCategories: true,
+ }"
>
<template #title>
<CategoriesHeader
@@ -153,6 +157,13 @@ async function onDeleteConfirm() {
/>
</template>
+ <template #selected>
+ <StatMenu
+ :active="activeTab"
+ @click="(id: StatTabSlug) => activeTab = id"
+ />
+ </template>
+
<template
v-if="!categoriesStore.transferCategoriesIds.includes(categoryId)"
#popover="{ close }"
diff --git a/app/components/stat/Header.vue b/app/components/stat/Header.vue
index aefd36d1..d22cab96 100644
--- a/app/components/stat/Header.vue
+++ b/app/components/stat/Header.vue
@@ -70,10 +70,14 @@ const statConfigModal: Ref<StatConfigModal> = ref({
:isShowWallets="!!props.config.isShowWallets"
:statConfigModal
>
- <template v-if="$slots.popover" #default="{ close }">
+ <template
+ v-if="$slots.popover"
+ #default="{ close }"
+ >
<div>
<slot
- name="popover" :close="() => {
+ name="popover"
+ :close="() => {
statConfigModal.close()
close()
}"
@@ -85,12 +89,10 @@ const statConfigModal: Ref<StatConfigModal> = ref({
</template>
<template #selected>
- <div v-if="props.menu">
- <StatMenu
- :active="props.menu.active"
- @click="props.menu.click"
- />
- </div>
+ <slot
+ v-if="$slots.selected"
+ name="selected"
+ />
</template>
<template
diff --git a/app/components/stat/Menu.vue b/app/components/stat/Menu.vue
index f3befaeb..6ac5f8f3 100644
--- a/app/components/stat/Menu.vue
+++ b/app/components/stat/Menu.vue
@@ -56,10 +56,10 @@ watch(() => props.active, () => {
v-for="item in menu"
:key="item.id"
:class="[{
- '!border-(--ui-primary) rounded-none border-b border-b-1': item.id === props.active,
- 'text-muted hover:pb-1 hover:mb-1 hover:bg-[var(--item-5)]': item.id !== props.active,
+ 'rounded-none border-b border-b-1 !border-(--ui-primary)': item.id === props.active,
+ 'text-muted hover:mb-1 hover:bg-[var(--item-5)] hover:pb-1': item.id !== props.active,
}]"
- class="text-nowrap rounded-lg px-3 py-1.5 pb-2 text-xs lg:text-sm tracking-wide"
+ class="rounded-lg px-3 py-1.5 pb-2 text-xs tracking-wide text-nowrap lg:text-sm"
@click="onClickStatMenu(item.id)"
>
{{ item.name }}
diff --git a/app/components/stat/date/Navigation.vue b/app/components/stat/date/Navigation.vue
index 3f325280..9780fdaa 100644
--- a/app/components/stat/date/Navigation.vue
+++ b/app/components/stat/date/Navigation.vue
@@ -59,7 +59,7 @@ function changeDate(way: 'next' | 'prev' | 'today') {
</script>
<template>
- <div class="items-top flex items-center grow gap-2 sticky top-[75px] lg:top-[89px] py-2 -my-2 sticky z-20 bg-default/90 backdrop-blur overflow-x-auto">
+ <div class="items-top bg-default/90 sticky top-0 z-20 -my-2 flex grow items-center gap-2 overflow-x-auto py-2 backdrop-blur lg:top-[87px]">
<div
v-if="!statDate.params.value.customDate"
class="flex gap-1"
diff --git a/app/components/ui/Header.vue b/app/components/ui/Header.vue
index 202b6dcc..b88b53df 100644
--- a/app/components/ui/Header.vue
+++ b/app/components/ui/Header.vue
@@ -1,6 +1,6 @@
<template>
- <div class="mb-2 top-0 sticky z-20 bg-default/90 backdrop-blur">
- <div class="py-2 grid max-w-7xl items-center border-b border-item-4 min-h-12 px-2 lg:px-4 2xl:px-8 lg:py-4">
+ <div class="bg-default/90 top-0 z-20 mb-2 backdrop-blur lg:sticky">
+ <div class="border-item-4 grid min-h-12 max-w-7xl items-center border-b px-2 py-2 lg:px-4 lg:py-4 2xl:px-8">
<div class="flex grow items-center gap-2">
<slot />
@@ -8,9 +8,10 @@
<slot name="actions" />
</div>
</div>
+
<div
v-if="$slots.selected"
- class="grid -mb-2 lg:-mb-4"
+ class="-mb-2 grid lg:-mb-4"
>
<slot name="selected" />
</div>
@@ -18,7 +19,7 @@
<div
v-if="$slots.after"
- class="grid gap-2 pb-2 pt-1"
+ class="grid gap-2 pt-1 pb-2"
>
<slot name="after" />
</div>
diff --git a/app/components/wallets/page/id/Index.vue b/app/components/wallets/page/id/Index.vue
index 23708321..5a2dd54a 100644
--- a/app/components/wallets/page/id/Index.vue
+++ b/app/components/wallets/page/id/Index.vue
@@ -114,9 +114,11 @@ async function onDeleteConfirm() {
<template>
<UiPage v-if="wallet">
<StatHeader
- :config="{ isShowCategories: true }"
- :filter="{ isShowCategories: true }"
- :menu="{ active: activeTab, click: id => activeTab = id }"
+ :config="{
+ isShowCategories: true,
+ }"
+ :filter="{ isShowCategories: true,
+ }"
>
<template #title>
<UiHeaderTitle>
@@ -129,6 +131,13 @@ async function onDeleteConfirm() {
</UiHeaderTitle>
</template>
+ <template #selected>
+ <StatMenu
+ :active="activeTab"
+ @click="(id: StatTabSlug) => activeTab = id"
+ />
+ </template>
+
<template #popover="{ close }">
<UiHeaderLink
icon="mdi:pencil-outline"