code refactor

This commit is contained in:
MaysWind
2025-02-05 00:19:01 +08:00
parent 833e767e6c
commit 00f62fd608
6 changed files with 54 additions and 98 deletions
@@ -188,8 +188,7 @@ import type { TransactionTag } from '@/models/transaction_tag.ts';
import {
getTransactionPrimaryCategoryName,
getTransactionSecondaryCategoryName,
getFirstAvailableCategoryId
getTransactionSecondaryCategoryName
} from '@/lib/category.ts';
import {
@@ -233,32 +232,9 @@ const allVisibleCategorizedAccounts = computed<CategorizedAccountWithDisplayBala
const allCategories = computed<Record<number, TransactionCategory[]>>(() => transactionCategoriesStore.allTransactionCategories);
const allTags = computed<TransactionTag[]>(() => transactionTagsStore.allTransactionTags);
const hasAvailableExpenseCategories = computed<boolean>(() => {
if (!allCategories.value || !allCategories.value[CategoryType.Expense] || !allCategories.value[CategoryType.Expense].length) {
return false;
}
const firstAvailableCategoryId = getFirstAvailableCategoryId(allCategories.value[CategoryType.Expense]);
return firstAvailableCategoryId !== '';
});
const hasAvailableIncomeCategories = computed<boolean>(() => {
if (!allCategories.value || !allCategories.value[CategoryType.Income] || !allCategories.value[CategoryType.Income].length) {
return false;
}
const firstAvailableCategoryId = getFirstAvailableCategoryId(allCategories.value[CategoryType.Income]);
return firstAvailableCategoryId !== '';
});
const hasAvailableTransferCategories = computed<boolean>(() => {
if (!allCategories.value || !allCategories.value[CategoryType.Transfer] || !allCategories.value[CategoryType.Transfer].length) {
return false;
}
const firstAvailableCategoryId = getFirstAvailableCategoryId(allCategories.value[CategoryType.Transfer]);
return firstAvailableCategoryId !== '';
});
const hasAvailableExpenseCategories = computed<boolean>(() => transactionCategoriesStore.hasAvailableExpenseCategories);
const hasAvailableIncomeCategories = computed<boolean>(() => transactionCategoriesStore.hasAvailableIncomeCategories);
const hasAvailableTransferCategories = computed<boolean>(() => transactionCategoriesStore.hasAvailableTransferCategories);
function getAccountDisplayName(accountId?: string): string {
if (accountId) {