mirror of
https://github.com/Nezumi-2711/javascript-training.git
synced 2026-09-22 13:38:43 +00:00
Fix bug and remove uncessary code and assets
This commit is contained in:
@@ -78,8 +78,6 @@ export default class UserService extends CommonService {
|
||||
LOCAL_STORAGE.ACCESS_TOKEN,
|
||||
newUserData.accessToken,
|
||||
);
|
||||
|
||||
LocalStorageService.add(LOCAL_STORAGE.IS_FIRST_LOGIN, true);
|
||||
}
|
||||
|
||||
async getInfoUserLogin() {
|
||||
@@ -89,12 +87,6 @@ export default class UserService extends CommonService {
|
||||
if (accessToken) {
|
||||
const user = await this.getUserByToken(accessToken);
|
||||
|
||||
if (LocalStorageService.get(LOCAL_STORAGE.IS_FIRST_LOGIN)) {
|
||||
user.isFirstLogin = true;
|
||||
|
||||
LocalStorageService.remove(LOCAL_STORAGE.IS_FIRST_LOGIN);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import Transaction from '../models/transaction';
|
||||
import * as MESSAGE from '../constants/message';
|
||||
import { renderRequiredText } from '../helpers/validateForm';
|
||||
|
||||
class BudgetView {
|
||||
export default class BudgetView {
|
||||
constructor() {
|
||||
this.budgetDialog = document.getElementById('budgetDialog');
|
||||
this.addBudgetBtn = document.getElementById('addBudget');
|
||||
@@ -170,5 +170,3 @@ class BudgetView {
|
||||
this.addHandlerEventBudgetForm();
|
||||
}
|
||||
}
|
||||
|
||||
export default new BudgetView();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { REMOVE_CATEGORY } from '../constants/config';
|
||||
|
||||
class CategoryView {
|
||||
export default class CategoryView {
|
||||
constructor() {
|
||||
this.categoryDialog = document.getElementById('categoryDialog');
|
||||
this.categoryField = document.getElementById('selectCategory');
|
||||
@@ -132,5 +132,3 @@ class CategoryView {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default new CategoryView();
|
||||
|
||||
@@ -24,6 +24,13 @@ export default class HomeView extends CommonView {
|
||||
this.amountInputs = document.querySelectorAll('.form__input-balance');
|
||||
|
||||
this.transactionDialog = document.getElementById('transactionDialog');
|
||||
|
||||
this.walletView = new WalletView();
|
||||
this.categoryView = new CategoryView();
|
||||
this.transactionView = new TransactionView(this.categoryView);
|
||||
this.budgetView = new BudgetView();
|
||||
this.summaryTabView = new SummaryTabView();
|
||||
this.transactionTabView = new TransactionTabView(this.transactionView);
|
||||
}
|
||||
|
||||
initFunction(
|
||||
@@ -57,11 +64,11 @@ export default class HomeView extends CommonView {
|
||||
}
|
||||
|
||||
initCategoryViewFunction() {
|
||||
CategoryView.initFunction(this.getAllCategory, this.transform);
|
||||
this.categoryView.initFunction(this.getAllCategory, this.transform);
|
||||
}
|
||||
|
||||
initTransactionViewFunction() {
|
||||
TransactionView.initFunction(
|
||||
this.transactionView.initFunction(
|
||||
this.toggleLoaderSpinner.bind(this),
|
||||
this.deleteTransaction,
|
||||
this.loadTransactionData.bind(this),
|
||||
@@ -75,7 +82,7 @@ export default class HomeView extends CommonView {
|
||||
}
|
||||
|
||||
initBudgetViewFunction() {
|
||||
BudgetView.initFunction(
|
||||
this.budgetView.initFunction(
|
||||
this.showErrorToast.bind(this),
|
||||
this.showSuccessToast.bind(this),
|
||||
this.toggleLoaderSpinner.bind(this),
|
||||
@@ -88,19 +95,19 @@ export default class HomeView extends CommonView {
|
||||
}
|
||||
|
||||
initFunctionCategoryView() {
|
||||
CategoryView.initFunction(this.getAllCategory, this.transform);
|
||||
this.categoryView.initFunction(this.getAllCategory, this.transform);
|
||||
}
|
||||
|
||||
initSummaryTabViewFunction() {
|
||||
SummaryTabView.initFunction(this.transform);
|
||||
this.summaryTabView.initFunction(this.transform);
|
||||
}
|
||||
|
||||
initTransactionTabViewFunction() {
|
||||
TransactionTabView.initFunction(this.transform);
|
||||
this.transactionTabView.initFunction(this.transform);
|
||||
}
|
||||
|
||||
initWalletViewFunction() {
|
||||
WalletView.initFunction(
|
||||
this.walletView.initFunction(
|
||||
this.transform,
|
||||
this.toggleLoaderSpinner.bind(this),
|
||||
this.saveWallet,
|
||||
@@ -115,24 +122,24 @@ export default class HomeView extends CommonView {
|
||||
|
||||
subscribeListenerData() {
|
||||
this.subscribe();
|
||||
TransactionView.subscribe();
|
||||
BudgetView.subscribe();
|
||||
SummaryTabView.subscribe();
|
||||
TransactionTabView.subscribe();
|
||||
WalletView.subscribe();
|
||||
this.transactionView.subscribe();
|
||||
this.budgetView.subscribe();
|
||||
this.summaryTabView.subscribe();
|
||||
this.transactionTabView.subscribe();
|
||||
this.walletView.subscribe();
|
||||
}
|
||||
|
||||
async loadData() {
|
||||
// Send data to other class
|
||||
this.sendData();
|
||||
|
||||
await CategoryView.loadCategory();
|
||||
await this.categoryView.loadCategory();
|
||||
|
||||
await this.loadWalletUser();
|
||||
|
||||
SummaryTabView.load();
|
||||
this.summaryTabView.load();
|
||||
|
||||
TransactionTabView.loadTransactionTab();
|
||||
this.transactionTabView.loadTransactionTab();
|
||||
}
|
||||
|
||||
async loadPage() {
|
||||
@@ -150,7 +157,7 @@ export default class HomeView extends CommonView {
|
||||
// Check user's wallet if have or not
|
||||
if (!this.wallet) {
|
||||
// Show add wallet dialog
|
||||
WalletView.showDialog();
|
||||
this.walletView.showDialog();
|
||||
} else {
|
||||
// Init data
|
||||
await this.loadTransactionData();
|
||||
@@ -218,7 +225,8 @@ export default class HomeView extends CommonView {
|
||||
let outflow = 0;
|
||||
|
||||
// Init data first
|
||||
this.transactionDetails = TransactionTabView.loadTransactionDetailsData();
|
||||
this.transactionDetails =
|
||||
this.transactionTabView.loadTransactionDetailsData();
|
||||
|
||||
this.transactionDetails.forEach((transaction) => {
|
||||
if (transaction.totalAmount >= 0) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { formatNumber } from '../helpers/helpers';
|
||||
|
||||
class SummaryTabView {
|
||||
export default class SummaryTabView {
|
||||
initFunction(transform) {
|
||||
this.transform = transform;
|
||||
}
|
||||
@@ -33,5 +33,3 @@ class SummaryTabView {
|
||||
)}`;
|
||||
}
|
||||
}
|
||||
|
||||
export default new SummaryTabView();
|
||||
|
||||
@@ -4,10 +4,10 @@ import {
|
||||
getAllTransactionByCategoryName,
|
||||
} from '../helpers/dataProcess';
|
||||
import { formatNumber } from '../helpers/helpers';
|
||||
import TransactionView from './transactionView';
|
||||
|
||||
class TransactionTabView {
|
||||
constructor() {
|
||||
export default class TransactionTabView {
|
||||
constructor(transactionView) {
|
||||
this.transactionView = transactionView;
|
||||
this.addEventTransactionItem();
|
||||
}
|
||||
|
||||
@@ -158,12 +158,10 @@ class TransactionTabView {
|
||||
|
||||
// If it is income transaction, don't show dialog
|
||||
if (categoryNameEl.textContent.trim() !== 'Income')
|
||||
TransactionView.showTransactionDialog(idTransaction);
|
||||
this.transactionView.showTransactionDialog(idTransaction);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new TransactionTabView();
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
import * as MESSAGE from '../constants/message';
|
||||
import { renderRequiredText } from '../helpers/validateForm';
|
||||
import Transaction from '../models/transaction';
|
||||
import CategoryView from './categoryView';
|
||||
|
||||
import defaultCategoryIcon from '../../assets/images/question-icon.svg';
|
||||
|
||||
class TransactionView {
|
||||
constructor() {
|
||||
export default class TransactionView {
|
||||
constructor(categoryView) {
|
||||
this.addTransactionBtn = document.getElementById('addTransaction');
|
||||
this.transactionDialog = document.getElementById('transactionDialog');
|
||||
this.transactionForm = document.getElementById('formAddTransaction');
|
||||
|
||||
this.handlerEventTransactionDialog();
|
||||
|
||||
this.categoryView = categoryView;
|
||||
}
|
||||
|
||||
initFunction(
|
||||
@@ -288,7 +289,10 @@ class TransactionView {
|
||||
|
||||
categoryIcon.src = defaultCategoryIcon;
|
||||
this.keySearchCategory = null; // Delete keyword search
|
||||
CategoryView.renderCategoryList(this.keySearchCategory);
|
||||
this.categoryView.renderCategoryList(
|
||||
this.keySearchCategory,
|
||||
this.listCategory,
|
||||
);
|
||||
this.transactionForm.reset();
|
||||
}
|
||||
|
||||
@@ -308,5 +312,3 @@ class TransactionView {
|
||||
this.transactionDialog.showModal();
|
||||
}
|
||||
}
|
||||
|
||||
export default new TransactionView();
|
||||
|
||||
@@ -4,7 +4,7 @@ import Wallet from '../models/wallet';
|
||||
import * as MESSAGE from '../constants/message';
|
||||
import { renderRequiredText } from '../helpers/validateForm';
|
||||
|
||||
class WalletView {
|
||||
export default class WalletView {
|
||||
constructor() {
|
||||
this.walletDialog = document.getElementById('walletDialog');
|
||||
|
||||
@@ -176,5 +176,3 @@ class WalletView {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new WalletView();
|
||||
|
||||
Reference in New Issue
Block a user