1-
1+ import { AuthorizationPage } from './authorization-page/authorization-page' ;
22import { ContactPage } from './contact/contact' ;
33import { KeypadPage } from './keypad/keypad' ;
44import { AddUserPage } from './add-user/add-user' ;
55
66class App {
77 constructor ( ) {
88 this . store = this . createStore ( ) ;
9- this . pages = {
10- 'contacts' : new ContactPage ( this . store ) ,
11- 'keypad' : new KeypadPage ( this . store ) ,
12- 'addUser' : new AddUserPage ( this . store ) ,
13- 'footer' : new FooterNavigationBar ( )
14- }
15- this . pages . contacts . setStateContact ( ) ;
16- this . render ( ) ;
17- this . pages . contacts . applyListenerForContactPage ( ) ;
18- this . applyListenerForNavigation ( ) ;
9+ this . authorizationPage = new AuthorizationPage ( ) ;
10+ this . renderAuthorizationPage ( ) ;
1911 }
2012
2113 createStore ( ) {
@@ -27,7 +19,7 @@ class App {
2719 } ,
2820 setState ( newState ) {
2921 state = newState ;
30- }
22+ }
3123 }
3224 }
3325
@@ -48,6 +40,7 @@ class App {
4840 if ( action . type === 'MOVE_TO_CONTACT_PAGE' ) {
4941 this . pages . contacts . setStateContact ( ) ;
5042 switchBetweenPages ( ) ;
43+ this . pages . contacts . renderUsers ( ) ;
5144 this . pages . contacts . applyListenerForContactPage ( ) ;
5245 return ;
5346 }
@@ -61,6 +54,54 @@ class App {
6154
6255 }
6356
57+ renderAuthorizationPage ( ) {
58+ const authorizationPage = this . authorizationPage . render ( ) ;
59+ const mountMode = document . getElementById ( 'mountMode' ) ;
60+ mountMode . innerHTML = authorizationPage ;
61+ this . applyListenerForAuthorizationPage ( ) ;
62+ }
63+
64+ applyListenerForAuthorizationPage ( ) {
65+ const input = document . querySelector ( '.au-input' ) ;
66+ const logInButton = document . getElementById ( 'log-in' ) ;
67+ const switchBetweenPages = ( ) => {
68+ this . accountName = input . value ;
69+
70+ this . pages = {
71+ 'contacts' : new ContactPage ( this . store , this . accountName ) ,
72+ 'keypad' : new KeypadPage ( this . store , this . accountName ) ,
73+ 'addUser' : new AddUserPage ( this . store , this . accountName ) ,
74+ 'footer' : new FooterNavigationBar ( )
75+ }
76+
77+ this . pages . contacts . setStateContact ( ) ;
78+ this . render ( ) ;
79+ this . pages . contacts . applyListenerForContactPage ( ) ;
80+ this . applyListenerForNavigation ( ) ;
81+ }
82+
83+ const handlerForLogInBtn = ( ) => {
84+ if ( input . value . length > 3 ) {
85+ switchBetweenPages ( ) ;
86+ } else {
87+ alert ( 'So short login' ) ;
88+ }
89+ } ;
90+
91+ const handlerForLogInInput = ( e ) => {
92+ if ( e . keyCode === 13 ) {
93+ if ( input . value . length > 3 ) {
94+ switchBetweenPages ( ) ;
95+ } else {
96+ alert ( 'So short login' ) ;
97+ }
98+ }
99+ } ;
100+
101+ logInButton . addEventListener ( 'click' , handlerForLogInBtn ) ;
102+ input . addEventListener ( 'keydown' , handlerForLogInInput ) ;
103+ }
104+
64105 render ( ) {
65106 const currentState = this . store . getState ( ) ;
66107 const FOOTER = this . pages . footer . render ( ) ;
@@ -74,6 +115,8 @@ class App {
74115
75116 const mountMode = document . getElementById ( 'mountMode' ) ;
76117 mountMode . innerHTML = appTemplate ;
118+
119+ this . pages . contacts . renderUsers ( ) ;
77120 }
78121
79122 applyListenerForNavigation ( ) {
0 commit comments