Skip to content

Commit

Permalink
code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mayswind committed Jan 29, 2025
1 parent c07e937 commit ca9fe26
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
11 changes: 0 additions & 11 deletions src/stores/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
} from '@/models/account.ts';

import { isNumber, isEquals } from '@/lib/common.ts';
import { getCurrentUnixTime } from '@/lib/datetime.ts';
import { getCategorizedAccountsMap, getAllFilteredAccountsBalance } from '@/lib/account.ts';
import services from '@/lib/services.ts';
import logger from '@/lib/logger.ts';
Expand Down Expand Up @@ -268,14 +267,6 @@ export const useAccountsStore = defineStore('accounts', () => {
return shownAccountCount;
});

function generateNewAccountModel(): Account {
return Account.createNewAccount(userStore.currentUserDefaultCurrency, getCurrentUnixTime());
}

function generateNewSubAccountModel(parentAccount: Account): Account {
return parentAccount.createNewSubAccount(userStore.currentUserDefaultCurrency, getCurrentUnixTime());
}

function updateAccountListInvalidState(invalidState: boolean): void {
accountListStateInvalid.value = invalidState;
}
Expand Down Expand Up @@ -990,8 +981,6 @@ export const useAccountsStore = defineStore('accounts', () => {
allAvailableAccountsCount,
allVisibleAccountsCount,
// functions
generateNewAccountModel,
generateNewSubAccountModel,
updateAccountListInvalidState,
resetAccounts,
getFirstShowingIds,
Expand Down
14 changes: 8 additions & 6 deletions src/views/base/accounts/AccountEditPageBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { ref, computed, watch } from 'vue';

import { useI18n } from '@/locales/helpers.ts';

import { useAccountsStore } from '@/stores/account.ts';
import { useUserStore } from '@/stores/user.ts';

import type { TypeAndDisplayName } from '@/core/base.ts';
import { AccountCategory, AccountType } from '@/core/account.ts';
import type { LocalizedCurrencyInfo } from '@/core/currency.ts';
import type { LocalizedAccountCategory } from '@/core/account.ts';
import type { Account } from '@/models/account.ts';
import { Account } from '@/models/account.ts';

import { getCurrentUnixTime } from '@/lib/datetime.ts';
import { setAccountSuitableIcon } from '@/lib/account.ts';

export interface DayAndDisplayName {
Expand All @@ -19,13 +20,14 @@ export interface DayAndDisplayName {

export function useAccountEditPageBaseBase() {
const { tt, getAllCurrencies, getAllAccountCategories, getAllAccountTypes, getMonthdayShortName } = useI18n();
const accountsStore = useAccountsStore();

const userStore = useUserStore();

const editAccountId = ref<string | null>(null);
const clientSessionId = ref<string>('');
const loading = ref<boolean>(false);
const submitting = ref<boolean>(false);
const account = ref<Account>(accountsStore.generateNewAccountModel());
const account = ref<Account>(Account.createNewAccount(userStore.currentUserDefaultCurrency, getCurrentUnixTime()));
const subAccounts = ref<Account[]>([]);

const title = computed<string>(() => {
Expand Down Expand Up @@ -133,7 +135,7 @@ export function useAccountEditPageBaseBase() {
return false;
}

const subAccount = accountsStore.generateNewSubAccountModel(account.value);
const subAccount = account.value.createNewSubAccount(userStore.currentUserDefaultCurrency, getCurrentUnixTime());
subAccounts.value.push(subAccount);
return true;
}
Expand All @@ -144,7 +146,7 @@ export function useAccountEditPageBaseBase() {

if (newAccount.childrenAccounts && newAccount.childrenAccounts.length > 0) {
for (let i = 0; i < newAccount.childrenAccounts.length; i++) {
const subAccount = accountsStore.generateNewSubAccountModel(account.value);
const subAccount = account.value.createNewSubAccount(userStore.currentUserDefaultCurrency, getCurrentUnixTime());
subAccount.from(newAccount.childrenAccounts[i]);

subAccounts.value.push(subAccount);
Expand Down
7 changes: 5 additions & 2 deletions src/views/desktop/accounts/list/dialogs/EditDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,16 @@ import { ref, computed, useTemplateRef, watch } from 'vue';
import { useI18n } from '@/locales/helpers.ts';
import { useAccountEditPageBaseBase } from '@/views/base/accounts/AccountEditPageBase.ts';
import { useUserStore } from '@/stores/user.ts';
import { useAccountsStore } from '@/stores/account.ts';
import { AccountType } from '@/core/account.ts';
import { ALL_ACCOUNT_ICONS } from '@/consts/icon.ts';
import { ALL_ACCOUNT_COLORS } from '@/consts/color.ts';
import type { Account } from '@/models/account.ts';
import { Account } from '@/models/account.ts';
import { isNumber } from '@/lib/common.ts';
import { getCurrentUnixTime } from '@/lib/datetime.ts';
import { generateRandomUUID } from '@/lib/misc.ts';
import { setAccountSuitableIcon } from '@/lib/account.ts';
Expand Down Expand Up @@ -254,6 +256,7 @@ const {
setAccount
} = useAccountEditPageBaseBase();
const userStore = useUserStore();
const accountsStore = useAccountsStore();
const icons = {
Expand Down Expand Up @@ -285,7 +288,7 @@ function open(options?: { id?: string, currentAccount?: Account, category?: numb
loading.value = true;
submitting.value = false;
const newAccount = accountsStore.generateNewAccountModel();
const newAccount = Account.createNewAccount(userStore.currentUserDefaultCurrency, getCurrentUnixTime());
account.value.from(newAccount);
subAccounts.value = [];
currentAccountIndex.value = -1;
Expand Down

0 comments on commit ca9fe26

Please sign in to comment.