better loading indicators for timetables, talk and files

This commit is contained in:
2026-05-05 21:07:48 +02:00
parent bee5c02a4f
commit db9c3386f1
25 changed files with 439 additions and 203 deletions
+21 -2
View File
@@ -15,6 +15,15 @@ abstract class RequestCache<T extends ApiResponse?> {
int maxCacheTime;
void Function(T)? onUpdate;
/// Called only when [start] finds a cached payload in localstore. Use this
/// (instead of [onUpdate]) when callers need to distinguish stale-but-fast
/// cache hits from authoritative network responses.
void Function(T)? onCacheData;
/// Called only when [start] receives a fresh payload from the network.
void Function(T)? onNetworkData;
void Function(Exception) onError;
bool? renew;
@@ -26,7 +35,14 @@ abstract class RequestCache<T extends ApiResponse?> {
/// attempt have settled.
Future<void> get ready => _ready.future;
RequestCache(this.maxCacheTime, this.onUpdate, {this.onError = ignore, this.renew = false});
RequestCache(
this.maxCacheTime,
this.onUpdate, {
this.onError = ignore,
this.renew = false,
this.onCacheData,
this.onNetworkData,
});
static void ignore(Exception e) {}
@@ -34,7 +50,9 @@ abstract class RequestCache<T extends ApiResponse?> {
try {
final tableData = await Localstore.instance.collection(collection).doc(document).get();
if (tableData != null) {
onUpdate?.call(onLocalData(tableData['json']));
final cached = onLocalData(tableData['json']);
onUpdate?.call(cached);
onCacheData?.call(cached);
}
if (DateTime.now().millisecondsSinceEpoch - (maxCacheTime * 1000) < (tableData?['lastupdate'] ?? 0)) {
@@ -44,6 +62,7 @@ abstract class RequestCache<T extends ApiResponse?> {
try {
final newValue = await onLoad();
onUpdate?.call(newValue);
onNetworkData?.call(newValue);
Localstore.instance.collection(collection).doc(document).set({
'json': jsonEncode(newValue),
'lastupdate': DateTime.now().millisecondsSinceEpoch,