11import { Authenticator } from "../auth" ;
2- import { Screen } from "./screen" ;
2+ import { UILoginElements , UIScreen } from "./screen" ;
33
4- export interface UILoginElements {
5- loginForm : HTMLFormElement ;
6- loginInput : HTMLInputElement ;
7- passwordInput : HTMLInputElement ;
8- loginButton : HTMLButtonElement ;
9- }
4+ export class LoginScreenUI extends UIScreen {
5+ public readonly _form : UILoginElements ;
106
11- export class LoginScreenUI extends Screen {
127 public constructor ( auth : Authenticator ) {
13- super ( ) ;
8+ super ( auth , {
9+ authenticationStart : ( ) => {
10+ this . _disableForm ( ) ;
11+ } ,
12+ authenticationComplete : ( ) => {
13+ // TODO: Add a loading animation here
14+ } ,
15+ authenticationFailure : ( ) => {
16+ this . _enableForm ( ) ;
17+ this . _wigglePasswordInput ( ) ;
18+ } ,
19+ errorMessage : ( message : string ) => {
20+ alert ( message ) ;
21+ } ,
22+ infoMessage : ( message : string ) => {
23+ alert ( message ) ;
24+ } ,
25+ } ) ;
1426
1527 this . _auth = auth ;
1628 this . _form = {
@@ -20,10 +32,10 @@ export class LoginScreenUI extends Screen {
2032 loginButton : document . getElementById ( 'login-button' ) as HTMLButtonElement ,
2133 } as UILoginElements ;
2234
23- this . _initLoginForm ( ) ;
35+ this . _initForm ( ) ;
2436 }
2537
26- private _initLoginForm ( ) : void {
38+ protected _initForm ( ) : void {
2739 const form = this . _form as UILoginElements ;
2840
2941 // This event gets called when the user clicks the login button or submits the login form in any other way
@@ -83,23 +95,4 @@ export class LoginScreenUI extends Screen {
8395 }
8496 return form . passwordInput ;
8597 }
86-
87- protected _events = {
88- authenticationStart : ( ) => {
89- this . _disableForm ( ) ;
90- } ,
91- authenticationComplete : ( ) => {
92- // TODO: Add a loading animation here
93- } ,
94- authenticationFailure : ( ) => {
95- this . _enableForm ( ) ;
96- this . _wigglePasswordInput ( ) ;
97- } ,
98- errorMessage : ( message : string ) => {
99- alert ( message ) ;
100- } ,
101- infoMessage : ( message : string ) => {
102- alert ( message ) ;
103- } ,
104- }
10598}
0 commit comments