aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
}