do not save transaction draft when category / account / tag is same as the initial value (#37)

This commit is contained in:
MaysWind
2025-02-05 22:38:41 +08:00
parent 9797e7e58f
commit b077b99806
4 changed files with 44 additions and 15 deletions
+10 -9
View File
@@ -39,6 +39,7 @@ import {
isDefined,
isNumber,
isString,
isArray1SubsetOfArray2,
splitItemsToMap,
countSplitItems
} from '@/lib/common.ts';
@@ -422,7 +423,7 @@ export const useTransactionsStore = defineStore('transactions', () => {
}
}
function isTransactionDraftModified(transaction?: Transaction): boolean {
function isTransactionDraftModified(transaction?: Transaction, initCategoryId?: string, initAccountId?: string, initTagIds?: string): boolean {
if (!transaction) {
return false;
}
@@ -435,11 +436,11 @@ export const useTransactionsStore = defineStore('transactions', () => {
return true;
}
if (transaction.sourceAccountId && transaction.sourceAccountId !== '0' && transaction.sourceAccountId !== userStore.currentUserDefaultAccountId) {
if (transaction.sourceAccountId && transaction.sourceAccountId !== '0' && transaction.sourceAccountId !== userStore.currentUserDefaultAccountId && transaction.sourceAccountId !== initAccountId) {
return true;
}
if (transaction.type === TransactionType.Transfer && transaction.destinationAccountId && transaction.destinationAccountId !== '0' && transaction.destinationAccountId !== userStore.currentUserDefaultAccountId) {
if (transaction.type === TransactionType.Transfer && transaction.destinationAccountId && transaction.destinationAccountId !== '0' && transaction.destinationAccountId !== userStore.currentUserDefaultAccountId && transaction.destinationAccountId !== initAccountId) {
return true;
}
@@ -449,19 +450,19 @@ export const useTransactionsStore = defineStore('transactions', () => {
if (transaction.type === TransactionType.Expense) {
const defaultCategoryId = getFirstAvailableCategoryId(allCategories[CategoryType.Expense]);
if (transaction.expenseCategoryId && transaction.expenseCategoryId !== '0' && transaction.expenseCategoryId !== defaultCategoryId) {
if (transaction.expenseCategoryId && transaction.expenseCategoryId !== '0' && transaction.expenseCategoryId !== defaultCategoryId && transaction.expenseCategoryId !== initCategoryId) {
return true;
}
} else if (transaction.type === TransactionType.Income) {
const defaultCategoryId = getFirstAvailableCategoryId(allCategories[CategoryType.Income]);
if (transaction.incomeCategoryId && transaction.incomeCategoryId !== '0' && transaction.incomeCategoryId !== defaultCategoryId) {
if (transaction.incomeCategoryId && transaction.incomeCategoryId !== '0' && transaction.incomeCategoryId !== defaultCategoryId && transaction.incomeCategoryId !== initCategoryId) {
return true;
}
} else if (transaction.type === TransactionType.Transfer) {
const defaultCategoryId = getFirstAvailableCategoryId(allCategories[CategoryType.Transfer]);
if (transaction.transferCategoryId && transaction.transferCategoryId !== '0' && transaction.transferCategoryId !== defaultCategoryId) {
if (transaction.transferCategoryId && transaction.transferCategoryId !== '0' && transaction.transferCategoryId !== defaultCategoryId && transaction.transferCategoryId !== initCategoryId) {
return true;
}
}
@@ -472,7 +473,7 @@ export const useTransactionsStore = defineStore('transactions', () => {
}
if (transaction.tagIds && transaction.tagIds.length > 0) {
return true;
return !initTagIds || !isArray1SubsetOfArray2(transaction.tagIds, initTagIds.split(','));
}
if (transaction.pictures && transaction.pictures.length > 0) {
@@ -486,14 +487,14 @@ export const useTransactionsStore = defineStore('transactions', () => {
return false;
}
function saveTransactionDraft(transaction?: Transaction): void {
function saveTransactionDraft(transaction?: Transaction, initCategoryId?: string, initAccountId?: string, initTagIds?: string): void {
if (settingsStore.appSettings.autoSaveTransactionDraft !== 'enabled' && settingsStore.appSettings.autoSaveTransactionDraft !== 'confirmation') {
clearTransactionDraft();
return;
}
if (transaction) {
if (!isTransactionDraftModified(transaction)) {
if (!isTransactionDraftModified(transaction, initCategoryId, initAccountId, initTagIds)) {
clearTransactionDraft();
return;
}