aboutsummaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorJoris2022-12-18 20:02:42 +0100
committerJoris2022-12-18 20:02:42 +0100
commit80fdf874ac74efea64c7a21937ee790a4d871163 (patch)
tree8a1fc9b0b360dcdeafc03c88ecee711c532a7178 /src/gui
parenta6fd0110b65ec352603d69b9c4ccf3532689cd32 (diff)
Fix changing week
After changing 1 week, we could not move anymore afterward. I didn’t find the source of the bug, but after removing one row from the grid, we lost the key event handler, albeit the application still working fine otherwise.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/update.rs30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/gui/update.rs b/src/gui/update.rs
index 7b3625c..a4b36f3 100644
--- a/src/gui/update.rs
+++ b/src/gui/update.rs
@@ -1,6 +1,5 @@
use async_channel::{Receiver, Sender};
use chrono::{Duration, NaiveDate};
-use gtk4::prelude::GridExt;
use std::collections::HashSet;
use std::iter::FromIterator;
use uuid::Uuid;
@@ -166,8 +165,6 @@ pub async fn event_handler(rx: Receiver<Msg>, mut app: App) {
refresh(&app, &HashSet::from([date]))
}
Msg::SelectPreviousWeek => {
- app.calendar.remove_row(4);
- app.calendar.insert_row(1);
app.start_date -= Duration::days(7);
app.end_date -= Duration::days(7);
@@ -179,11 +176,9 @@ pub async fn event_handler(rx: Receiver<Msg>, mut app: App) {
Ok(events) => app.events = events,
Err(err) => eprintln!("{}", err),
};
- refresh(&app, &HashSet::from_iter(week_from(app.start_date)));
+ refresh(&app, &HashSet::from_iter(visible_dates(&app)));
}
Msg::SelectNextWeek => {
- app.calendar.remove_row(1);
- app.calendar.insert_row(4);
app.start_date += Duration::days(7);
app.end_date += Duration::days(7);
@@ -195,10 +190,7 @@ pub async fn event_handler(rx: Receiver<Msg>, mut app: App) {
Ok(events) => app.events = events,
Err(err) => eprintln!("{}", err),
};
- refresh(
- &app,
- &HashSet::from_iter(week_from(app.end_date - Duration::days(6))),
- );
+ refresh(&app, &HashSet::from_iter(visible_dates(&app)));
}
}
}
@@ -283,16 +275,24 @@ fn refresh(app: &App, dates: &HashSet<NaiveDate>) {
for date in dates {
if date >= &app.start_date && date <= &app.end_date {
- calendar::refresh_date(app, *date, &repetitions, &app.categories, &app.default_color)
+ calendar::refresh_date(
+ app,
+ *date,
+ &repetitions,
+ &app.categories,
+ &app.default_color,
+ )
}
}
}
-/// Seven days vector from the given date.
-fn week_from(date: NaiveDate) -> Vec<NaiveDate> {
+/// List visible dates in calendar.
+fn visible_dates(app: &App) -> Vec<NaiveDate> {
+ let mut date = app.start_date;
let mut res = vec![date];
- for i in 1..=6 {
- res.push(date + Duration::days(i))
+ while date <= app.end_date {
+ date += Duration::days(1);
+ res.push(date);
}
res
}