/*
* This file is part of sdbclient
* Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
*
* Licensed under GPL-3.0-only.
* See LICENSE for licensing information.
*/
use bevy::prelude::*;
use iyes_loopless::prelude::*;
use belly::prelude::*;
use regex::Regex;
use crate::plugins::menu::MenuState;
use super::LoginState;
/// Login inputs
#[derive(Resource, Debug, Component, PartialEq, Eq, Clone)]
pub(super) struct InputsUserLogin {
pub email: String,
pub password: String,
pub visible_pwd: String,
pub error: String,
}
impl InputsUserLogin {
pub fn new() -> Self {
Self {
email: "".to_string(),
password: "".to_string(),
visible_pwd: "".to_string(),
error: "".to_string(),
}
}
}
pub(super) fn account_login_setup(mut commands: Commands /*, pwd: Res<Password>*/) {
let input_email = commands.spawn_empty().id();
let input_password = commands.spawn_empty().id();
//let visible_pwd = pwd.visible.clone();
commands.add(eml! {
<body>
<div c:menu>
<span c:menutitle>
"Login"
</span>
<span>"Email:"</span>
<textinput {input_email} bind:value=to!(input_email, Label:value | fmt.val("{val}"))/>
<span>"Password:"</span>
<textinput {input_password} bind:value=from!(InputsUserLogin:password | fmt.s("{s}"))/>
<button c:menubutton on:press=connect!(|ctx| {
//ctx.commands().insert_resource(NextState(LoginState::LoggingIn))
})>
"Login"
</button>
<button c:menubutton on:press=connect!(|ctx| {
ctx.commands().insert_resource(NextState(LoginState::None));
ctx.commands().insert_resource(NextState(MenuState::AccountLoggedOut));
})>
"Cancel"
</button>
</div>
</body>
});
}
/*
pub fn account_login_ui(
mut commands: Commands,
mut egui_context: ResMut<EguiContext>,
mut inputs: ResMut<InputsUserLogin>,
) {
egui::Window::new("Login")
.collapsible(false)
.show(egui_context.ctx_mut(), |ui| {
ui.horizontal(|ui| {
ui.label("Email: ");
ui.text_edit_singleline(&mut inputs.email);
});
ui.horizontal(|ui| {
ui.label("Password: ");
ui.add(eguipwd::password(&mut inputs.password));
});
// Show an error if there is one
if !inputs.error.is_empty() {
ui.horizontal(|ui| {
ui.label(egui::RichText::new(inputs.error.clone()).color(egui::Color32::RED));
});
}
ui.with_layout(egui::Layout::right_to_left(egui::Align::Min), |ui| {
if ui.button("Cancel").clicked() {
commands.insert_resource(NextState(LoginState::None));
commands.insert_resource(NextState(MenuState::AccountLoggedOut));
}
if ui.button("Login").clicked() {
commands.insert_resource(NextState(LoginState::LoggingIn));
// Reset error field
inputs.error = "".to_string();
}
})
});
}
*/