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 {
let mut app = Self {
link: link.clone(),
link,
user_name: get_cookie("user_id").unwrap_or_else(|e| {
ConsoleService::error(&e.to_string());
None
@ -89,7 +89,7 @@ impl Component for App {
render = Router::render(move |switch: AppRoute| {
match switch {
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! {
<div>
@ -112,7 +112,7 @@ impl App {
if current_route.is_empty() || current_route.contains("login") {
String::from("/")
} else {
current_route.into()
current_route
}
}
}

View File

@ -7,7 +7,7 @@ fn get_document() -> Result<HtmlDocument> {
web_sys::window()
.map(|w| w.document())
.flatten()
.ok_or(anyhow!("Could not get window document"))
.ok_or_else(|| anyhow!("Could not get window document"))
.and_then(|d| {
d.dyn_into::<web_sys::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()
.map(|w| w.document())
.flatten()
.ok_or(anyhow!("Could not get window document"))
.ok_or_else(|| anyhow!("Could not get window document"))
.and_then(|d| {
d.dyn_into::<web_sys::HtmlDocument>()
.map_err(|_| anyhow!("Document is not an HTMLDocument"))
@ -35,7 +35,7 @@ pub fn get_cookie(cookie_name: &str) -> Result<Option<String>> {
.cookie()
.map_err(|_| anyhow!("Could not access cookies"))?;
Ok(cookies
.split(";")
.split(';')
.filter_map(|c| c.split_once('='))
.find_map(|(name, value)| {
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<()> {
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))
} else {
Ok(())

View File

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

View File

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

View File

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