Skip to content

Open source personal finance application

refactor: update categories

ilkome5056ca35bdd2
diff --git a/components/categories/EditModal.vue b/components/categories/EditModal.vue
index 3d5a16ca..422a5967 100644
--- a/components/categories/EditModal.vue
+++ b/components/categories/EditModal.vue
@@ -291,7 +291,7 @@ div
div(@click="showParents = true")
template(v-if="category.parentId !== 0")
- CategoriesItemCategoryItem(
+ CategoriesItem(
:category="$store.state.categories.items[category.parentId]"
:id="category.parentId"
)
@@ -438,10 +438,9 @@ div
icon="mdi mdi-folder-star"
@onClick="() => handleParenCategorySelect(0)")
- CategoriesView(
+ CategoriesList(
:activeItemId="category.parentId"
:ids="$store.getters['categories/categoriesForBeParent'].filter(cId => cId !== categoryId)"
- noPadding
@onClick="handleParenCategorySelect"
)
</template>
diff --git a/components/categories/item/CategoryItem.vue b/components/categories/Item.vue
similarity index 93%
rename from components/categories/item/CategoryItem.vue
rename to components/categories/Item.vue
index a726d309..3e703250 100644
--- a/components/categories/item/CategoryItem.vue
+++ b/components/categories/Item.vue
@@ -8,7 +8,6 @@ export default defineComponent({
id: { type: String, required: true },
isHideParentCategory: { type: Boolean, default: false },
slider: { type: Object, required: true },
- ui: { type: String, default: null },
},
setup(props, { listeners }) {
@@ -47,7 +46,7 @@ export default defineComponent({
<template lang="pug">
.categoryItem.bg-main.py-2.px-3.gap-x-3.flex.items-center.rounded-md.bg-gray-50.dark_bg-dark5.hocus_bg-gray-100.dark_hocus_bg-neutral-800(
v-if="category"
- :class="{ [ui]: ui, _active: activeItemId === id }"
+ :class="{ _active: activeItemId === id }"
@click="onClickItem"
)
.categoryItem__active(v-if="activeItemId === id")
@@ -62,9 +61,7 @@ export default defineComponent({
class="dark_text-neutral-400"
) {{ parentCategory.name }}
- .leading-none.text-sm.text-neutral-700.dark_text-neutral-300
- | {{ category.name }}
- template(v-if="childCategoriesIds.length > 0") ...
+ .leading-none.text-sm.text-neutral-700.dark_text-neutral-300 {{ category.name }}
.font-unica.text-md.text-neutral-500(
v-if="childCategoriesIds.length > 0"
diff --git a/components/categories/List.vue b/components/categories/List.vue
new file mode 100644
index 00000000..8f7469eb
--- /dev/null
+++ b/components/categories/List.vue
@@ -0,0 +1,33 @@
+<script>
+export default {
+ props: {
+ activeItemId: { type: String, default: null },
+ ids: { type: Array, required: true },
+ isHideParentCategory: { type: Boolean, default: false },
+ slider: { type: Object, required: true },
+ },
+
+ computed: {
+ categoresIds() {
+ if (this.limit)
+ return this.ids.slice(0, this.limit)
+
+ return this.ids
+ },
+ },
+}
+</script>
+
+<template lang="pug">
+.grid.gap-y-1.gap-x-2.3sm_grid-cols-2.sm_gap-x-6
+ CategoriesItem(
+ v-for="categoryId in categoresIds"
+ :category="$store.state.categories.items[categoryId]"
+ :activeItemId="activeItemId"
+ :id="categoryId"
+ :key="categoryId"
+ :slider="slider"
+ :isHideParentCategory="isHideParentCategory"
+ v-on="$listeners"
+ )
+</template>
diff --git a/components/categories/list/CategoriesList.vue b/components/categories/list/CategoriesList.vue
deleted file mode 100644
index 305acb2e..00000000
--- a/components/categories/list/CategoriesList.vue
+++ /dev/null
@@ -1,11 +0,0 @@
-<script>
-export default {
-}
-</script>
-
-<template lang="pug">
-CategoriesView(
- :ids="$store.getters['categories/categoriesRootIds']"
- v-on="$listeners"
-)
-</template>
diff --git a/components/categories/list/CategoriesListSlot.vue b/components/categories/list/CategoriesListSlot.vue
deleted file mode 100644
index 12a5679d..00000000
--- a/components/categories/list/CategoriesListSlot.vue
+++ /dev/null
@@ -1,37 +0,0 @@
-<script>
-export default {
- props: {
- ids: { type: Array, required: true },
- limit: { type: Number, default: null },
- },
-
- computed: {
- categories() {
- const categores = {}
- let ids = this.ids
-
- if (!this.ids || this.ids.length <= 0)
- return categores
-
- if (this.limit)
- ids = this.ids.slice(0, this.limit)
-
- for (const categoryId of ids) {
- const category = this.$store.state.categories.items[categoryId]
-
- categores[categoryId] = {
- id: categoryId,
- ...category,
- }
- }
-
- return categores
- },
- },
-}
-</script>
-
-<template lang="pug">
-.categories
- slot(:categories="categories")
-</template>
diff --git a/components/categories/list/CategoriesView.vue b/components/categories/list/CategoriesView.vue
deleted file mode 100644
index dbc53449..00000000
--- a/components/categories/list/CategoriesView.vue
+++ /dev/null
@@ -1,48 +0,0 @@
-<script>
-export default {
- props: {
- activeItemId: { type: String, default: null },
- ids: { type: Array, required: true },
- limit: { type: Number, default: null },
- noPadding: { type: Boolean, default: false },
- isHideParentCategory: { type: Boolean, default: false },
- noPaddingBottom: { type: Boolean, default: false },
- slider: { type: Object, required: true },
- title: { type: String, default: null },
- ui: { type: String, default: null },
- },
-
- computed: {
- categoresIds() {
- if (this.limit)
- return this.ids.slice(0, this.limit)
-
- return this.ids
- },
- },
-}
-</script>
-
-<template lang="pug">
-.categories(:class="{ _noPadding: noPadding, _noPaddingBottom: noPaddingBottom, [ui]: ui }")
- .categories__title(v-if="title") {{ title }}
-
- .categories__list
- CategoriesItemCategoryItem(
- v-for="categoryId in categoresIds"
- :category="$store.state.categories.items[categoryId]"
- :activeItemId="activeItemId"
- :id="categoryId"
- :key="categoryId"
- :slider="slider"
- :isHideParentCategory="isHideParentCategory"
- :ui="ui"
- v-on="$listeners"
- )
-</template>
-
-<style lang="stylus" scoped>
-.categories._flat
- overflow hidden
- padding 0
-</style>
diff --git a/components/categories/list/categories.styl b/components/categories/list/categories.styl
deleted file mode 100644
index 30ee24d8..00000000
--- a/components/categories/list/categories.styl
+++ /dev/null
@@ -1,44 +0,0 @@
-.categories
- padding-bottom $m7
-
- &._noPadding
- padding 0
-
- &._noPaddingBottom
- padding 0
-
- &__title
- padding 0 $m7
- padding-bottom $m7
- color var(--c-font-4)
- font-size 22px
-
- &__list
- display grid
- grid-template-columns repeat(2, 1fr)
- grid-column-gap $m6
- grid-row-gap $m6
- padding 0 $m7
-
- +media(600px)
- grid-template-columns repeat(auto-fill, minmax(200px, 1fr))
- grid-column-gap $m6
- grid-row-gap $m6
-
- ^[0]._noPadding &
- padding 0
-
- &:last-child
- padding-bottom 0
-
- ^[0]._borderTop &
- margin-top $m6
- padding-top $m8
- border-top 1px solid var(--c-bg-4)
-
- &__desc
- padding $m7
- padding-bottom 0
- color var(--c-font-4)
- font-size 12px
- text-align center
diff --git a/components/categories/page/List.vue b/components/categories/page/List.vue
index 56d5129c..2c20a664 100644
--- a/components/categories/page/List.vue
+++ b/components/categories/page/List.vue
@@ -41,19 +41,11 @@ export default defineComponent({
//- List
//---------------------------------
- CategoriesListSlot(
- :ids="catsIds"
- v-slot="{ categories }"
- )
- .pb-12.px-3.grid.gap-y-1.gap-x-2.2sm_grid-cols-2.sm_gap-x-6
- CategoriesItemCategoryItem(
- v-for="category in categories"
- :category="category"
- :slider="() => ({})"
- :id="category.id"
- :key="category.id"
- @onClick="id => $router.push(`/categories/${category.id}`)"
- )
+ .pb-12.px-3
+ CategoriesList(
+ :ids="catsIds"
+ @onClick="catId => $router.push(`/categories/${catId}`)"
+ )
.pb-4.px-3.flex.justify-evenly.gap-6
//- Create
diff --git a/components/categories/page/id/Edit.vue b/components/categories/page/id/Edit.vue
index f5890b67..fd0f4523 100644
--- a/components/categories/page/id/Edit.vue
+++ b/components/categories/page/id/Edit.vue
@@ -283,7 +283,7 @@ export default defineComponent({
div(@click="showParents = true")
template(v-if="category.parentId !== 0")
- CategoriesItemCategoryItem(
+ CategoriesItem(
:category="$store.state.categories.items[category.parentId]"
:id="category.parentId"
)
@@ -421,10 +421,9 @@ export default defineComponent({
icon="mdi mdi-folder-star"
@onClick="() => handleParenCategorySelect(0)")
- CategoriesView(
+ CategoriesList(
:activeItemId="category.parentId"
:ids="$store.getters['categories/categoriesForBeParent'].filter(cId => cId !== categoryId)"
- noPadding
@onClick="handleParenCategorySelect"
)
</template>
diff --git a/components/categories/page/id/Index.vue b/components/categories/page/id/Index.vue
index 335ae38c..05218737 100644
--- a/components/categories/page/id/Index.vue
+++ b/components/categories/page/id/Index.vue
@@ -92,12 +92,10 @@ function handleEditClick() {
div {{ category.childIds.length }}
.px-3
- CategoriesView(
+ CategoriesList(
:ids="categoryChildIds"
:slider="() => ({})"
isHideParentCategory
- borderTop
- noPadding
@onClick="id => $router.push(`/categories/${id}`)"
)
diff --git a/store/categories/getters.js b/store/categories/getters.js
index 8b3daa09..f236e93b 100644
--- a/store/categories/getters.js
+++ b/store/categories/getters.js
@@ -74,7 +74,7 @@ export default {
if (state.items && rootGetters['trns/hasTrns']) {
for (const trnId of trnsIds.slice(0, 500)) {
- if (lastCategoriesIds.length < 12) {
+ if (lastCategoriesIds.length < 16) {
const categoryId = trnsItems[trnId].categoryId
const category = state.items[categoryId]
if (category && (category.showInLastUsed || category.showInLastUsed === undefined)) {