diff --git a/visions/ui/src/main.rs b/visions/ui/src/main.rs index a5b91c4..99cc11d 100644 --- a/visions/ui/src/main.rs +++ b/visions/ui/src/main.rs @@ -1,13 +1,54 @@ +use std::rc::Rc; + use yew::prelude::*; +struct AuthInfo { + session_id: Option, +} + +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, action: Self::Action) -> Rc { + 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<()>, +} + #[function_component] -fn Login() -> Html { +fn Login(LoginProps { on_click }: &LoginProps) -> Html { + let on_click = { + let on_click = on_click.clone(); + Callback::from(move |_| on_click.emit(())) + }; html! { } @@ -15,8 +56,17 @@ fn Login() -> Html { #[function_component] fn App() -> Html { - html! { - + 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! {

{ "this is just a thing" }

} + } else { + html! { } } }