use primary color & icon as default when creating secondary category
This commit is contained in:
@@ -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<boolean>(true);
|
||||||
|
const primaryCategoryId = ref<string>('0');
|
||||||
|
|
||||||
|
const currentPrimaryCategory = computed<TransactionCategory | undefined>(() => {
|
||||||
|
if (!transactionCategoriesStore.allTransactionCategoriesMap || !transactionCategoriesStore.allTransactionCategoriesMap[primaryCategoryId.value]) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return transactionCategoriesStore.allTransactionCategoriesMap[primaryCategoryId.value];
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
// states
|
||||||
|
loading,
|
||||||
|
primaryCategoryId,
|
||||||
|
// computed states
|
||||||
|
currentPrimaryCategory
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -203,6 +203,7 @@ import { ref, computed, useTemplateRef, watch, nextTick } from 'vue';
|
|||||||
import { useDisplay } from 'vuetify';
|
import { useDisplay } from 'vuetify';
|
||||||
|
|
||||||
import { useI18n } from '@/locales/helpers.ts';
|
import { useI18n } from '@/locales/helpers.ts';
|
||||||
|
import { useCategoryListPageBase } from '@/views/base/categories/CategoryListPageBase.ts';
|
||||||
|
|
||||||
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
|
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
|
||||||
|
|
||||||
@@ -232,6 +233,7 @@ type EditDialogType = InstanceType<typeof EditDialog>;
|
|||||||
|
|
||||||
const display = useDisplay();
|
const display = useDisplay();
|
||||||
const { tt } = useI18n();
|
const { tt } = useI18n();
|
||||||
|
const { loading, primaryCategoryId, currentPrimaryCategory } = useCategoryListPageBase();
|
||||||
|
|
||||||
const transactionCategoriesStore = useTransactionCategoriesStore();
|
const transactionCategoriesStore = useTransactionCategoriesStore();
|
||||||
|
|
||||||
@@ -242,8 +244,6 @@ const editDialog = useTemplateRef<EditDialogType>('editDialog');
|
|||||||
|
|
||||||
const activeCategoryType = ref<CategoryType>(CategoryType.Expense);
|
const activeCategoryType = ref<CategoryType>(CategoryType.Expense);
|
||||||
const activeTab = ref<string>('categoryPage');
|
const activeTab = ref<string>('categoryPage');
|
||||||
const primaryCategoryId = ref<string>('0');
|
|
||||||
const loading = ref<boolean>(true);
|
|
||||||
const updating = ref<boolean>(false);
|
const updating = ref<boolean>(false);
|
||||||
const categoryHiding = ref<Record<string, boolean>>({});
|
const categoryHiding = ref<Record<string, boolean>>({});
|
||||||
const categoryRemoving = ref<Record<string, boolean>>({});
|
const categoryRemoving = ref<Record<string, boolean>>({});
|
||||||
@@ -350,7 +350,9 @@ function reload(force: boolean): void {
|
|||||||
function add(): void {
|
function add(): void {
|
||||||
editDialog.value?.open({
|
editDialog.value?.open({
|
||||||
type: activeCategoryType.value,
|
type: activeCategoryType.value,
|
||||||
parentId: primaryCategoryId.value
|
parentId: primaryCategoryId.value,
|
||||||
|
color: currentPrimaryCategory.value?.color,
|
||||||
|
icon: currentPrimaryCategory.value?.icon
|
||||||
}).then(result => {
|
}).then(result => {
|
||||||
if (result && result.message) {
|
if (result && result.message) {
|
||||||
snackbar.value?.showMessage(result.message);
|
snackbar.value?.showMessage(result.message);
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ import { useCategoryEditPageBase } from '@/views/base/categories/CategoryEditPag
|
|||||||
|
|
||||||
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
|
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
|
||||||
|
|
||||||
|
import type { ColorValue } from '@/core/color.ts';
|
||||||
import { CategoryType } from '@/core/category.ts';
|
import { CategoryType } from '@/core/category.ts';
|
||||||
import { ALL_CATEGORY_ICONS } from '@/consts/icon.ts';
|
import { ALL_CATEGORY_ICONS } from '@/consts/icon.ts';
|
||||||
import { ALL_CATEGORY_COLORS } from '@/consts/color.ts';
|
import { ALL_CATEGORY_COLORS } from '@/consts/color.ts';
|
||||||
@@ -147,7 +148,7 @@ const isCategoryModified = computed<boolean>(() => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function open(options: { id?: string; parentId?: string; type?: CategoryType; currentCategory?: TransactionCategory }): Promise<TransactionCategoryEditResponse> {
|
function open(options: { id?: string; parentId?: string; type?: CategoryType; currentCategory?: TransactionCategory, color?: ColorValue, icon?: string }): Promise<TransactionCategoryEditResponse> {
|
||||||
showState.value = true;
|
showState.value = true;
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
submitting.value = false;
|
submitting.value = false;
|
||||||
@@ -193,6 +194,14 @@ function open(options: { id?: string; parentId?: string; type?: CategoryType; cu
|
|||||||
category.value.type = categoryType;
|
category.value.type = categoryType;
|
||||||
category.value.parentId = options.parentId;
|
category.value.parentId = options.parentId;
|
||||||
|
|
||||||
|
if (options.color) {
|
||||||
|
category.value.color = options.color;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.icon) {
|
||||||
|
category.value.icon = options.icon;
|
||||||
|
}
|
||||||
|
|
||||||
clientSessionId.value = generateRandomUUID();
|
clientSessionId.value = generateRandomUUID();
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,6 +155,7 @@ import { useCategoryEditPageBase } from '@/views/base/categories/CategoryEditPag
|
|||||||
|
|
||||||
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
|
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
|
||||||
|
|
||||||
|
import type { ColorValue } from '@/core/color.ts';
|
||||||
import { CategoryType } from '@/core/category.ts';
|
import { CategoryType } from '@/core/category.ts';
|
||||||
import { ALL_CATEGORY_ICONS } from '@/consts/icon.ts';
|
import { ALL_CATEGORY_ICONS } from '@/consts/icon.ts';
|
||||||
import { ALL_CATEGORY_COLORS } from '@/consts/color.ts';
|
import { ALL_CATEGORY_COLORS } from '@/consts/color.ts';
|
||||||
@@ -230,6 +231,14 @@ function init(): void {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (query['color']) {
|
||||||
|
category.value.color = query['color'] as ColorValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (query['icon']) {
|
||||||
|
category.value.icon = query['icon'];
|
||||||
|
}
|
||||||
|
|
||||||
clientSessionId.value = generateRandomUUID();
|
clientSessionId.value = generateRandomUUID();
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<f7-nav-title :title="tt(title)"></f7-nav-title>
|
<f7-nav-title :title="tt(title)"></f7-nav-title>
|
||||||
<f7-nav-right class="navbar-compact-icons">
|
<f7-nav-right class="navbar-compact-icons">
|
||||||
<f7-link icon-f7="ellipsis" :class="{ 'disabled': !categories.length }" v-if="!sortable" @click="showMoreActionSheet = true"></f7-link>
|
<f7-link icon-f7="ellipsis" :class="{ 'disabled': !categories.length }" v-if="!sortable" @click="showMoreActionSheet = true"></f7-link>
|
||||||
<f7-link :href="'/category/add?type=' + categoryType + '&parentId=' + primaryCategoryId" icon-f7="plus" v-if="!sortable"></f7-link>
|
<f7-link :href="'/category/add?type=' + categoryType + '&parentId=' + primaryCategoryId + (currentPrimaryCategory ? `&color=${currentPrimaryCategory.color}&icon=${currentPrimaryCategory.icon}` : '')" icon-f7="plus" v-if="!sortable"></f7-link>
|
||||||
<f7-link :text="tt('Done')" :class="{ 'disabled': displayOrderSaving }" @click="saveSortResult" v-else-if="sortable"></f7-link>
|
<f7-link :text="tt('Done')" :class="{ 'disabled': displayOrderSaving }" @click="saveSortResult" v-else-if="sortable"></f7-link>
|
||||||
</f7-nav-right>
|
</f7-nav-right>
|
||||||
</f7-navbar>
|
</f7-navbar>
|
||||||
@@ -92,6 +92,7 @@ import type { Router } from 'framework7/types';
|
|||||||
|
|
||||||
import { useI18n } from '@/locales/helpers.ts';
|
import { useI18n } from '@/locales/helpers.ts';
|
||||||
import { useI18nUIComponents, showLoading, hideLoading, onSwipeoutDeleted } from '@/lib/ui/mobile.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';
|
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
|
||||||
|
|
||||||
@@ -111,13 +112,12 @@ const props = defineProps<{
|
|||||||
|
|
||||||
const { tt } = useI18n();
|
const { tt } = useI18n();
|
||||||
const { showAlert, showToast, routeBackOnError } = useI18nUIComponents();
|
const { showAlert, showToast, routeBackOnError } = useI18nUIComponents();
|
||||||
|
const { loading, primaryCategoryId, currentPrimaryCategory } = useCategoryListPageBase();
|
||||||
|
|
||||||
const transactionCategoriesStore = useTransactionCategoriesStore();
|
const transactionCategoriesStore = useTransactionCategoriesStore();
|
||||||
|
|
||||||
const hasSubCategories = ref<boolean>(false);
|
const hasSubCategories = ref<boolean>(false);
|
||||||
const categoryType = ref<CategoryType | 0>(0);
|
const categoryType = ref<CategoryType | 0>(0);
|
||||||
const primaryCategoryId = ref<string>('0');
|
|
||||||
const loading = ref<boolean>(true);
|
|
||||||
const loadingError = ref<unknown | null>(null);
|
const loadingError = ref<unknown | null>(null);
|
||||||
const showHidden = ref<boolean>(false);
|
const showHidden = ref<boolean>(false);
|
||||||
const sortable = ref<boolean>(false);
|
const sortable = ref<boolean>(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user