Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Click on schedule card redirects to next lecture's day #1373

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

athoscf
Copy link

@athoscf athoscf commented Oct 29, 2024

Closes #1359

Clicking on home schedule card redirects to next lecture's day instead of current day.
Changes were made to the initState of the schedule so opening the schedule from anywhere starts at the next lecture's day.
If there are no classes in the next week it opens the current day.

Review checklist

  • Terms and conditions reflect the current change
  • Contains enough appropriate tests
  • If aimed at production, writes a new summary in whatsnew/whatsnew-pt-PT
  • Properly adds an entry in changelog.md with the change
  • If PR includes UI updates/additions, its description has screenshots
  • Behavior is as expected
  • Clean, well-structured code

Copy link

codecov bot commented Oct 29, 2024

Codecov Report

Attention: Patch coverage is 75.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 12%. Comparing base (4259069) to head (8a2ca5a).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #1373   +/-   ##
=======================================
+ Coverage       12%     12%   +1%     
=======================================
  Files          266     266           
  Lines         7201    7212   +11     
=======================================
+ Hits           803     811    +8     
- Misses        6398    6401    +3     

@DGoiana DGoiana requested a review from a team November 2, 2024 18:51
Copy link
Member

@limwa limwa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! I think we can use this opportunity to clean up the code a bit!

Comment on lines +73 to +76
widget.currentWeek.weekdays.take(6).forEach((day) {
final lectures = lecturesOfDay(widget.lectures, day);
lecturesThisWeek.addAll(lectures);
});
Copy link
Member

@limwa limwa Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this code is repeated, I'll propose a refactoring to help cleanup the code.

To be continued...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can store the lecturesThisWeek at the state level (by creating a property late final List<Lecture> lecturesThisWeek) and setting it in the initState method.

Then, below, you can simply access that array instead of filtering again.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repeated code actually does slightly different things. The first one is to get the lectures of the week (using forEach) and the other to map the days of the week to the lectures of each day (using map).

I made changes to the build function to look for the lectures of the day on the lecturesThisWeek list instead of going through the full list of lectures of the semester for each day of the week.

Another alternative could be to initially store lecturesThisWeek in a Map and the build code can iterate only once over this map to build the widget list. What do you think?

Comment on lines 78 to 91
if (lecturesThisWeek.isNotEmpty) {
final now = DateTime.now();
Lecture? nextLecture;
Duration? closestDuration;

for (final lecture in lecturesThisWeek) {
if (lecture.endTime.isAfter(now)) {
final difference = lecture.endTime.difference(now);
if (closestDuration == null || difference < closestDuration) {
closestDuration = difference;
nextLecture = lecture;
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be changed for something like final nextLecture = lecturesThisWeek.firstWhere((lecture) => lecture.endTime.isAfter(widget.now));

I am assuming that there are no concurrent lectures and that they are ordered in the list (I think they are)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lecturesThisWeek isn't in chronological order, it always starts on Monday and ends on Saturday even if the next class is on a Tuesday.

I made changes to use where and fold functions instead of this to make the code cleaner.

@athoscf athoscf changed the title fix: Click on schedule card redirects to next lexture's day fix: Click on schedule card redirects to next lecture's day Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Click on schedule card always redirect to current day
2 participants