Skip to content

Commit

Permalink
Clippy happy (#179)
Browse files Browse the repository at this point in the history
* chore: make clippy happy

* style: fmt
  • Loading branch information
b-avb authored Nov 18, 2024
1 parent d001cde commit c1859df
Show file tree
Hide file tree
Showing 44 changed files with 230 additions and 283 deletions.
10 changes: 6 additions & 4 deletions src/components/atoms/attach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn Attach(props: AttachProps) -> Element {
async move {
let files = &event.files().ok_or(AttachError::NotFound)?;
let fs = files.files();
let existing_file = fs.get(0).ok_or(AttachError::NotFound)?;
let existing_file = fs.first().ok_or(AttachError::NotFound)?;
let content = files
.read_file(existing_file)
.await
Expand All @@ -81,7 +81,7 @@ pub fn Attach(props: AttachProps) -> Element {
}
_ => gloo::file::Blob::new(content.deref()),
};
let size = blob.size().clone();
let size = blob.size();
if size > MAX_FILE_SIZE {
return Err(AttachError::Size);
}
Expand Down Expand Up @@ -184,11 +184,13 @@ pub fn Attach(props: AttachProps) -> Element {
r#type: "file",
class: "attach__input",
onmounted: move |event| {
event
if let Some(html_element) = event
.data
.downcast::<web_sys::Element>()
.and_then(|element| element.clone().dyn_into::<web_sys::HtmlElement>().ok())
.map(|html_element| textarea_ref.set(Some(Box::new(html_element.clone()))));
{
textarea_ref.set(Some(Box::new(html_element.clone())))
}
},
oninput: on_handle_input
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/atoms/avatar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct AvatarProps {
}
pub fn Avatar(props: AvatarProps) -> Element {
let size_avatar = format!("--avatar-size: {}px;", props.size);
let avatar_style = format!("{}", size_avatar);
let avatar_style = size_avatar.to_string();
let variant = match props.variant {
Variant::Round => "avatar--round",
Variant::SemiRound => "avatar--semi-round",
Expand Down
2 changes: 1 addition & 1 deletion src/components/atoms/dropdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct DropdownProps {
pub fn Dropdown(props: DropdownProps) -> Element {
let mut is_active = use_signal::<bool>(|| false);
let disabled = if props.disabled { "button--disabled" } else { "" };
let placeholder = if let None = props.value { "dropdown__placeholder" } else { "" };
let placeholder = if props.value.is_none() { "dropdown__placeholder" } else { "" };
let size = match props.size {
ElementSize::Big => "dropdown__container--big",
ElementSize::Medium => "dropdown__container--medium",
Expand Down
14 changes: 8 additions & 6 deletions src/components/atoms/input.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::dropdown::ElementSize;
use crate::components::atoms::{Icon, IconButton, Search, WarningSign};
use dioxus::prelude::*;
use wasm_bindgen::JsCast;
use web_sys::HtmlInputElement;
use crate::components::atoms::{Icon, IconButton, Search, WarningSign};
use super::dropdown::ElementSize;
#[derive(PartialEq, Clone)]
pub enum InputType {
Text,
Expand Down Expand Up @@ -35,7 +35,7 @@ pub struct InputProps {
}
pub fn Input(props: InputProps) -> Element {
let mut input_ref = use_signal::<Option<Box<HtmlInputElement>>>(|| None);
let input_error_container = if let Some(_) = props.error {
let input_error_container = if props.error.is_some() {
"input--error-container"
} else {
""
Expand Down Expand Up @@ -71,11 +71,13 @@ pub fn Input(props: InputProps) -> Element {
r#type: "{input_type}",
class: "input",
onmounted: move |event| {
event
if let Some(html_element) = event
.data
.downcast::<web_sys::Element>()
.and_then(|element| element.clone().dyn_into::<HtmlInputElement>().ok())
.map(|html_element| input_ref.set(Some(Box::new(html_element.clone()))));
{
input_ref.set(Some(Box::new(html_element.clone())))
}
if input_type == "date" {
if let Some(input_element) = input_ref() {
input_element.set_type("text")
Expand All @@ -98,7 +100,7 @@ pub fn Input(props: InputProps) -> Element {
placeholder: if props.required {
format!("{}*", props.placeholder)
} else {
format!("{}", props.placeholder)
props.placeholder.to_string()
},
oninput: move |event| props.on_input.call(event),
onkeypress: move |event| props.on_keypress.call(event)
Expand Down
30 changes: 13 additions & 17 deletions src/components/atoms/input_tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct InputTagsProps {
on_click: EventHandler<MouseEvent>,
}
pub fn InputTags(props: InputTagsProps) -> Element {
let input_error_container = if let Some(_) = props.error {
let input_error_container = if props.error.is_some() {
"input--error-container"
} else {
""
Expand All @@ -37,19 +37,19 @@ pub fn InputTags(props: InputTagsProps) -> Element {

let is_active = use_signal::<bool>(|| false);
let mut tags = use_signal::<Vec<String>>(|| {
if props.message.len() > 0 {
if !props.message.is_empty() {
props
.message
.split(",")
.map(|e| String::from(e))
.split(',')
.map(String::from)
.collect::<Vec<String>>()
} else {
vec![]
}
});
let mut complete_value = use_signal(|| String::new());
let mut new_value = use_signal(|| String::new());
let mut temporal_value = use_signal(|| String::new());
let mut complete_value = use_signal(String::new);
let mut new_value = use_signal(String::new);
let mut temporal_value = use_signal(String::new);
let mut is_editing_tag = use_signal(|| None);
rsx!(
section {
Expand Down Expand Up @@ -109,7 +109,7 @@ pub fn InputTags(props: InputTagsProps) -> Element {
)
})
},
if new_value().trim().len() > 0 {
if !new_value().trim().is_empty() {
div {
class: "tag",
class: if is_editing_tag().is_some() { "tag--editing" },
Expand All @@ -119,7 +119,7 @@ pub fn InputTags(props: InputTagsProps) -> Element {
new_value.set(temporal_value());
is_editing_tag.set(None);
},
if temporal_value().len() > 0 {
if !temporal_value().is_empty() {
"{temporal_value()}"
} else {
"{new_value()}"
Expand All @@ -141,11 +141,7 @@ pub fn InputTags(props: InputTagsProps) -> Element {
class: "input",
value: new_value,
required: props.required,
placeholder: if props.required {
format!("{}*", props.placeholder)
} else {
format!("{}", props.placeholder)
},
placeholder: if props.required { format!("{}*", props.placeholder) } else { props.placeholder },
oninput: move |event| {
if let Some(index) = is_editing_tag() {
tags.with_mut(|t| t[index] = event.value());
Expand All @@ -171,7 +167,7 @@ pub fn InputTags(props: InputTagsProps) -> Element {
.map(|s| s.to_string())
.collect();
let last_tag = e[1].clone();
if last_tag.len() > 0 {
if !last_tag.is_empty() {
tags.with_mut(|t| t.push(e[0].clone()));
complete_value.set(tags().join(","));
new_value.set(last_tag.clone());
Expand All @@ -181,11 +177,11 @@ pub fn InputTags(props: InputTagsProps) -> Element {
} else {
new_value.set(event.value().clone());
}
if event.value().len() == 0 && tags.last().is_some() {
if event.value().is_empty() && tags.last().is_some() {
new_value.set(tags().last().unwrap().to_string());
tags.with_mut(|t| t.pop());
}
let val = if temporal_value().len() > 0 {
let val = if !temporal_value().is_empty() {
temporal_value()
} else {
new_value()
Expand Down
18 changes: 11 additions & 7 deletions src/components/atoms/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn Markdown(props: MarkdownProps) -> Element {
let i18 = use_i18();
let mut is_editor_loaded = use_signal(|| false);
let content = use_signal(|| {
if props.content.len() > 0 {
if !props.content.is_empty() {
props.content.clone()
} else {
translate!(i18, "utils.markdown.value")
Expand Down Expand Up @@ -97,21 +97,25 @@ pub fn Markdown(props: MarkdownProps) -> Element {
class: if !is_markdown_visible() { "hide" } else { "markdown__wrapper--editor" },
div {
onmounted: move |event| {
event
if let Some(html_element) = event
.data
.downcast::<web_sys::Element>()
.and_then(|element| element.clone().dyn_into::<web_sys::HtmlElement>().ok())
.map(|html_element| toolbar_ref.set(Some(Box::new(html_element.clone()))));
},
{
toolbar_ref.set(Some(Box::new(html_element.clone())))
}
}
}
div {
onmounted: move |event| {
event
if let Some(html_element) = event
.data
.downcast::<web_sys::Element>()
.and_then(|element| element.clone().dyn_into::<web_sys::HtmlElement>().ok())
.map(|html_element| editor_ref.set(Some(Box::new(html_element.clone()))));
},
{
editor_ref.set(Some(Box::new(html_element.clone())))
}
}
}
}
div {
Expand Down
6 changes: 3 additions & 3 deletions src/components/atoms/search_input.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dioxus::prelude::*;
use crate::components::atoms::{Icon, IconButton, Search};
use super::dropdown::ElementSize;
use crate::components::atoms::{Icon, IconButton, Search};
use dioxus::prelude::*;
#[derive(PartialEq, Props, Clone)]
pub struct SearchInputProps {
message: String,
Expand All @@ -15,7 +15,7 @@ pub struct SearchInputProps {
on_click: EventHandler<MouseEvent>,
}
pub fn SearchInput(props: SearchInputProps) -> Element {
let input_error_container = if let Some(_) = props.error {
let input_error_container = if props.error.is_some() {
"input--error-container"
} else {
""
Expand Down
8 changes: 4 additions & 4 deletions src/components/molecules/action_request_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ pub fn ActionRequestList(props: ActionRequestListProps) -> Element {
for request in props.actions.iter() {
div { class: "requests",
match request {
ActionItem::AddMembers(action) => render_add_members(& action),
ActionItem::KusamaTreasury(action) => render_kusama_treasury(& action),
ActionItem::VotingOpenGov(action) => render_voting_open_gov(& action) ,
ActionItem::CommunityTransfer(action) => render_community_transfer(& action) }
ActionItem::AddMembers(action) => render_add_members(action),
ActionItem::KusamaTreasury(action) => render_kusama_treasury(action),
ActionItem::VotingOpenGov(action) => render_voting_open_gov(action) ,
ActionItem::CommunityTransfer(action) => render_community_transfer(action) }
}
}
)
Expand Down
2 changes: 1 addition & 1 deletion src/components/molecules/actions/members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn MembersAction(props: VotingProps) -> Element {
}, value: match member.medium.clone() {
MediumOptions::Wallet => translate!(i18, "onboard.invite.form.wallet.label"),
} };

rsx!(
li {
ComboInput {
Expand Down
4 changes: 2 additions & 2 deletions src/components/molecules/actions/voting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub fn VotingAction(props: VotingProps) -> Element {
RadioButton {
title: translate!(i18, "initiative.steps.actions.voting_open_gov.standard.aye"),
name: "Aye",
checked: vote.aye.clone(),
checked: vote.aye,
on_change: move |_| {
if let ActionItem::VotingOpenGov(ref mut meta) = initiative.get_action(props.index) {
vote_b.aye = true;
Expand All @@ -158,7 +158,7 @@ pub fn VotingAction(props: VotingProps) -> Element {
RadioButton {
title: translate!(i18, "initiative.steps.actions.voting_open_gov.standard.nay"),
name: "Nay",
checked: !vote.aye.clone(),
checked: !vote.aye,
on_change: move |_| {
if let ActionItem::VotingOpenGov(ref mut meta) = initiative.get_action(props.index) {
vote_c.aye = false;
Expand Down
40 changes: 19 additions & 21 deletions src/components/molecules/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ pub fn Header() -> Element {
let mut connect_handled = use_signal(|| false);

let get_account = move || {
let Some(user_session) = session.get() else {
return None;
};
let user_session = session.get()?;
accounts.get_one(user_session.account_id)
};
let get_balance = move || {
Expand Down Expand Up @@ -79,8 +77,8 @@ pub fn Header() -> Element {
let usdt_value = unscaled_value * KSM_PRICE;
let usdt_value = usdt_value.to_string();
let unscaled_value = unscaled_value.to_string();
let usdt_value = usdt_value.split(".").collect::<Vec<&str>>();
let unscaled_value = unscaled_value.split(".").collect::<Vec<&str>>();
let usdt_value = usdt_value.split('.').collect::<Vec<&str>>();
let unscaled_value = unscaled_value.split('.').collect::<Vec<&str>>();

ksm_balance.set((
unscaled_value[0].to_string(),
Expand All @@ -93,17 +91,16 @@ pub fn Header() -> Element {

Ok::<(), String>(())
}
.unwrap_or_else(move |e: String| notification.handle_warning(&translate!(i18, "warnings.title"), &e))
.unwrap_or_else(move |e: String| {
notification.handle_warning(&translate!(i18, "warnings.title"), &e)
})
});
};
let mut dropdown_value = use_signal::<Option<DropdownItem>>(|| {
let account = get_account().and_then(|account| {
Some(DropdownItem {
key: account.address().clone(),
value: account.name(),
})
});
account
get_account().map(|account| DropdownItem {
key: account.address().clone(),
value: account.name(),
})
});
let mut items = vec![];
for account in accounts.get().into_iter() {
Expand All @@ -117,10 +114,13 @@ pub fn Header() -> Element {
let on_handle_account = use_coroutine(move |mut rx: UnboundedReceiver<u8>| async move {
while let Some(event) = rx.next().await {
let account_list = accounts.get();

let Some(account) = account_list.get(event as usize) else {
// return;
return notification.handle_warning(&translate!(i18, "warnings.title"), &translate!(i18, "warnings.middleware.not_account"));
// return;
return notification.handle_warning(
&translate!(i18, "warnings.title"),
&translate!(i18, "warnings.middleware.not_account"),
);
};

let Ok(serialized_session) = serde_json::to_string(&UserSession {
Expand All @@ -142,11 +142,9 @@ pub fn Header() -> Element {
accounts.set_account(Some(account.clone()));
set_signer(account.address().clone());

let account = get_account().and_then(|account| {
Some(DropdownItem {
key: account.address().clone(),
value: account.name(),
})
let account = get_account().map(|account| DropdownItem {
key: account.address().clone(),
value: account.name(),
});

dropdown_value.set(account);
Expand Down
8 changes: 3 additions & 5 deletions src/components/molecules/initiative/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ pub fn InitiativeActions() -> Element {
default: None,
on_change: move |event: usize| {
let options = initiative.get_actions_options();

let to_assign = &options[event];

initiative.update_action(index, initiative.to_action_option(to_assign.key.clone()));
},
body: items.clone()
Expand Down Expand Up @@ -110,10 +110,8 @@ pub fn InitiativeActions() -> Element {
default: None,
on_change: move |event: usize| {
let options = initiative.get_actions_options();

let to_assign = &options[event];
let action = initiative.to_action_option(to_assign.key.clone());

initiative.push_action(action);
},
body: items
Expand All @@ -122,7 +120,7 @@ pub fn InitiativeActions() -> Element {
variant: Variant::Round,
size: ElementSize::Small,
class: "button--action",
disabled: actions_lock.len() == 0,
disabled: actions_lock.is_empty(),
body: rsx! {
Icon { icon: AddPlus, height: 24, width: 24, fill: "var(--fill-00)" }
},
Expand Down
Loading

0 comments on commit c1859df

Please sign in to comment.