<commit_before>import { Credentials } from 'sdi/source';
import tr from 'sdi/locale';
import { DIV, H1, INPUT } from 'sdi/components/elements';

import { getUsername, getPassword } from '../../queries/login';
import { setUsername, setPassword, tryLogin } from '../../events/login';
import { button } from '../button';



export interface LoginForm {
    credentials: Credentials;
}

export const defaultLoginForm =
    (): LoginForm => ({
        credentials: {
            username: '',
            password: '',
        },
    });


const loginButton = button('login', 'login');

const renderUsername =
    () => (
        DIV({ className: 'username' },
            DIV({ className: 'label' }, tr('userName')),
            INPUT({
                type: 'text',
                defaultValue: getUsername(),
                onChange: e => setUsername(e.currentTarget.value),
            })));


const renderPassword =
    () => (
        DIV({ className: 'password' },
            DIV({ className: 'label' }, tr('password')),
            INPUT({
                type: 'password',
                defaultValue: getPassword(),
                onChange: e => setPassword(e.currentTarget.value),
            })));
<commit_msg>[login] try login on enter key<commit_after>import { Credentials } from 'sdi/source';
import tr from 'sdi/locale';
import { DIV, H1, INPUT } from 'sdi/components/elements';
import { isENTER } from 'sdi/components/keycodes';

import { getUsername, getPassword } from '../../queries/login';
import { setUsername, setPassword, tryLogin } from '../../events/login';
import { button } from '../button';



export interface LoginForm {
    credentials: Credentials;
}

export const defaultLoginForm =
    (): LoginForm => ({
        credentials: {
            username: '',
            password: '',
        },
    });

const tryOnReturn =
    (e: React.KeyboardEvent<HTMLInputElement>) => {
        if (isENTER(e)) {
            tryLogin();
        }
    };

const loginButton = button('login', 'login');

const renderUsername =
    () => (
        DIV({ className: 'username' },
            DIV({ className: 'label' }, tr('userName')),
            INPUT({
                type: 'text',
                defaultValue: getUsername(),
                onChange: e => setUsername(e.currentTarget.value),
                onKeyUp: tryOnReturn,
            })));


const renderPassword =
    () => (
        DIV({ className: 'password' },
            DIV({ className: 'label' }, tr('password')),
            INPUT({
                type: 'password',
                defaultValue: getPassword(),
                onChange: e => setPassword(e.currentTarget.value),
                onKeyUp: tryOnReturn,
            })));

{'fraction_non_alphanumeric': 0.15254858819215256, 'fraction_numerical': 0.0007334066740007334, 'mean_word_length': 2.0582959641255605, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2746014', 'n_tokens_mistral': 751, 'n_tokens_neox': 721, 'n_words': 178}