refactor: updated yew / renamed signin/signup state field `submitted` to `loading`

This commit is contained in:
antifallobst 2023-10-11 12:50:01 +02:00
parent 33419e75f8
commit ca7ed256f8
Signed by: antifallobst
GPG Key ID: 2B4F402172791BAF
4 changed files with 47 additions and 56 deletions

72
Cargo.lock generated
View File

@ -334,7 +334,6 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8d5564e570a38b43d78bdc063374a0c3098c4f0d64005b12f9bbe87e869b6d7"
dependencies = [
"futures-channel",
"gloo-events 0.1.2",
"js-sys",
"wasm-bindgen",
@ -347,6 +346,7 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97563d71863fb2824b2e974e754a81d19c4a7ec47b09ced8a0e6656b6d54bd1f"
dependencies = [
"futures-channel",
"gloo-events 0.2.0",
"js-sys",
"wasm-bindgen",
@ -483,8 +483,6 @@ version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c"
dependencies = [
"futures-channel",
"futures-core",
"js-sys",
"wasm-bindgen",
]
@ -495,6 +493,8 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbb143cf96099802033e0d4f4963b19fd2e0b728bcf076cd9cf7f6634f092994"
dependencies = [
"futures-channel",
"futures-core",
"js-sys",
"wasm-bindgen",
]
@ -573,12 +573,6 @@ dependencies = [
"syn 2.0.31",
]
[[package]]
name = "hashbrown"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]]
name = "hashbrown"
version = "0.14.0"
@ -604,21 +598,11 @@ dependencies = [
[[package]]
name = "implicit-clone"
version = "0.3.6"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c6ecbd987bb94f1f3c76c6787879756cf4b6f73bfff48d79308e8c56b46f65f"
checksum = "af3d77000817fd9e7db159e8d52ed9b5941a2cdbfbdc8ca646e59887ae2b2dd1"
dependencies = [
"indexmap 1.9.3",
]
[[package]]
name = "indexmap"
version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
dependencies = [
"autocfg",
"hashbrown 0.12.3",
"indexmap",
]
[[package]]
@ -628,7 +612,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad227c3af19d4914570ad36d30409928b75967c298feb9ea1969db3a610bb14e"
dependencies = [
"equivalent",
"hashbrown 0.14.0",
"hashbrown",
]
[[package]]
@ -749,12 +733,12 @@ dependencies = [
[[package]]
name = "prettyplease"
version = "0.1.25"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c8646e95016a7a6c4adea95bafa8a16baab64b583356217f2c85db4a39d9a86"
checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d"
dependencies = [
"proc-macro2",
"syn 1.0.109",
"syn 2.0.31",
]
[[package]]
@ -920,7 +904,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
@ -988,7 +971,7 @@ version = "0.19.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421"
dependencies = [
"indexmap 2.0.1",
"indexmap",
"toml_datetime",
"winnow",
]
@ -1031,6 +1014,12 @@ version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
[[package]]
name = "urlencoding"
version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
[[package]]
name = "version_check"
version = "0.9.4"
@ -1124,15 +1113,15 @@ dependencies = [
[[package]]
name = "yew"
version = "0.20.0"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5dbecfe44343b70cc2932c3eb445425969ae21754a8ab3a0966981c1cf7af1cc"
checksum = "5f1a03f255c70c7aa3e9c62e15292f142ede0564123543c1cc0c7a4f31660cac"
dependencies = [
"console_error_panic_hook",
"futures",
"gloo 0.8.1",
"gloo 0.10.0",
"implicit-clone",
"indexmap 1.9.3",
"indexmap",
"js-sys",
"prokio",
"rustversion",
@ -1149,9 +1138,9 @@ dependencies = [
[[package]]
name = "yew-macro"
version = "0.20.0"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b64c253c1d401f1ea868ca9988db63958cfa15a69f739101f338d6f05eea8301"
checksum = "02fd8ca5166d69e59f796500a2ce432ff751edecbbb308ca59fd3fe4d0343de2"
dependencies = [
"boolinator",
"once_cell",
@ -1159,21 +1148,22 @@ dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
"syn 1.0.109",
"syn 2.0.31",
]
[[package]]
name = "yew-router"
version = "0.17.0"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "426ee0486d2572a6c5e39fbdbc48b58d59bb555f3326f54631025266cf04146e"
checksum = "4ca1d5052c96e6762b4d6209a8aded597758d442e6c479995faf0c7b5538e0c6"
dependencies = [
"gloo 0.8.1",
"gloo 0.10.0",
"js-sys",
"route-recognizer",
"serde",
"serde_urlencoded",
"tracing",
"urlencoding",
"wasm-bindgen",
"web-sys",
"yew",
@ -1182,11 +1172,11 @@ dependencies = [
[[package]]
name = "yew-router-macro"
version = "0.17.0"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89b249cdb39e0cddaf0644dedc781854524374664793479fdc01e6a65d6e6ae3"
checksum = "42bfd190a07ca8cfde7cd4c52b3ac463803dc07323db8c34daa697e86365978c"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
"syn 2.0.31",
]

View File

@ -13,8 +13,8 @@ serde_json = "1.0"
futures-channel = "0.3.28"
# Yew
yew = { version = "0.20.0", features = ["csr"] }
yew-router = "0.17.0"
yew = { version = "0.21.0", features = ["csr"] }
yew-router = "0.18.0"
# Web
wasm-bindgen = "0.2.87"

View File

@ -8,8 +8,8 @@ use yew::prelude::*;
#[derive(PartialEq, Clone, Default, Debug)]
struct Data {
pub submitted: bool,
pub status: String,
pub loading: bool,
pub username: String,
pub password: String,
@ -56,16 +56,17 @@ pub fn SignIn(props: &Props) -> Html {
let callback = callbacks.sign_in.clone();
let close_callback = props.close.clone();
let on_sign_in_api_response = Callback::from(move |response: Result<String>| {
let mut data = cloned_state.deref().clone();
let mut state = cloned_state.deref().clone();
state.loading = false;
match response {
Ok(token) => {
callback.emit(token);
close_callback.emit(());
}
Err(e) => data.status = e.to_string(),
Err(e) => state.status = e.to_string(),
}
cloned_state.set(data);
cloned_state.set(state);
});
let callback = on_sign_in_api_response.clone();
@ -74,7 +75,7 @@ pub fn SignIn(props: &Props) -> Html {
event.prevent_default();
let mut state = cloned_state.deref().clone();
state.submitted = true;
state.loading = true;
session.login(
state.username.clone(),
@ -96,7 +97,7 @@ pub fn SignIn(props: &Props) -> Html {
<input class="auth-input" type="password" name="password" onchange={on_password_changed}/><br/>
</div>
if !state.submitted {
if !state.loading {
<div class="center-x">
<button class="auth-submit" type="submit">{"Sign In"}</button>
</div>

View File

@ -1,6 +1,6 @@
use crate::backend::Session;
use crate::Callbacks;
use anyhow::Result;
use anyhow::{Error, Result};
use std::ops::Deref;
use wasm_bindgen::JsCast;
use web_sys::HtmlInputElement;
@ -22,7 +22,7 @@ impl Default for View {
struct Data {
pub view: View,
pub status: String,
pub submitted: bool,
pub loading: bool,
pub username: String,
pub email: String,
@ -118,7 +118,7 @@ pub fn SignUp(props: &Props) -> Html {
let cloned_state = state.clone();
let on_sign_up_api_response = Callback::from(move |response: Result<()>| {
let mut state = cloned_state.deref().clone();
state.submitted = false;
state.loading = false;
match response {
Ok(_) => state.view = View::Verify,
@ -133,7 +133,7 @@ pub fn SignUp(props: &Props) -> Html {
let sign_in_callback = callbacks.sign_in.clone();
let on_verify_api_response = Callback::from(move |response: Result<String>| {
let mut state = cloned_state.deref().clone();
state.submitted = false;
state.loading = false;
match response {
Ok(token) => {
@ -151,7 +151,7 @@ pub fn SignUp(props: &Props) -> Html {
event.prevent_default();
let mut state = cloned_state.deref().clone();
state.status = String::default();
state.submitted = true;
state.loading = true;
match state.view {
View::SignUp => session.register(
@ -189,7 +189,7 @@ pub fn SignUp(props: &Props) -> Html {
<input class="auth-input" type="password" name="password-reenter" onchange={on_password_reenter_changed}/><br/>
</div>
if !state.submitted {
if !state.loading {
<div class="center-x">
<button class="auth-submit" type="submit">{"Sign Up"}</button>
</div>
@ -221,7 +221,7 @@ pub fn SignUp(props: &Props) -> Html {
<input class="auth-input" type="text" name="token" onchange={on_token_changed}/><br/>
</div>
if !state.submitted {
if !state.loading {
<div class="center-x">
<button class="auth-submit" type="submit">{"Verify"}</button>
</div>