Fix View object call twice

This commit is contained in:
2023-09-09 17:53:56 +07:00
parent b62dd17f73
commit 409cba5b8f
5 changed files with 27 additions and 4 deletions
@@ -12,6 +12,12 @@ export const MESSAGE = {
USER_EXIST_ERROR: 'User is exists! Please try another email!',
};
export const URL = {
LOGIN: 'login',
REGISTER: 'register',
HOME: 'home',
};
export const BTN_CONTENT = {
GOT_IT: 'Got it!',
OK: 'Ok',
@@ -9,7 +9,7 @@ export default class LoginController {
}
init() {
if (this.loginView.isLoginPage()) {
if (this.loginView) {
this.loginView.addHandlerForm(this.handlerValidateUser.bind(this));
}
}
@@ -13,7 +13,7 @@ export default class RegisterController {
}
init() {
if (this.registerView.isRegisterPage()) {
if (this.registerView) {
this.registerView.addHandlerForm(
this.hanlderCheckUserExist.bind(this),
this.handlerSaveUser.bind(this),
@@ -62,3 +62,11 @@ export const convertDataObjectToModel = (data) => {
return { id, ...object.data };
};
export const getURL = () => {
const url = window.location.href;
const parts = url.split('/');
const lastPart = parts.pop(); // Lấy phần tử cuối cùng trong mảng
return lastPart;
};
+11 -2
View File
@@ -1,9 +1,18 @@
import RegisterView from './registerView';
import LoginView from './loginView';
import { getURL } from '../helpers/helpers';
import { URL } from '../constants/constant';
export default class View {
constructor() {
this.registerView = new RegisterView();
this.loginView = new LoginView();
switch (getURL()) {
case URL.LOGIN:
this.loginView = new LoginView();
break;
case URL.REGISTER:
this.registerView = new RegisterView();
break;
default:
}
}
}