From 630da4212d84eeedff1cbf69652f8c7e70a8cf6b Mon Sep 17 00:00:00 2001 From: agilarity Date: Fri, 5 May 2023 11:26:09 -0400 Subject: [PATCH] fix: lint issues in `login_with_token_csr_only` example (#995) * build: add common tasks * test: resolve check-style issues --- .../login_with_token_csr_only/Makefile.toml | 2 + .../api-boundary/Makefile.toml | 1 + .../client/Makefile.toml | 1 + .../client/src/api.rs | 3 +- .../client/src/components/credentials.rs | 96 ++++++++++--------- .../client/src/components/navbar.rs | 40 ++++---- .../client/src/lib.rs | 77 ++++++++------- .../client/src/main.rs | 5 +- .../client/src/pages/home.rs | 24 +++-- .../client/src/pages/login.rs | 26 +++-- .../client/src/pages/register.rs | 48 +++++----- .../server/Makefile.toml | 1 + .../server/src/adapters.rs | 3 +- .../server/src/main.rs | 11 ++- 14 files changed, 176 insertions(+), 162 deletions(-) create mode 100644 examples/login_with_token_csr_only/api-boundary/Makefile.toml create mode 100644 examples/login_with_token_csr_only/client/Makefile.toml create mode 100644 examples/login_with_token_csr_only/server/Makefile.toml diff --git a/examples/login_with_token_csr_only/Makefile.toml b/examples/login_with_token_csr_only/Makefile.toml index ab9175602..18313d806 100644 --- a/examples/login_with_token_csr_only/Makefile.toml +++ b/examples/login_with_token_csr_only/Makefile.toml @@ -1,3 +1,5 @@ +extend = { path = "../cargo-make/common.toml" } + [tasks.build] command = "cargo" args = ["+nightly", "build-all-features"] diff --git a/examples/login_with_token_csr_only/api-boundary/Makefile.toml b/examples/login_with_token_csr_only/api-boundary/Makefile.toml new file mode 100644 index 000000000..8861b2dc1 --- /dev/null +++ b/examples/login_with_token_csr_only/api-boundary/Makefile.toml @@ -0,0 +1 @@ +extend = { path = "../../cargo-make/common.toml" } diff --git a/examples/login_with_token_csr_only/client/Makefile.toml b/examples/login_with_token_csr_only/client/Makefile.toml new file mode 100644 index 000000000..8861b2dc1 --- /dev/null +++ b/examples/login_with_token_csr_only/client/Makefile.toml @@ -0,0 +1 @@ +extend = { path = "../../cargo-make/common.toml" } diff --git a/examples/login_with_token_csr_only/client/src/api.rs b/examples/login_with_token_csr_only/client/src/api.rs index 8fb4fb174..d4bcda1be 100644 --- a/examples/login_with_token_csr_only/client/src/api.rs +++ b/examples/login_with_token_csr_only/client/src/api.rs @@ -1,9 +1,8 @@ +use api_boundary::*; use gloo_net::http::{Request, Response}; use serde::de::DeserializeOwned; use thiserror::Error; -use api_boundary::*; - #[derive(Clone, Copy)] pub struct UnauthorizedApi { url: &'static str, diff --git a/examples/login_with_token_csr_only/client/src/components/credentials.rs b/examples/login_with_token_csr_only/client/src/components/credentials.rs index f287c7029..a6dfc4b82 100644 --- a/examples/login_with_token_csr_only/client/src/components/credentials.rs +++ b/examples/login_with_token_csr_only/client/src/components/credentials.rs @@ -20,54 +20,56 @@ pub fn CredentialsForm( }); view! { cx, -
-

{ title }

- {move || error.get().map(|err| view!{ cx, -

{ err }

- })} - - { - dispatch_action(); + +

{title}

+ {move || { + error + .get() + .map(|err| { + view! { cx,

{err}

} + }) + }} + { - let val = event_target_value(&ev); - set_password.update(|p|*p = val); + on:change=move |ev| { + let val = event_target_value(&ev); + set_email.update(|v| *v = val); } - } - } - // The `change` event fires when the browser fills the form automatically, - on:change = move |ev| { - let val = event_target_value(&ev); - set_password.update(|p|*p = val); - } - /> - -
+ /> + { + dispatch_action(); + } + _ => { + let val = event_target_value(&ev); + set_password.update(|p| *p = val); + } + } + } + on:change=move |ev| { + let val = event_target_value(&ev); + set_password.update(|p| *p = val); + } + /> + + } } diff --git a/examples/login_with_token_csr_only/client/src/components/navbar.rs b/examples/login_with_token_csr_only/client/src/components/navbar.rs index 485f36bee..246128a91 100644 --- a/examples/login_with_token_csr_only/client/src/components/navbar.rs +++ b/examples/login_with_token_csr_only/client/src/components/navbar.rs @@ -1,8 +1,7 @@ +use crate::Page; use leptos::*; use leptos_router::*; -use crate::Page; - #[component] pub fn NavBar( cx: Scope, @@ -13,20 +12,27 @@ where F: Fn() + 'static + Clone, { view! { cx, - + } } diff --git a/examples/login_with_token_csr_only/client/src/lib.rs b/examples/login_with_token_csr_only/client/src/lib.rs index b1a6b1ea7..cc89eeba9 100644 --- a/examples/login_with_token_csr_only/client/src/lib.rs +++ b/examples/login_with_token_csr_only/client/src/lib.rs @@ -1,9 +1,8 @@ +use api_boundary::*; use gloo_storage::{LocalStorage, Storage}; use leptos::*; use leptos_router::*; -use api_boundary::*; - mod api; mod components; mod pages; @@ -86,45 +85,51 @@ pub fn App(cx: Scope) -> impl IntoView { .expect("LocalStorage::set"); } None => { - log::debug!("API is no longer authorized: delete token from LocalStorage"); + log::debug!( + "API is no longer authorized: delete token from \ + LocalStorage" + ); LocalStorage::delete(API_TOKEN_STORAGE_KEY); } } }); view! { cx, - - -
- - - } - /> - - } - /> - - } - /> - -
-
+ + +
+ + } + } + /> + + } + } + /> + } + } + /> + +
+
} } diff --git a/examples/login_with_token_csr_only/client/src/main.rs b/examples/login_with_token_csr_only/client/src/main.rs index 5643a2ea1..5fc342348 100644 --- a/examples/login_with_token_csr_only/client/src/main.rs +++ b/examples/login_with_token_csr_only/client/src/main.rs @@ -1,9 +1,8 @@ -use leptos::*; - use client::*; +use leptos::*; pub fn main() { _ = console_log::init_with_level(log::Level::Debug); console_error_panic_hook::set_once(); - mount_to_body(|cx| view! { cx, }) + mount_to_body(|cx| view! { cx, }) } diff --git a/examples/login_with_token_csr_only/client/src/pages/home.rs b/examples/login_with_token_csr_only/client/src/pages/home.rs index 7b5c5a80b..34fcbd582 100644 --- a/examples/login_with_token_csr_only/client/src/pages/home.rs +++ b/examples/login_with_token_csr_only/client/src/pages/home.rs @@ -6,15 +6,19 @@ use leptos_router::*; #[component] pub fn Home(cx: Scope, user_info: Signal>) -> impl IntoView { view! { cx, -

"Leptos Login example"

- {move || match user_info.get() { - Some(info) => view!{ cx, -

"You are logged in with "{ info.email }"."

- }.into_view(cx), - None => view!{ cx, -

"You are not logged in."

- "Login now." - }.into_view(cx) - }} +

"Leptos Login example"

+ {move || match user_info.get() { + Some(info) => { + view! { cx,

"You are logged in with " {info.email} "."

} + .into_view(cx) + } + None => { + view! { cx, +

"You are not logged in."

+ "Login now." + } + .into_view(cx) + } + }} } } diff --git a/examples/login_with_token_csr_only/client/src/pages/login.rs b/examples/login_with_token_csr_only/client/src/pages/login.rs index 2de0f841d..74df958ce 100644 --- a/examples/login_with_token_csr_only/client/src/pages/login.rs +++ b/examples/login_with_token_csr_only/client/src/pages/login.rs @@ -1,13 +1,11 @@ -use leptos::*; -use leptos_router::*; - -use api_boundary::*; - use crate::{ api::{self, AuthorizedApi, UnauthorizedApi}, components::credentials::*, Page, }; +use api_boundary::*; +use leptos::*; +use leptos_router::*; #[component] pub fn Login(cx: Scope, api: UnauthorizedApi, on_success: F) -> impl IntoView @@ -53,14 +51,14 @@ where let disabled = Signal::derive(cx, move || wait_for_response.get()); view! { cx, - -

"Don't have an account?"

- "Register" + +

"Don't have an account?"

+ "Register" } } diff --git a/examples/login_with_token_csr_only/client/src/pages/register.rs b/examples/login_with_token_csr_only/client/src/pages/register.rs index 008012913..274342448 100644 --- a/examples/login_with_token_csr_only/client/src/pages/register.rs +++ b/examples/login_with_token_csr_only/client/src/pages/register.rs @@ -1,13 +1,11 @@ -use leptos::*; -use leptos_router::*; - -use api_boundary::*; - use crate::{ api::{self, UnauthorizedApi}, components::credentials::*, Page, }; +use api_boundary::*; +use leptos::*; +use leptos_router::*; #[component] pub fn Register(cx: Scope, api: UnauthorizedApi) -> impl IntoView { @@ -52,26 +50,24 @@ pub fn Register(cx: Scope, api: UnauthorizedApi) -> impl IntoView { let disabled = Signal::derive(cx, move || wait_for_response.get()); view! { cx, - -

"Your already have an account?"

- "Login" - } - > -

"You have successfully registered."

-

- "You can now " - "login" - " with your new account." -

-
+ +

"Your already have an account?"

+ "Login" + } + } + > +

"You have successfully registered."

+

"You can now " "login" " with your new account."

+
} } diff --git a/examples/login_with_token_csr_only/server/Makefile.toml b/examples/login_with_token_csr_only/server/Makefile.toml new file mode 100644 index 000000000..8861b2dc1 --- /dev/null +++ b/examples/login_with_token_csr_only/server/Makefile.toml @@ -0,0 +1 @@ +extend = { path = "../../cargo-make/common.toml" } diff --git a/examples/login_with_token_csr_only/server/src/adapters.rs b/examples/login_with_token_csr_only/server/src/adapters.rs index 9d7e491d5..2bd587615 100644 --- a/examples/login_with_token_csr_only/server/src/adapters.rs +++ b/examples/login_with_token_csr_only/server/src/adapters.rs @@ -2,8 +2,7 @@ use crate::{application::*, Error}; use api_boundary as json; use axum::{ http::StatusCode, - response::Json, - response::{IntoResponse, Response}, + response::{IntoResponse, Json, Response}, }; use thiserror::Error; diff --git a/examples/login_with_token_csr_only/server/src/main.rs b/examples/login_with_token_csr_only/server/src/main.rs index 3eb3f880e..8d7566add 100644 --- a/examples/login_with_token_csr_only/server/src/main.rs +++ b/examples/login_with_token_csr_only/server/src/main.rs @@ -1,5 +1,4 @@ -use std::{env, sync::Arc}; - +use api_boundary as json; use axum::{ extract::{State, TypedHeader}, headers::{authorization::Bearer, Authorization}, @@ -8,10 +7,9 @@ use axum::{ routing::{get, post}, Router, }; +use std::{env, sync::Arc}; use tower_http::cors::{Any, CorsLayer}; -use api_boundary as json; - mod adapters; mod application; @@ -25,7 +23,10 @@ async fn main() -> anyhow::Result<()> { env::set_var("RUST_LOG", "debug"); } env::VarError::NotUnicode(_) => { - return Err(anyhow::anyhow!("The value of 'RUST_LOG' does not contain valid unicode data.")); + return Err(anyhow::anyhow!( + "The value of 'RUST_LOG' does not contain valid unicode \ + data." + )); } } }