Ignore:
Timestamp:
06/11/22 23:50:19 (2 years ago)
Author:
anastasovv <simon@…>
Branches:
main
Children:
4a1a3ca
Parents:
87614a5
Message:

Code cleanings

File:
1 edited

Legend:

Unmodified
Added
Removed
  • components/LoginScreen.jsx

    r87614a5 r64dc53b  
    22
    33import { useSelector, useDispatch } from 'react-redux'
     4
     5import { useRef } from 'react'
    46
    57import { setPlayer } from '../redux/reducers/playerSlice';
     
    911
    1012const LoginScreen = () => {
     13    const ref = useRef(null);
     14
    1115    const dispatch = useDispatch();
    1216
    1317    const playerState = useSelector(state => state.player);
    1418    const styleState = useSelector(state => state.style);
     19
     20    setTimeout(() => {
     21        if (styleState.style.displayLoginScreen && styleState.style.loginScreenInfo.setFocus) {
     22            ref.current.focus();
     23            dispatch(setStyle({
     24                ...styleState.style,
     25                loginScreenInfo: {
     26                    ...styleState.style.loginScreenInfo,
     27                    setFocus: false
     28                }
     29            }))
     30        }
     31    }, 10);
    1532
    1633    function onChangeUsername(e) {
     
    3451    }
    3552
     53    function keyUp(e) {
     54        if (e.key === 'Enter') {
     55            login();
     56        }
     57    }
     58
    3659    function closeForm() {
    3760        dispatch(setStyle({
     
    4467            inlineAlertText: '',
    4568        }));
     69
    4670    }
    47 
    4871    function login() {
    4972        dispatch(setStyle({
     
    119142                <div>
    120143                    <span>Username:</span>
    121                     <input type="text" onChange={(e) => {onChangeUsername(e)}} value={styleState.style.loginScreenInfo.username}/>
     144                    <input ref={ref} type="text" onChange={(e) => {onChangeUsername(e)}} onKeyUp={(e) => keyUp(e)} value={styleState.style.loginScreenInfo.username} placeholder="your username..."/>
    122145                    <span>Password:</span>
    123                     <input type="password" onChange={(e) => {onChangePassword(e)}} value={styleState.style.loginScreenInfo.password}/>
     146                    <input type="password" onChange={(e) => {onChangePassword(e)}} onKeyUp={(e) => keyUp(e)} value={styleState.style.loginScreenInfo.password} placeholder="your password..."/>
    124147                    <div style={{width: '100%', display: 'flex', flexDirection: 'row', justifyContent: 'space-between'}}>
    125148                        <button className="primaryButton" onClick={() => closeForm()}>Close Form</button>
Note: See TracChangeset for help on using the changeset viewer.