Skip to content

Commit

Permalink
Show only events starting in the future.
Browse files Browse the repository at this point in the history
  • Loading branch information
hjtappe committed Dec 3, 2024
1 parent 6317286 commit 55dccad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
16 changes: 12 additions & 4 deletions lib/data/dataProviders/events_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,24 @@ class EventsProvider with ChangeNotifier {

List<EventData> filterPastEvents({
List<EventData>? items,
bool withCurrent = true,
}) {
items ??= _items;
if (items.isEmpty) {
return [];
}
final DateTime now = DateTime.now();
return items.where(
(item) =>
item.end.isAfter(now) ||
item.end.isAtSameMomentAs(now)).toList();
if (withCurrent) {
return items.where(
(item) =>
item.end.isAfter(now) ||
item.end.isAtSameMomentAs(now)).toList();
} else {
return items.where(
(item) =>
item.start.isAfter(now) ||
item.start.isAtSameMomentAs(now)).toList();
}
}

List<EventData> eventsByRoom({
Expand Down
3 changes: 2 additions & 1 deletion lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class HomePageState extends State<HomePage> {
final EventsProvider eventsProvider = Provider.of<EventsProvider>(context);
_nextEventTime = eventsProvider.nextStartTime();
if (_remainingDuration <= Duration.zero) {
_upcomingEvents = eventsProvider.filterPastEvents().take(5).toList();
_upcomingEvents = eventsProvider.filterPastEvents(withCurrent: false).
take(5).toList();
}

return Scaffold(
Expand Down

0 comments on commit 55dccad

Please sign in to comment.