add notification for lesson updates
This commit is contained in:
@@ -25,6 +25,7 @@ class Lesson {
|
||||
String name;
|
||||
bool online;
|
||||
bool isEmpty;
|
||||
bool isSeen;
|
||||
|
||||
Lesson({
|
||||
this.status,
|
||||
@@ -49,7 +50,15 @@ class Lesson {
|
||||
this.online = false,
|
||||
this.isEmpty = false,
|
||||
this.json,
|
||||
this.isSeen = false,
|
||||
});
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is Lesson && runtimeType == other.runtimeType && id == other.id;
|
||||
|
||||
@override
|
||||
int get hashCode => id.hashCode;
|
||||
|
||||
factory Lesson.fromJson(Map json) {
|
||||
return Lesson(
|
||||
@@ -90,6 +99,7 @@ class Lesson {
|
||||
online: json["IsDigitalisOra"] ?? false,
|
||||
isEmpty: json['isEmpty'] ?? false,
|
||||
json: json,
|
||||
isSeen: false
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import 'package:filcnaplo_kreta_api/models/week.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class TimetableProvider with ChangeNotifier {
|
||||
Map<Week, List<Lesson>> _lessons = {};
|
||||
Map<Week, List<Lesson>> lessons = {};
|
||||
late final UserProvider _user;
|
||||
late final DatabaseProvider _database;
|
||||
late final KretaClient _kreta;
|
||||
@@ -29,7 +29,7 @@ class TimetableProvider with ChangeNotifier {
|
||||
// Load lessons from the database
|
||||
if (userId != null) {
|
||||
var dbLessons = await _database.userQuery.getLessons(userId: userId);
|
||||
_lessons = dbLessons;
|
||||
lessons = dbLessons;
|
||||
await convertBySettings();
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ class TimetableProvider with ChangeNotifier {
|
||||
? await _database.userQuery.renamedTeachers(userId: _user.id!)
|
||||
: {};
|
||||
|
||||
for (Lesson lesson in _lessons.values.expand((e) => e)) {
|
||||
for (Lesson lesson in lessons.values.expand((e) => e)) {
|
||||
lesson.subject.renamedTo = renamedSubjects.isNotEmpty
|
||||
? renamedSubjects[lesson.subject.id]
|
||||
: null;
|
||||
@@ -57,7 +57,7 @@ class TimetableProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
List<Lesson>? getWeek(Week week) => _lessons[week];
|
||||
List<Lesson>? getWeek(Week week) => lessons[week];
|
||||
|
||||
// Fetches Lessons from the Kreta API then stores them in the database
|
||||
Future<void> fetch({Week? week}) async {
|
||||
@@ -68,11 +68,11 @@ class TimetableProvider with ChangeNotifier {
|
||||
List? lessonsJson = await _kreta
|
||||
.getAPI(KretaAPI.timetable(iss, start: week.start, end: week.end));
|
||||
if (lessonsJson == null) throw "Cannot fetch Lessons for User ${user.id}";
|
||||
List<Lesson> lessons = lessonsJson.map((e) => Lesson.fromJson(e)).toList();
|
||||
List<Lesson> lessonsList = lessonsJson.map((e) => Lesson.fromJson(e)).toList();
|
||||
|
||||
if (lessons.isEmpty && _lessons.isEmpty) return;
|
||||
if (lessons.isEmpty && lessons.isEmpty) return;
|
||||
|
||||
_lessons[week] = lessons;
|
||||
lessons[week] = lessonsList;
|
||||
|
||||
await store();
|
||||
await convertBySettings();
|
||||
@@ -85,7 +85,7 @@ class TimetableProvider with ChangeNotifier {
|
||||
String userId = user.id;
|
||||
|
||||
// -TODO: clear indexes with weeks outside of the current school year
|
||||
await _database.userStore.storeLessons(_lessons, userId: userId);
|
||||
await _database.userStore.storeLessons(lessons, userId: userId);
|
||||
}
|
||||
|
||||
// Future<void> setLessonCount(SubjectLessonCount lessonCount, {bool store = true}) async {
|
||||
|
||||
Reference in New Issue
Block a user