2025-02-18 13:25:40 +00:00
|
|
|
use std::rc::Rc;
|
|
|
|
|
2025-02-18 04:03:12 +00:00
|
|
|
use yew::prelude::*;
|
|
|
|
|
2025-02-18 13:25:40 +00:00
|
|
|
struct AuthInfo {
|
|
|
|
session_id: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for AuthInfo {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self { session_id: None }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum AuthAction {
|
|
|
|
Auth(String),
|
|
|
|
Unauth,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Reducible for AuthInfo {
|
|
|
|
type Action = AuthAction;
|
|
|
|
|
|
|
|
fn reduce(self: Rc<Self>, action: Self::Action) -> Rc<Self> {
|
|
|
|
match action {
|
|
|
|
AuthAction::Auth(session_id) => Self {
|
|
|
|
session_id: Some(session_id),
|
|
|
|
}
|
|
|
|
.into(),
|
|
|
|
AuthAction::Unauth => Self { session_id: None }.into(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Properties, PartialEq)]
|
|
|
|
struct LoginProps {
|
|
|
|
on_click: Callback<()>,
|
|
|
|
}
|
|
|
|
|
2025-02-18 04:03:12 +00:00
|
|
|
#[function_component]
|
2025-02-18 13:25:40 +00:00
|
|
|
fn Login(LoginProps { on_click }: &LoginProps) -> Html {
|
|
|
|
let on_click = {
|
|
|
|
let on_click = on_click.clone();
|
|
|
|
Callback::from(move |_| on_click.emit(()))
|
|
|
|
};
|
2025-02-18 04:03:12 +00:00
|
|
|
html! {
|
|
|
|
<div class="login-form">
|
|
|
|
<div class="card">
|
|
|
|
<h1>{"Welcome to Visions VTT"}</h1>
|
|
|
|
<input type="text" name="username" placeholder="username" />
|
|
|
|
<input type="password" name="password" placeholder="password" />
|
2025-02-18 13:25:40 +00:00
|
|
|
<button onclick={on_click}>{"Login"}</button>
|
2025-02-18 04:03:12 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[function_component]
|
|
|
|
fn App() -> Html {
|
2025-02-18 13:25:40 +00:00
|
|
|
let auth_info = use_reducer(AuthInfo::default);
|
|
|
|
|
|
|
|
let on_login = {
|
|
|
|
let auth_info = auth_info.clone();
|
|
|
|
Callback::from(move |_| auth_info.dispatch(AuthAction::Auth("abcdefg".into())))
|
|
|
|
};
|
|
|
|
|
|
|
|
if auth_info.session_id.is_some() {
|
|
|
|
html! { <p>{ "this is just a thing" }</p> }
|
|
|
|
} else {
|
|
|
|
html! { <Login on_click={on_login.clone()} /> }
|
2025-02-18 04:03:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
yew::Renderer::<App>::new().render();
|
|
|
|
}
|