App: Various cleanups (clippy)

This commit is contained in:
Valentin Tolmer 2021-05-30 17:07:34 +02:00
parent c1cb5792fe
commit ac492f987d
5 changed files with 12 additions and 12 deletions

View File

@ -40,7 +40,7 @@ impl Component for App {
fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self { fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self {
let mut app = Self { let mut app = Self {
link: link.clone(), link,
user_name: get_cookie("user_id").unwrap_or_else(|e| { user_name: get_cookie("user_id").unwrap_or_else(|e| {
ConsoleService::error(&e.to_string()); ConsoleService::error(&e.to_string());
None None
@ -89,7 +89,7 @@ impl Component for App {
render = Router::render(move |switch: AppRoute| { render = Router::render(move |switch: AppRoute| {
match switch { match switch {
AppRoute::Login => html! { AppRoute::Login => html! {
<LoginForm on_logged_in=link.callback(|u| Msg::Login(u))/> <LoginForm on_logged_in=link.callback(Msg::Login)/>
}, },
AppRoute::Index | AppRoute::ListUsers => html! { AppRoute::Index | AppRoute::ListUsers => html! {
<div> <div>
@ -112,7 +112,7 @@ impl App {
if current_route.is_empty() || current_route.contains("login") { if current_route.is_empty() || current_route.contains("login") {
String::from("/") String::from("/")
} else { } else {
current_route.into() current_route
} }
} }
} }

View File

@ -7,7 +7,7 @@ fn get_document() -> Result<HtmlDocument> {
web_sys::window() web_sys::window()
.map(|w| w.document()) .map(|w| w.document())
.flatten() .flatten()
.ok_or(anyhow!("Could not get window document")) .ok_or_else(|| anyhow!("Could not get window document"))
.and_then(|d| { .and_then(|d| {
d.dyn_into::<web_sys::HtmlDocument>() d.dyn_into::<web_sys::HtmlDocument>()
.map_err(|_| anyhow!("Document is not an HTMLDocument")) .map_err(|_| anyhow!("Document is not an HTMLDocument"))
@ -18,7 +18,7 @@ pub fn set_cookie(cookie_name: &str, value: &str, expiration: &DateTime<Utc>) ->
let doc = web_sys::window() let doc = web_sys::window()
.map(|w| w.document()) .map(|w| w.document())
.flatten() .flatten()
.ok_or(anyhow!("Could not get window document")) .ok_or_else(|| anyhow!("Could not get window document"))
.and_then(|d| { .and_then(|d| {
d.dyn_into::<web_sys::HtmlDocument>() d.dyn_into::<web_sys::HtmlDocument>()
.map_err(|_| anyhow!("Document is not an HTMLDocument")) .map_err(|_| anyhow!("Document is not an HTMLDocument"))
@ -35,7 +35,7 @@ pub fn get_cookie(cookie_name: &str) -> Result<Option<String>> {
.cookie() .cookie()
.map_err(|_| anyhow!("Could not access cookies"))?; .map_err(|_| anyhow!("Could not access cookies"))?;
Ok(cookies Ok(cookies
.split(";") .split(';')
.filter_map(|c| c.split_once('=')) .filter_map(|c| c.split_once('='))
.find_map(|(name, value)| { .find_map(|(name, value)| {
if name == cookie_name { if name == cookie_name {
@ -51,7 +51,7 @@ pub fn get_cookie(cookie_name: &str) -> Result<Option<String>> {
} }
pub fn delete_cookie(cookie_name: &str) -> Result<()> { pub fn delete_cookie(cookie_name: &str) -> Result<()> {
if let Some(_) = get_cookie(cookie_name)? { if get_cookie(cookie_name)?.is_some() {
set_cookie(cookie_name, "", &Utc.ymd(1970, 1, 1).and_hms(0, 0, 0)) set_cookie(cookie_name, "", &Utc.ymd(1970, 1, 1).and_hms(0, 0, 0))
} else { } else {
Ok(()) Ok(())

View File

@ -38,7 +38,7 @@ impl Component for LoginForm {
fn create(props: Self::Properties, link: ComponentLink<Self>) -> Self { fn create(props: Self::Properties, link: ComponentLink<Self>) -> Self {
LoginForm { LoginForm {
link: link.clone(), link,
on_logged_in: props.on_logged_in, on_logged_in: props.on_logged_in,
error: None, error: None,
node_ref: NodeRef::default(), node_ref: NodeRef::default(),
@ -63,8 +63,8 @@ impl Component for LoginForm {
.unwrap() .unwrap()
.value(); .value();
let req = BindRequest { let req = BindRequest {
name: username.to_string(), name: username,
password: password.to_string(), password,
}; };
match HostService::authenticate( match HostService::authenticate(
req, req,

View File

@ -26,7 +26,7 @@ impl Component for LogoutButton {
fn create(props: Self::Properties, link: ComponentLink<Self>) -> Self { fn create(props: Self::Properties, link: ComponentLink<Self>) -> Self {
LogoutButton { LogoutButton {
link: link.clone(), link,
on_logged_out: props.on_logged_out, on_logged_out: props.on_logged_out,
_task: None, _task: None,
} }

View File

@ -34,7 +34,7 @@ impl Component for UserTable {
fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self { fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self {
let mut table = UserTable { let mut table = UserTable {
link: link.clone(), link,
_task: None, _task: None,
users: None, users: None,
}; };