diff --git a/src/views/base/categories/CategoryListPageBase.ts b/src/views/base/categories/CategoryListPageBase.ts new file mode 100644 index 00000000..1b708d30 --- /dev/null +++ b/src/views/base/categories/CategoryListPageBase.ts @@ -0,0 +1,28 @@ +import { ref, computed } from 'vue'; + +import type { TransactionCategory } from '@/models/transaction_category.ts'; + +import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts'; + +export function useCategoryListPageBase() { + const transactionCategoriesStore = useTransactionCategoriesStore(); + + const loading = ref(true); + const primaryCategoryId = ref('0'); + + const currentPrimaryCategory = computed(() => { + if (!transactionCategoriesStore.allTransactionCategoriesMap || !transactionCategoriesStore.allTransactionCategoriesMap[primaryCategoryId.value]) { + return undefined; + } + + return transactionCategoriesStore.allTransactionCategoriesMap[primaryCategoryId.value]; + }); + + return { + // states + loading, + primaryCategoryId, + // computed states + currentPrimaryCategory + }; +} diff --git a/src/views/desktop/categories/ListPage.vue b/src/views/desktop/categories/ListPage.vue index 30ee0c95..8b505ce7 100644 --- a/src/views/desktop/categories/ListPage.vue +++ b/src/views/desktop/categories/ListPage.vue @@ -203,6 +203,7 @@ import { ref, computed, useTemplateRef, watch, nextTick } from 'vue'; import { useDisplay } from 'vuetify'; import { useI18n } from '@/locales/helpers.ts'; +import { useCategoryListPageBase } from '@/views/base/categories/CategoryListPageBase.ts'; import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts'; @@ -232,6 +233,7 @@ type EditDialogType = InstanceType; const display = useDisplay(); const { tt } = useI18n(); +const { loading, primaryCategoryId, currentPrimaryCategory } = useCategoryListPageBase(); const transactionCategoriesStore = useTransactionCategoriesStore(); @@ -242,8 +244,6 @@ const editDialog = useTemplateRef('editDialog'); const activeCategoryType = ref(CategoryType.Expense); const activeTab = ref('categoryPage'); -const primaryCategoryId = ref('0'); -const loading = ref(true); const updating = ref(false); const categoryHiding = ref>({}); const categoryRemoving = ref>({}); @@ -350,7 +350,9 @@ function reload(force: boolean): void { function add(): void { editDialog.value?.open({ type: activeCategoryType.value, - parentId: primaryCategoryId.value + parentId: primaryCategoryId.value, + color: currentPrimaryCategory.value?.color, + icon: currentPrimaryCategory.value?.icon }).then(result => { if (result && result.message) { snackbar.value?.showMessage(result.message); diff --git a/src/views/desktop/categories/list/dialogs/EditDialog.vue b/src/views/desktop/categories/list/dialogs/EditDialog.vue index e9abe841..c5acf871 100644 --- a/src/views/desktop/categories/list/dialogs/EditDialog.vue +++ b/src/views/desktop/categories/list/dialogs/EditDialog.vue @@ -103,6 +103,7 @@ import { useCategoryEditPageBase } from '@/views/base/categories/CategoryEditPag import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts'; +import type { ColorValue } from '@/core/color.ts'; import { CategoryType } from '@/core/category.ts'; import { ALL_CATEGORY_ICONS } from '@/consts/icon.ts'; import { ALL_CATEGORY_COLORS } from '@/consts/color.ts'; @@ -147,7 +148,7 @@ const isCategoryModified = computed(() => { } }); -function open(options: { id?: string; parentId?: string; type?: CategoryType; currentCategory?: TransactionCategory }): Promise { +function open(options: { id?: string; parentId?: string; type?: CategoryType; currentCategory?: TransactionCategory, color?: ColorValue, icon?: string }): Promise { showState.value = true; loading.value = true; submitting.value = false; @@ -193,6 +194,14 @@ function open(options: { id?: string; parentId?: string; type?: CategoryType; cu category.value.type = categoryType; category.value.parentId = options.parentId; + if (options.color) { + category.value.color = options.color; + } + + if (options.icon) { + category.value.icon = options.icon; + } + clientSessionId.value = generateRandomUUID(); loading.value = false; } diff --git a/src/views/mobile/categories/EditPage.vue b/src/views/mobile/categories/EditPage.vue index edf50242..2c6eeb5c 100644 --- a/src/views/mobile/categories/EditPage.vue +++ b/src/views/mobile/categories/EditPage.vue @@ -155,6 +155,7 @@ import { useCategoryEditPageBase } from '@/views/base/categories/CategoryEditPag import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts'; +import type { ColorValue } from '@/core/color.ts'; import { CategoryType } from '@/core/category.ts'; import { ALL_CATEGORY_ICONS } from '@/consts/icon.ts'; import { ALL_CATEGORY_COLORS } from '@/consts/color.ts'; @@ -230,6 +231,14 @@ function init(): void { return; } + if (query['color']) { + category.value.color = query['color'] as ColorValue; + } + + if (query['icon']) { + category.value.icon = query['icon']; + } + clientSessionId.value = generateRandomUUID(); loading.value = false; } diff --git a/src/views/mobile/categories/ListPage.vue b/src/views/mobile/categories/ListPage.vue index cdc9cdcc..89a0beae 100644 --- a/src/views/mobile/categories/ListPage.vue +++ b/src/views/mobile/categories/ListPage.vue @@ -5,7 +5,7 @@ - + @@ -92,6 +92,7 @@ import type { Router } from 'framework7/types'; import { useI18n } from '@/locales/helpers.ts'; import { useI18nUIComponents, showLoading, hideLoading, onSwipeoutDeleted } from '@/lib/ui/mobile.ts'; +import { useCategoryListPageBase } from '@/views/base/categories/CategoryListPageBase.ts'; import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts'; @@ -111,13 +112,12 @@ const props = defineProps<{ const { tt } = useI18n(); const { showAlert, showToast, routeBackOnError } = useI18nUIComponents(); +const { loading, primaryCategoryId, currentPrimaryCategory } = useCategoryListPageBase(); const transactionCategoriesStore = useTransactionCategoriesStore(); const hasSubCategories = ref(false); const categoryType = ref(0); -const primaryCategoryId = ref('0'); -const loading = ref(true); const loadingError = ref(null); const showHidden = ref(false); const sortable = ref(false);