From 48f789ca8386d69ae35f4776866fa68dd66bc083 Mon Sep 17 00:00:00 2001 From: Julian Mutter Date: Sun, 26 May 2024 12:12:33 +0200 Subject: [PATCH] Clean up code --- src/sheet.rs | 6 ++---- src/ui/app.rs | 4 ++-- src/ui/sheet_edit_dialog.rs | 13 ++++++------- src/ui/sheet_listing.rs | 8 ++++---- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/sheet.rs b/src/sheet.rs index 1dade35..c0aeda9 100644 --- a/src/sheet.rs +++ b/src/sheet.rs @@ -4,7 +4,7 @@ use std::{ path::{Path, PathBuf}, }; -use chrono::{DateTime, NaiveDateTime, Utc}; +use chrono::{DateTime, Utc}; use strum_macros::{EnumDiscriminants, EnumIter}; pub trait PdfSheet { @@ -87,9 +87,7 @@ impl TryFrom for I64DateTime { fn try_from(value: i64) -> Result { Ok(I64DateTime( - NaiveDateTime::from_timestamp_opt(value, 0) - .ok_or("Failed converting i64 to DateTime")? - .and_utc(), + DateTime::::from_timestamp(value, 0).ok_or("Failed converting i64 to DateTime")?, )) } } diff --git a/src/ui/app.rs b/src/ui/app.rs index 437fc30..22d9e6d 100644 --- a/src/ui/app.rs +++ b/src/ui/app.rs @@ -19,7 +19,7 @@ use crate::{ use super::{ mcdu::McduModel, - sheet_edit_dialog::{SheetEditDialogInit, SheetEditDialogInput, SheetEditDialogModel}, + sheet_edit_dialog::{SheetEditDialogInit, SheetEditDialogModel}, sheet_listing::{SheetListingInput, SheetListingModel, SheetListingOutput}, }; @@ -163,7 +163,7 @@ impl AsyncComponent for AppModel { if self.edit_mode { self.sheet_edit_dialog = Some( SheetEditDialogModel::builder() - .transient_for(&root) + .transient_for(root) .launch(SheetEditDialogInit { sheet, database: Arc::clone(&self.database), diff --git a/src/ui/sheet_edit_dialog.rs b/src/ui/sheet_edit_dialog.rs index 4038a90..17ef9a5 100644 --- a/src/ui/sheet_edit_dialog.rs +++ b/src/ui/sheet_edit_dialog.rs @@ -1,7 +1,6 @@ -use std::{borrow::BorrowMut, sync::Arc}; - use gtk::prelude::*; -use log::debug; +use std::sync::Arc; + use relm4::{ component::{AsyncComponent, AsyncComponentParts, Connector}, prelude::*, @@ -137,7 +136,7 @@ impl AsyncComponent for SheetEditDialogModel { crate::sheet::SheetKind::Book { name, composer_id, - sheet_ids, + sheet_ids: _, } => { is_book = true; sheet_name = name.to_string(); @@ -178,12 +177,12 @@ impl AsyncComponent for SheetEditDialogModel { async fn update( &mut self, msg: Self::Input, - sender: AsyncComponentSender, - root: &Self::Root, + _sender: AsyncComponentSender, + _root: &Self::Root, ) { match msg { SheetEditDialogInput::Accept => { - if let Some(sheet) = &self.sheet { + if let Some(_sheet) = &self.sheet { if self.sheet_name.is_empty() || self.sheet_composer.is_empty() { self.alert_empty_fields.emit(AlertMsg::Show); return; diff --git a/src/ui/sheet_listing.rs b/src/ui/sheet_listing.rs index 595dcd9..ce6e48a 100644 --- a/src/ui/sheet_listing.rs +++ b/src/ui/sheet_listing.rs @@ -1,6 +1,6 @@ use gtk::prelude::*; -use relm4::factory::{FactoryVecDeque, Position}; +use relm4::factory::FactoryVecDeque; use relm4::RelmListBoxExt; use relm4::{gtk, ComponentParts, ComponentSender, SimpleComponent}; @@ -85,18 +85,18 @@ impl SimpleComponent for SheetListingModel { } SheetListingInput::Sort => { sort_sheets(&mut self.sheets); - sender.output(SheetListingOutput::ContentsChanged); + sender.output(SheetListingOutput::ContentsChanged).unwrap(); } SheetListingInput::Shuffle => { shuffle_sheets(&mut self.sheets); - sender.output(SheetListingOutput::ContentsChanged); + sender.output(SheetListingOutput::ContentsChanged).unwrap(); } SheetListingInput::ReloadSheets(sheets) => { self.sheets.guard().clear(); for sheet_model_type in sheets { self.sheets.guard().push_back(sheet_model_type); } - sender.output(SheetListingOutput::ContentsChanged); + sender.output(SheetListingOutput::ContentsChanged).unwrap(); } SheetListingInput::None => {} }