mirror of
https://github.com/zaphar/kitchen.git
synced 2025-07-22 19:40:14 -04:00
Use handler in login form
This commit is contained in:
parent
9881d2972b
commit
69dc4b99cf
@ -14,10 +14,10 @@
|
|||||||
use sycamore::{futures::spawn_local_scoped, prelude::*};
|
use sycamore::{futures::spawn_local_scoped, prelude::*};
|
||||||
use tracing::{debug, info};
|
use tracing::{debug, info};
|
||||||
|
|
||||||
use crate::app_state::{self, StateHandler};
|
use crate::app_state::{Message, StateHandler};
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn LoginForm<G: Html>(cx: Scope) -> View<G> {
|
pub fn LoginForm<'ctx, G: Html>(cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> View<G> {
|
||||||
let username = create_signal(cx, "".to_owned());
|
let username = create_signal(cx, "".to_owned());
|
||||||
let password = create_signal(cx, "".to_owned());
|
let password = create_signal(cx, "".to_owned());
|
||||||
let clicked = create_signal(cx, ("".to_owned(), "".to_owned()));
|
let clicked = create_signal(cx, ("".to_owned(), "".to_owned()));
|
||||||
@ -25,11 +25,12 @@ pub fn LoginForm<G: Html>(cx: Scope) -> View<G> {
|
|||||||
let (username, password) = (*clicked.get()).clone();
|
let (username, password) = (*clicked.get()).clone();
|
||||||
if username != "" && password != "" {
|
if username != "" && password != "" {
|
||||||
spawn_local_scoped(cx, async move {
|
spawn_local_scoped(cx, async move {
|
||||||
let state = app_state::State::get_from_context(cx);
|
|
||||||
let store = crate::api::HttpStore::get_from_context(cx);
|
let store = crate::api::HttpStore::get_from_context(cx);
|
||||||
debug!("authenticating against ui");
|
debug!("authenticating against ui");
|
||||||
// TODO(jwall): Navigate to plan if the below is successful.
|
// TODO(jwall): Navigate to plan if the below is successful.
|
||||||
state.auth.set(store.authenticate(username, password).await);
|
if let Some(user_data) = store.authenticate(username, password).await {
|
||||||
|
sh.dispatch(Message::SetUserData(user_data));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -52,6 +53,6 @@ pub fn LoginForm<G: Html>(cx: Scope) -> View<G> {
|
|||||||
#[component]
|
#[component]
|
||||||
pub fn LoginPage<'ctx, G: Html>(cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> View<G> {
|
pub fn LoginPage<'ctx, G: Html>(cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> View<G> {
|
||||||
view! {cx,
|
view! {cx,
|
||||||
LoginForm()
|
LoginForm(sh)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user