simplified code across the app and consolidated duplicated helpers
This commit is contained in:
@@ -253,20 +253,8 @@ class _DayColumn extends StatelessWidget {
|
||||
final period = layout.periodAtY(details.localPosition.dy);
|
||||
if (period == null) return;
|
||||
|
||||
final start = DateTime(
|
||||
date.year,
|
||||
date.month,
|
||||
date.day,
|
||||
period.start.hour,
|
||||
period.start.minute,
|
||||
);
|
||||
final end = DateTime(
|
||||
date.year,
|
||||
date.month,
|
||||
date.day,
|
||||
period.end.hour,
|
||||
period.end.minute,
|
||||
);
|
||||
final start = date.withTime(period.start);
|
||||
final end = date.withTime(period.end);
|
||||
if (_overlapsExistingAppointment(start, end, dayAppts)) return;
|
||||
|
||||
Haptics.longPress();
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/// Custom 5-day work-week calendar (replaces Syncfusion's `WorkWeek` view).
|
||||
///
|
||||
/// Implementation is split across `calendar/` for readability; everything
|
||||
/// stays in this single library so private widgets and helpers (`_DayColumn`,
|
||||
/// `_PeriodLayout`, `_isAllDayLike`, …) can remain library-private.
|
||||
/// stays in this single library so private widgets (`_DayColumn`,
|
||||
/// `_WeekGrid`, …) can remain library-private.
|
||||
library;
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
@@ -44,11 +44,7 @@ class SpecialRegionsBuilder {
|
||||
for (var day = rangeStart; !day.isAfter(rangeEnd); day = day.addDays(1)) {
|
||||
if (holidayDays.contains(_dayKey(day))) continue;
|
||||
for (final p in breakPeriods) {
|
||||
final start = day.copyWith(
|
||||
hour: p.start.hour,
|
||||
minute: p.start.minute,
|
||||
);
|
||||
breakRegions.add(_breakRegion(start, p.duration));
|
||||
breakRegions.add(_breakRegion(day.withTime(p.start), p.duration));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,16 +60,8 @@ class SpecialRegionsBuilder {
|
||||
// on top of each other.
|
||||
final byDay = <String, _HolidayDay>{};
|
||||
for (final holiday in holidays.result) {
|
||||
final startDay = DateTime(
|
||||
holiday.startDate.year,
|
||||
holiday.startDate.month,
|
||||
holiday.startDate.day,
|
||||
);
|
||||
final endDay = DateTime(
|
||||
holiday.endDate.year,
|
||||
holiday.endDate.month,
|
||||
holiday.endDate.day,
|
||||
);
|
||||
final startDay = holiday.startDate.dateOnly;
|
||||
final endDay = holiday.endDate.dateOnly;
|
||||
// Webuntis treats endDate inclusively (last day of the break) — the
|
||||
// `+ 1` covers single-day public holidays (where startDate == endDate)
|
||||
// and the final day of a multi-day vacation, both of which would
|
||||
|
||||
@@ -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