| 
									
										
										
										
											2021-03-14 14:51:53 +00:00
										 |  |  | import React from 'react'; | 
					
						
							|  |  |  | import {Button} from '../../elements/GPElements/Button'; | 
					
						
							|  |  |  | import style from './AuthenticationPage.module.css'; | 
					
						
							| 
									
										
										
										
											2021-03-16 20:44:32 +01:00
										 |  |  | import {addKeyHandler, removeKeyHandler} from '../../utils/ShortkeyHandler'; | 
					
						
							| 
									
										
										
										
											2021-03-14 12:49:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | interface state { | 
					
						
							| 
									
										
										
										
											2021-03-14 14:51:53 +00:00
										 |  |  |     pwdText: string; | 
					
						
							| 
									
										
										
										
											2021-03-14 12:49:24 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-14 14:51:53 +00:00
										 |  |  | interface Props { | 
					
						
							|  |  |  |     submit: (password: string) => void; | 
					
						
							| 
									
										
										
										
											2021-03-14 12:49:24 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-14 14:51:53 +00:00
										 |  |  | class AuthenticationPage extends React.Component<Props, state> { | 
					
						
							|  |  |  |     constructor(props: Props) { | 
					
						
							| 
									
										
										
										
											2021-03-14 12:49:24 +00:00
										 |  |  |         super(props); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.state = { | 
					
						
							|  |  |  |             pwdText: '' | 
					
						
							| 
									
										
										
										
											2021-03-14 14:51:53 +00:00
										 |  |  |         }; | 
					
						
							| 
									
										
										
										
											2021-03-16 20:44:32 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         this.keypress = this.keypress.bind(this); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     componentDidMount(): void { | 
					
						
							|  |  |  |         addKeyHandler(this.keypress); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     componentWillUnmount(): void { | 
					
						
							|  |  |  |         removeKeyHandler(this.keypress); | 
					
						
							| 
									
										
										
										
											2021-03-14 12:49:24 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     render(): JSX.Element { | 
					
						
							|  |  |  |         return ( | 
					
						
							|  |  |  |             <> | 
					
						
							|  |  |  |                 <div className={style.openmediacenterlabel}>OpenMediaCenter</div> | 
					
						
							|  |  |  |                 <div className={style.main}> | 
					
						
							|  |  |  |                     <div className={style.loginText}>Login</div> | 
					
						
							|  |  |  |                     <div> | 
					
						
							| 
									
										
										
										
											2021-03-14 14:51:53 +00:00
										 |  |  |                         <input | 
					
						
							|  |  |  |                             className={style.input} | 
					
						
							|  |  |  |                             placeholder='Password' | 
					
						
							|  |  |  |                             type='password' | 
					
						
							|  |  |  |                             onChange={(ch): void => this.setState({pwdText: ch.target.value})} | 
					
						
							|  |  |  |                             value={this.state.pwdText} | 
					
						
							|  |  |  |                         /> | 
					
						
							| 
									
										
										
										
											2021-03-14 12:49:24 +00:00
										 |  |  |                     </div> | 
					
						
							|  |  |  |                     <div> | 
					
						
							| 
									
										
										
										
											2021-03-14 14:51:53 +00:00
										 |  |  |                         <Button | 
					
						
							|  |  |  |                             title='Submit' | 
					
						
							|  |  |  |                             onClick={(): void => { | 
					
						
							|  |  |  |                                 this.props.submit(this.state.pwdText); | 
					
						
							|  |  |  |                             }} | 
					
						
							|  |  |  |                         /> | 
					
						
							| 
									
										
										
										
											2021-03-14 12:49:24 +00:00
										 |  |  |                     </div> | 
					
						
							|  |  |  |                 </div> | 
					
						
							|  |  |  |             </> | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-03-16 20:44:32 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * key event handling | 
					
						
							|  |  |  |      * @param event keyevent | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     keypress(event: KeyboardEvent): void { | 
					
						
							|  |  |  |         // hide if escape is pressed
 | 
					
						
							|  |  |  |         if (event.key === 'Enter') { | 
					
						
							|  |  |  |             // call a parentsubmit if defined
 | 
					
						
							|  |  |  |             if (this.props.submit) { | 
					
						
							|  |  |  |                 this.props.submit(this.state.pwdText); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-03-14 12:49:24 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-14 14:51:53 +00:00
										 |  |  | export default AuthenticationPage; |