Skip to content

Commit

Permalink
fix: Click on schedule card redirects to next lecture's day (#1373)
Browse files Browse the repository at this point in the history
  • Loading branch information
DGoiana authored Dec 11, 2024
2 parents 3067393 + d63dcd0 commit 572e556
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions packages/uni_app/lib/view/schedule/schedule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class SchedulePageView extends StatefulWidget {
class SchedulePageViewState extends State<SchedulePageView>
with TickerProviderStateMixin {
TabController? tabController;
late final List<Lecture> lecturesThisWeek;

@override
void initState() {
Expand All @@ -67,7 +68,33 @@ class SchedulePageViewState extends State<SchedulePageView>
length: 6,
);

final weekDay = widget.currentWeek.start.weekday;
var weekDay = widget.currentWeek.start.weekday;

lecturesThisWeek = <Lecture>[];
widget.currentWeek.weekdays.take(6).forEach((day) {
final lectures = lecturesOfDay(widget.lectures, day);
lecturesThisWeek.addAll(lectures);
});

if (lecturesThisWeek.isNotEmpty) {
final now = DateTime.now();

final nextLecture = lecturesThisWeek
.where((lecture) => lecture.endTime.isAfter(now))
.fold<Lecture?>(null, (closest, lecture) {
if (closest == null) {
return lecture;
}
return lecture.endTime.difference(now) < closest.endTime.difference(now)
? lecture
: closest;
});

if (nextLecture != null) {
weekDay = nextLecture.endTime.weekday;
}
}

final offset = (weekDay > 6) ? 0 : (weekDay - 1) % 6;
tabController?.animateTo(tabController!.index + offset);
}
Expand All @@ -93,7 +120,7 @@ class SchedulePageViewState extends State<SchedulePageView>
child: TabBarView(
controller: tabController,
children: widget.currentWeek.weekdays.take(6).map((day) {
final lectures = lecturesOfDay(widget.lectures, day);
final lectures = lecturesOfDay(lecturesThisWeek, day);
final index = WeekdayMapper.fromDartToIndex.map(day.weekday);
if (lectures.isEmpty) {
return emptyDayColumn(context, index);
Expand Down

0 comments on commit 572e556

Please sign in to comment.