feat: select school terms and smooth refractive Dock motion
This commit is contained in:
@@ -9,6 +9,7 @@ import '../services/calendar_service.dart';
|
||||
import '../domain/schedule_engine.dart';
|
||||
import '../data/demo_schedule.dart';
|
||||
import '../domain/exam_schedule.dart';
|
||||
import '../domain/school_term.dart';
|
||||
|
||||
class AppController extends ChangeNotifier {
|
||||
AppController(this.store, this.notifications, this.calendar, this.clock);
|
||||
@@ -145,6 +146,11 @@ class AppController extends ChangeNotifier {
|
||||
await _save(
|
||||
snapshot.copyWith(
|
||||
courses: draft.courses,
|
||||
schoolTerm: draft.schoolTerm,
|
||||
clearExams: _differentTerm(draft.schoolTerm),
|
||||
settings: _differentTerm(draft.schoolTerm)
|
||||
? snapshot.settings.copyWith(clearSemester: true)
|
||||
: snapshot.settings,
|
||||
importMetadata: ImportMetadata(
|
||||
source: draft.source,
|
||||
importedAt: clock(),
|
||||
@@ -177,8 +183,29 @@ class AppController extends ChangeNotifier {
|
||||
});
|
||||
Future<void> applyExams(ExamSchedule value) => _run(() async {
|
||||
final validated = ExamSchedule.fromJson(value.toJson());
|
||||
await _save(snapshot.copyWith(examSchedule: validated));
|
||||
final term = SchoolTerm(int.parse(validated.termId));
|
||||
final changed = _differentTerm(term);
|
||||
await _save(
|
||||
snapshot.copyWith(
|
||||
examSchedule: validated,
|
||||
schoolTerm: term,
|
||||
courses: changed ? [] : null,
|
||||
clearMetadata: changed,
|
||||
settings: changed
|
||||
? snapshot.settings.copyWith(clearSemester: true)
|
||||
: null,
|
||||
),
|
||||
);
|
||||
if (changed) {
|
||||
isDemo = false;
|
||||
await _reconcile();
|
||||
}
|
||||
});
|
||||
bool _differentTerm(SchoolTerm? next) =>
|
||||
next != null &&
|
||||
((snapshot.schoolTerm != null && snapshot.schoolTerm != next) ||
|
||||
(snapshot.schoolTerm == null &&
|
||||
(snapshot.courses.isNotEmpty || snapshot.examSchedule != null)));
|
||||
Future<void> clearExams() => _run(() async {
|
||||
await _save(snapshot.copyWith(clearExams: true));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user