diff --git a/src/main.rs b/src/main.rs index aa13168..bf9e7d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -258,12 +258,16 @@ impl App { Screen::Authed => {} Screen::Loaded(temp_state) => match message { Message::TimeEntryProxy(TimeEntryMessage::Edit(i)) => { - self.screen = Screen::EditEntry(EditTimeEntry::new( - self.state.time_entries[i].clone(), - &self.state.api_token, - &self.state.customization, - self.state.projects.clone(), - )); + if let Some(entry) = + self.state.time_entries.iter().find(|e| e.id == i) + { + self.screen = Screen::EditEntry(EditTimeEntry::new( + entry.clone(), + &self.state.api_token, + &self.state.customization, + self.state.projects.clone(), + )); + } } Message::TimeEntryProxy(TimeEntryMessage::EditRunning) => { if let Some(entry) = &self.state.running_entry { @@ -594,9 +598,9 @@ impl App { .width(iced::Length::Fill) .into(), ) - .chain(tasks.enumerate().flat_map(|(i, task)| { + .chain(tasks.flat_map(|task| { vec![ - task.view(i, &self.state.projects) + task.view(&self.state.projects) .map(Message::TimeEntryProxy), horizontal_rule(0.5).into(), ] diff --git a/src/time_entry.rs b/src/time_entry.rs index 8a07613..ab8710b 100644 --- a/src/time_entry.rs +++ b/src/time_entry.rs @@ -198,18 +198,14 @@ impl CreateTimeEntry { #[derive(Clone, Debug)] pub enum TimeEntryMessage { - Edit(usize), + Edit(u64), EditRunning, StopRunning, Duplicate(Box), } impl TimeEntry { - pub fn view( - &self, - i: usize, - projects: &[Project], - ) -> Element { + pub fn view(&self, projects: &[Project]) -> Element { let project = projects.iter().find(|p| Some(p.id) == self.project_id); let name = self .description @@ -251,7 +247,7 @@ impl TimeEntry { }) .align_y(Vertical::Center), ) - .on_press(TimeEntryMessage::Edit(i)) + .on_press(TimeEntryMessage::Edit(self.id)) .clip(true) .style(button::text) .into()