simplified code across the app and consolidated duplicated helpers
This commit is contained in:
@@ -7,6 +7,7 @@ import '../../../../extensions/date_time.dart';
|
||||
import '../../../../state/app/modules/capabilities/bloc/capabilities_cubit.dart';
|
||||
import '../../../../state/app/modules/settings/bloc/settings_cubit.dart';
|
||||
import '../../../../state/app/modules/timetable/bloc/timetable_state.dart';
|
||||
import '../../../../state/app/modules/timetable/bloc/timetable_week_loader.dart';
|
||||
import '../data/arbitrary_appointment.dart';
|
||||
import '../data/lesson_period_schedule.dart';
|
||||
import '../data/timetable_appointment_factory.dart';
|
||||
@@ -63,12 +64,10 @@ class TimetableCalendarViewState extends State<TimetableCalendarView> {
|
||||
List<TimeRegion>? _regions;
|
||||
Object? _regionsKey;
|
||||
|
||||
DateTime _initialDisplayDate() => DateTime.now().addDays(2);
|
||||
|
||||
/// Snaps the calendar back to the current week. Exposed so host pages can
|
||||
/// wire it to a "today" AppBar action.
|
||||
void jumpToToday() {
|
||||
_calendarKey.currentState?.jumpToDate(_initialDisplayDate());
|
||||
_calendarKey.currentState?.jumpToDate(timetableAnchorDate());
|
||||
}
|
||||
|
||||
List<Appointment> _appointments(TimetableState state) {
|
||||
@@ -161,7 +160,7 @@ class TimetableCalendarViewState extends State<TimetableCalendarView> {
|
||||
schedule: schedule,
|
||||
appointments: appointments,
|
||||
timeRegions: regions,
|
||||
initialDate: _initialDisplayDate(),
|
||||
initialDate: timetableAnchorDate(),
|
||||
minDate: minDate,
|
||||
maxDate: maxDate,
|
||||
onAppointmentTap: widget.onAppointmentTap,
|
||||
@@ -197,16 +196,14 @@ class TimetableCalendarViewState extends State<TimetableCalendarView> {
|
||||
baseMin = now.subtractDays(14);
|
||||
baseMax = now.addDays(7);
|
||||
}
|
||||
final effectiveMin = state.accessibleStartDate != null
|
||||
? (state.accessibleStartDate!.isAfter(baseMin)
|
||||
? state.accessibleStartDate!
|
||||
: baseMin)
|
||||
: baseMin;
|
||||
final effectiveMax = state.accessibleEndDate != null
|
||||
? (state.accessibleEndDate!.isBefore(baseMax)
|
||||
? state.accessibleEndDate!
|
||||
: baseMax)
|
||||
: baseMax;
|
||||
final accessibleStart = state.accessibleStartDate;
|
||||
final accessibleEnd = state.accessibleEndDate;
|
||||
final effectiveMin = accessibleStart == null
|
||||
? baseMin
|
||||
: _later(accessibleStart, baseMin);
|
||||
final effectiveMax = accessibleEnd == null
|
||||
? baseMax
|
||||
: _earlier(accessibleEnd, baseMax);
|
||||
final today = DateTime.now().dateOnly;
|
||||
final todayMonday = today.mondayOfWeek;
|
||||
final currentWeekEnd = todayMonday.addDays(DateTime.daysPerWeek - 1);
|
||||
@@ -216,12 +213,12 @@ class TimetableCalendarViewState extends State<TimetableCalendarView> {
|
||||
final capMax = futureDays == null
|
||||
? null
|
||||
: _later(today.addDays(futureDays), currentWeekEnd);
|
||||
final cappedMin = capMin != null && effectiveMin.isBefore(capMin)
|
||||
? capMin
|
||||
: effectiveMin;
|
||||
final cappedMax = capMax != null && effectiveMax.isAfter(capMax)
|
||||
? capMax
|
||||
: effectiveMax;
|
||||
final cappedMin = capMin == null
|
||||
? effectiveMin
|
||||
: _later(effectiveMin, capMin);
|
||||
final cappedMax = capMax == null
|
||||
? effectiveMax
|
||||
: _earlier(effectiveMax, capMax);
|
||||
// When the resulting range does not cover the current week — the summer gap
|
||||
// between two school years, or a stale persisted bound — fall back to the
|
||||
// current week, widened to whatever the capabilities still allow. Otherwise
|
||||
|
||||
Reference in New Issue
Block a user