-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix:
TextField
value handling (#210)
Co-authored-by: Michael Liendo <[email protected]>
- Loading branch information
1 parent
3feace8
commit fe1d997
Showing
7 changed files
with
85 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
use crate::components::text_field::{TextField, TextFieldType}; | ||
use leptos::{component, leptos_dom::logging, view, IntoView}; | ||
use leptos::{component, view, IntoView}; | ||
|
||
use crate::components::button::{Button, ButtonVariant}; | ||
|
||
#[component] | ||
pub fn Home() -> impl IntoView { | ||
view! { | ||
<section class="flex flex-col justify-center items-center"> | ||
<img src="/assets/img/townhall.png" alt="TownHall AI Generated" height="500" width="500" /> | ||
<img | ||
src="/assets/img/townhall.png" | ||
alt="TownHall AI Generated" | ||
height="500" | ||
width="500" | ||
/> | ||
<h1>{"AI Generated Picture of a TownHall"}</h1> | ||
<Button variant={ButtonVariant::Text}>{"Text"}</Button> | ||
<Button variant={ButtonVariant::Contained}>{"Contained"}</Button> | ||
<Button variant={ButtonVariant::Outlined}>{"Outlined"}</Button> | ||
<TextField r#type=TextFieldType::Text placeholder="Simple" /> | ||
<TextField placeholder="Label" label="Input Label" id="label" on_input=|val: String| logging::console_log(&val) /> | ||
<TextField placeholder="Disabled" disabled={true}/> | ||
<Button variant=ButtonVariant::Text>{"Text"}</Button> | ||
<Button variant=ButtonVariant::Contained>{"Contained"}</Button> | ||
<Button variant=ButtonVariant::Outlined>{"Outlined"}</Button> | ||
</section> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
use leptos::{component, create_action, create_signal, view, IntoView, Show, SignalGet, SignalSet}; | ||
use leptos::{ | ||
component, create_action, create_rw_signal, create_signal, view, IntoView, Show, SignalGet, | ||
SignalGetUntracked, SignalSet, | ||
}; | ||
|
||
use townhall_client::Client; | ||
|
||
|
@@ -7,12 +10,14 @@ use crate::components::text_field::{TextField, TextFieldType}; | |
#[component] | ||
pub fn Login() -> impl IntoView { | ||
let (error_getter, error_setter) = create_signal::<Option<String>>(None); | ||
let email_value = create_rw_signal(String::default()); | ||
let password_value = create_rw_signal(String::default()); | ||
|
||
let submit = create_action(move |_| async move { | ||
let handle_submit = create_action(move |_| async move { | ||
let client = Client::new(); | ||
let res = client | ||
.auth | ||
.token_create("[email protected]".into(), "12345".into()) | ||
.token_create(email_value.get_untracked(), password_value.get_untracked()) | ||
.await; | ||
|
||
if let Some(ref error) = res.error { | ||
|
@@ -21,24 +26,39 @@ pub fn Login() -> impl IntoView { | |
}); | ||
|
||
view! { | ||
<div class="min-h-screen relative flex justify-center items-center bg-no-repeat bg-cover bg-slate-800 bg-[url('https://images.unsplash.com/photo-1580192985016-7e15ef081dd8?q=80&w=1961&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D')]"> | ||
<div class="absolute bg-black rounded-[50%] w-full h-full blur-[23rem]"></div> | ||
<div class="flex justify-center items-center z-20"> | ||
<div class="w-full"> | ||
<h1 class="text-6xl text-center font-bold text-white mb-16">TownHall</h1> | ||
<form class="w-96"> | ||
<TextField class="w-full" name="email" placeholder="Email" /> | ||
<TextField class="w-full" name="password" r#type=TextFieldType::Password placeholder="Password" /> | ||
<button type="button" on:click={move |_| submit.dispatch(())}>Login</button> | ||
<Show when=move ||error_getter.get().is_some()> | ||
<div class="bg-rose-600 text-white p-2 rounded-md"> | ||
{error_getter.get().unwrap()} | ||
<div class="min-h-screen relative flex justify-center items-center bg-no-repeat bg-cover bg-slate-800 bg-[url('https://images.unsplash.com/photo-1580192985016-7e15ef081dd8?q=80&w=1961&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D')]"> | ||
<div class="absolute bg-black rounded-[50%] w-full h-full blur-[23rem]"></div> | ||
<div class="flex justify-center items-center z-20"> | ||
<div class="w-full"> | ||
<h1 class="text-6xl text-center font-bold text-white mb-16">TownHall</h1> | ||
<form class="w-96" on:submit=move |_| handle_submit.dispatch(())> | ||
<TextField | ||
class="w-full" | ||
name="email" | ||
placeholder="Email" | ||
value=email_value | ||
/> | ||
<TextField | ||
class="w-full" | ||
name="password" | ||
r#type=TextFieldType::Password | ||
placeholder="Password" | ||
value=password_value | ||
/> | ||
<button type="submit">Login</button> | ||
<Show when=move || error_getter.get().is_some()> | ||
<div class="bg-rose-600 text-white p-2 rounded-md"> | ||
{error_getter.get().unwrap()} | ||
</div> | ||
</Show> | ||
</form> | ||
<div class="text-center w-full text-white mt-3"> | ||
{"Don't have an account? "} <a class="underline" href="/signup"> | ||
Sign up! | ||
</a> | ||
</div> | ||
</Show> | ||
</form> | ||
<div class="text-center w-full text-white mt-3">{"Don't have an account? "}<a class="underline" href="/signup">Sign up!</a></div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters