Skip to content

Commit

Permalink
chore: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
edfloreshz committed Jul 11, 2024
1 parent db3a32a commit b705459
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 47 deletions.
50 changes: 18 additions & 32 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ pub struct Flags {
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Action {
About,
ItemDown,
ItemUp,
Settings,
WindowClose,
WindowNew,
Expand All @@ -136,8 +134,6 @@ impl MenuAction for Action {
fn message(&self) -> Self::Message {
match self {
Action::About => Message::ToggleContextPage(ContextPage::About),
Action::ItemDown => Message::Content(content::Message::ItemDown),
Action::ItemUp => Message::Content(content::Message::ItemUp),
Action::Settings => Message::ToggleContextPage(ContextPage::Settings),
Action::WindowClose => Message::WindowClose,
Action::WindowNew => Message::WindowNew,
Expand Down Expand Up @@ -190,10 +186,7 @@ impl Tasks {
hash = short_hash.as_str(),
date = date
))
.on_press(Message::LaunchUrl(format!(
"{}/commits/{}",
repository, hash
)))
.on_press(Message::LaunchUrl(format!("{repository}/commits/{hash}")))
.padding(spacing.space_none)
.into(),
])
Expand Down Expand Up @@ -221,7 +214,7 @@ impl Tasks {
.into()
}

fn create_nav_item(&mut self, list: List) -> EntityMut<SingleSelect> {
fn create_nav_item(&mut self, list: &List) -> EntityMut<SingleSelect> {
self.nav_model
.insert()
.text(format!(
Expand Down Expand Up @@ -289,10 +282,7 @@ impl Application for Tasks {
}

fn dialog(&self) -> Option<Element<Message>> {
let dialog_page = match self.dialog_pages.front() {
Some(some) => some,
None => return None,
};
let dialog_page = self.dialog_pages.front()?;

let spacing = theme::active().cosmic().spacing;

Expand Down Expand Up @@ -372,7 +362,7 @@ impl Application for Tasks {
.control(
widget::container(scrollable(widget::row::with_children(vec![
widget::flex_row(icon_buttons).into(),
horizontal_space(Length::Fixed(spacing.space_s as f32)).into(),
horizontal_space(Length::Fixed(f32::from(spacing.space_s))).into(),
])))
.height(Length::Fixed(300.0)),
);
Expand Down Expand Up @@ -604,8 +594,7 @@ impl Application for Tasks {
let command = Command::perform(
todo::update_task(task, self.service.clone().clone()),
|result| match result {
Ok(_) => message::none(),
Err(_) => message::none(),
Ok(()) | Err(_) => message::none(),
},
);
commands.push(command);
Expand All @@ -620,8 +609,7 @@ impl Application for Tasks {
self.service.clone().clone(),
),
|result| match result {
Ok(_) => message::none(),
Err(_) => message::none(),
Ok(()) | Err(_) => message::none(),
},
);
commands.push(command);
Expand All @@ -631,8 +619,7 @@ impl Application for Tasks {
let command = Command::perform(
todo::create_task(task, self.service.clone()),
|result| match result {
Ok(_) => message::none(),
Err(_) => message::none(),
Ok(()) | Err(_) => message::none(),
},
);
commands.push(command);
Expand Down Expand Up @@ -665,17 +652,17 @@ impl Application for Tasks {
Message::NavMenuAction(action) => match action {
NavMenuAction::Rename(entity) => {
if self.nav_model.data::<List>(entity).is_some() {
commands.push(self.update(Message::OpenRenameListDialog))
commands.push(self.update(Message::OpenRenameListDialog));
}
}
NavMenuAction::SetIcon(entity) => {
if self.nav_model.data::<List>(entity).is_some() {
commands.push(self.update(Message::OpenIconDialog))
commands.push(self.update(Message::OpenIconDialog));
}
}
NavMenuAction::Delete(entity) => {
if self.nav_model.data::<List>(entity).is_some() {
commands.push(self.update(Message::OpenDeleteListDialog))
commands.push(self.update(Message::OpenDeleteListDialog));
}
}
},
Expand All @@ -693,13 +680,13 @@ impl Application for Tasks {
}
Message::WindowNew => match env::current_exe() {
Ok(exe) => match process::Command::new(&exe).spawn() {
Ok(_child) => {}
Ok(_) => {}
Err(err) => {
eprintln!("failed to execute {:?}: {}", exe, err);
eprintln!("failed to execute {exe:?}: {err}");
}
},
Err(err) => {
eprintln!("failed to get current executable path: {}", err);
eprintln!("failed to get current executable path: {err}");
}
},
Message::LaunchUrl(url) => match open::that_detached(&url) {
Expand Down Expand Up @@ -731,7 +718,7 @@ impl Application for Tasks {
}
Message::PopulateLists(lists) => {
for list in lists {
self.create_nav_item(list);
self.create_nav_item(&list);
}
let Some(entity) = self.nav_model.iter().next() else {
return Command::none();
Expand All @@ -741,7 +728,7 @@ impl Application for Tasks {
commands.push(command);
}
Message::Key(modifiers, key) => {
for (key_bind, action) in self.key_binds.iter() {
for (key_bind, action) in &self.key_binds {
if key_bind.matches(modifiers, &key) {
return self.update(action.message());
}
Expand All @@ -751,7 +738,7 @@ impl Application for Tasks {
self.modifiers = modifiers;
}
Message::AddList(list) => {
self.create_nav_item(list);
self.create_nav_item(&list);
let Some(entity) = self.nav_model.iter().last() else {
return Command::none();
};
Expand All @@ -763,8 +750,7 @@ impl Application for Tasks {
let command = Command::perform(
todo::delete_list(list.id().clone(), self.service.clone()),
|result| match result {
Ok(_) => message::none(),
Err(_) => message::none(),
Ok(()) | Err(_) => message::none(),
},
);

Expand All @@ -776,7 +762,7 @@ impl Application for Tasks {
}
Message::Export(tasks) => {
if let Some(list) = self.nav_model.data::<List>(self.nav_model.active()) {
let exported_markdown = todo::export_list(list.clone(), tasks);
let exported_markdown = todo::export_list(list, &tasks);
commands.push(self.update(Message::OpenExportDialog(exported_markdown)));
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/app/key_bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ pub fn key_binds() -> HashMap<KeyBind, Action> {
}};
}

bind!([], Key::Named(Named::ArrowDown), ItemDown);
bind!([], Key::Named(Named::ArrowUp), ItemUp);
bind!([Shift], Key::Named(Named::ArrowDown), ItemDown);
bind!([Shift], Key::Named(Named::ArrowUp), ItemUp);
bind!([Ctrl], Key::Character("n".into()), NewList);
bind!([], Key::Named(Named::Delete), DeleteList);
bind!([], Key::Named(Named::Enter), RenameList);
Expand Down
2 changes: 1 addition & 1 deletion src/app/localize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ pub fn set_localization() {
let requested_languages = i18n_embed::DesktopLanguageRequester::requested_languages();

if let Err(error) = localizer.select(&requested_languages) {
eprintln!("Error while loading language for App List {}", error);
eprintln!("Error while loading language for App List {error}");
}
}
2 changes: 1 addition & 1 deletion src/app/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn migrate(prev_app_id: &str) {
let new = dirs::data_local_dir().unwrap().join(Tasks::APP_ID);
if prev.exists() {
match std::fs::rename(prev, new) {
Ok(_) => log::info!("migrated data to new directory"),
Ok(()) => log::info!("migrated data to new directory"),
Err(err) => log::error!("error migrating data: {:?}", err),
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ pub enum Message {
EditMode(DefaultKey, bool),
Export(Vec<Task>),
Input(String),
ItemDown,
ItemUp,
List(Option<List>),
Select(Task),
SetItems(Vec<Task>),
Expand Down Expand Up @@ -193,8 +191,6 @@ impl Content {
commands.push(Command::GetTasks(list.id().clone()));
}
}
Message::ItemDown => {}
Message::ItemUp => {}
Message::TitleUpdate(id, title) => {
if let Some(task) = self.tasks.get_mut(id) {
task.title = title;
Expand Down Expand Up @@ -223,10 +219,10 @@ impl Content {
}
Message::SetItems(tasks) => {
self.tasks.clear();
tasks.into_iter().for_each(|task| {
for task in tasks {
let id = self.tasks.insert(task);
self.task_input_ids.insert(id, widget::Id::unique());
});
}
}
Message::Select(task) => {
commands.push(Command::DisplayTask(task));
Expand Down
6 changes: 3 additions & 3 deletions src/todo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ pub async fn delete_task(
Ok(())
}

pub fn export_list(list: List, tasks: Vec<Task>) -> String {
pub fn export_list(list: &List, tasks: &[Task]) -> String {
let markdown = list.markdown();
let tasks_markdown: String = tasks.iter().map(|task| task.markdown()).collect();
format!("{}\n{}", markdown, tasks_markdown)
let tasks_markdown: String = tasks.iter().map(Markdown::markdown).collect();
format!("{markdown}\n{tasks_markdown}")
}

0 comments on commit b705459

Please sign in to comment.