Skip to content

Commit

Permalink
Filter at parse lever
Browse files Browse the repository at this point in the history
  • Loading branch information
DGoiana committed Aug 24, 2023
1 parent 0aa828b commit 437f379
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
11 changes: 10 additions & 1 deletion uni/lib/controller/parsers/parser_calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@ Future<List<CalendarEvent>> getCalendarFromHtml(Response response) async {

final calendarHtml = document.querySelectorAll('tr');

return calendarHtml
final eventList = calendarHtml
.map(
(event) => CalendarEvent(
event.children[0].innerHtml,
event.children[1].innerHtml,
),
)
.toList();

final filteredCalendar = eventList
.where(
(event) =>
event.name.trim() != '&nbsp;' && event.date.trim() != '&nbsp;',

Check warning on line 22 in uni/lib/controller/parsers/parser_calendar.dart

View check run for this annotation

Codecov / codecov/patch

uni/lib/controller/parsers/parser_calendar.dart#L20-L22

Added lines #L20 - L22 were not covered by tests
)
.toList();

Check warning on line 24 in uni/lib/controller/parsers/parser_calendar.dart

View check run for this annotation

Codecov / codecov/patch

uni/lib/controller/parsers/parser_calendar.dart#L24

Added line #L24 was not covered by tests

return filteredCalendar;
}
14 changes: 3 additions & 11 deletions uni/lib/view/calendar/calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ class CalendarPageViewState extends GeneralPageViewState<CalendarPageView> {
}

Widget getTimeline(BuildContext context, List<CalendarEvent> calendar) {
// Filter out events where name or date is a non-breaking space
final filteredCalendar = calendar
.where(
(event) =>
event.name.trim() != '&nbsp;' && event.date.trim() != '&nbsp;',
)
.toList();

return FixedTimeline.tileBuilder(
theme: TimelineTheme.of(context).copyWith(
connectorTheme: TimelineTheme.of(context)
Expand All @@ -68,7 +60,7 @@ class CalendarPageViewState extends GeneralPageViewState<CalendarPageView> {
contentsBuilder: (context, index) => Padding(
padding: const EdgeInsets.all(24),
child: Text(
filteredCalendar[index].name,
calendar[index].name,
style: Theme.of(context)
.textTheme
.titleLarge
Expand All @@ -78,13 +70,13 @@ class CalendarPageViewState extends GeneralPageViewState<CalendarPageView> {
oppositeContentsBuilder: (context, index) => Padding(
padding: const EdgeInsets.all(24),
child: Text(
filteredCalendar[index].date,
calendar[index].date,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontStyle: FontStyle.italic,
),
),
),
itemCount: filteredCalendar.length,
itemCount: calendar.length,
),
);
}
Expand Down

0 comments on commit 437f379

Please sign in to comment.