Files
Client/lib/state/app/modules/timetable/bloc/timetable_state.dart
T

50 lines
2.0 KiB
Dart

import 'package:freezed_annotation/freezed_annotation.dart';
import '../../../../../api/mhsl/custom_timetable_event/get/get_custom_timetable_event_response.dart';
import '../../../../../api/webuntis/queries/get_current_schoolyear/get_current_schoolyear_response.dart';
import '../../../../../api/webuntis/queries/get_holidays/get_holidays_response.dart';
import '../../../../../api/webuntis/queries/get_rooms/get_rooms_response.dart';
import '../../../../../api/webuntis/queries/get_subjects/get_subjects_response.dart';
import '../../../../../api/webuntis/queries/get_timegrid_units/get_timegrid_units_response.dart';
import '../../../../../api/webuntis/queries/get_timetable/get_timetable_response.dart';
part 'timetable_state.freezed.dart';
part 'timetable_state.g.dart';
@freezed
abstract class TimetableState with _$TimetableState {
const TimetableState._();
const factory TimetableState({
@Default(<String, GetTimetableResponse>{})
Map<String, GetTimetableResponse> weekCache,
GetRoomsResponse? rooms,
GetSubjectsResponse? subjects,
GetHolidaysResponse? schoolHolidays,
GetCurrentSchoolyearResponse? schoolyear,
GetTimegridUnitsResponse? timegrid,
GetCustomTimetableEventResponse? customEvents,
required DateTime startDate,
required DateTime endDate,
@Default(0) int dataVersion,
// Boundaries learned from `-7004 no allowed date` errors during scroll.
// Inclusive: weeks whose start is on/before `accessibleEndDate` and
// whose end is on/after `accessibleStartDate` are within the user's
// permitted range. Null = no upper / lower bound discovered yet.
DateTime? accessibleStartDate,
DateTime? accessibleEndDate,
}) = _TimetableState;
factory TimetableState.fromJson(Map<String, Object?> json) =>
_$TimetableStateFromJson(json);
Iterable<GetTimetableResponseObject> getAllKnownLessons() =>
weekCache.values.expand((response) => response.result);
bool get hasReferenceData =>
rooms != null &&
subjects != null &&
schoolHolidays != null &&
customEvents != null;
}