Skip to content

Commit

Permalink
Fix "edit entry" screen opening with a wrong entry
Browse files Browse the repository at this point in the history
  • Loading branch information
sterliakov committed Oct 18, 2024
1 parent 1959ce2 commit 43e1d6b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
20 changes: 12 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
]
Expand Down
10 changes: 3 additions & 7 deletions src/time_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,14 @@ impl CreateTimeEntry {

#[derive(Clone, Debug)]
pub enum TimeEntryMessage {
Edit(usize),
Edit(u64),
EditRunning,
StopRunning,
Duplicate(Box<TimeEntry>),
}

impl TimeEntry {
pub fn view(
&self,
i: usize,
projects: &[Project],
) -> Element<TimeEntryMessage> {
pub fn view(&self, projects: &[Project]) -> Element<TimeEntryMessage> {
let project = projects.iter().find(|p| Some(p.id) == self.project_id);
let name = self
.description
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 43e1d6b

Please sign in to comment.