mirror of
https://github.com/Nezumi-2711/javascript-training.git
synced 2026-09-23 04:09:58 +00:00
Fix View object call twice
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user