Offline Support
This commit is contained in:
@@ -3,6 +3,7 @@ import 'dart:async';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
import '../brick/cache_helpers.dart';
|
||||
import '../models/app_settings.dart';
|
||||
import '../models/duty_schedule.dart';
|
||||
import '../models/swap_request.dart';
|
||||
@@ -52,6 +53,13 @@ final dutySchedulesProvider = StreamProvider<List<DutySchedule>>((ref) {
|
||||
fromMap: DutySchedule.fromMap,
|
||||
channelName: 'duty_schedules',
|
||||
onStatusChanged: ref.read(realtimeControllerProvider).handleChannelStatus,
|
||||
onOfflineData: () async {
|
||||
final all = await cachedListFromBrick<DutySchedule>();
|
||||
all.sort((a, b) => a.startTime.compareTo(b.startTime));
|
||||
return all;
|
||||
},
|
||||
onCacheMirror: (rows) =>
|
||||
mirrorBatchToBrick<DutySchedule>(rows, tag: 'duty_schedules'),
|
||||
);
|
||||
|
||||
ref.onDispose(wrapper.dispose);
|
||||
@@ -150,6 +158,20 @@ final swapRequestsProvider = StreamProvider<List<SwapRequest>>((ref) {
|
||||
fromMap: SwapRequest.fromMap,
|
||||
channelName: 'swap_requests',
|
||||
onStatusChanged: ref.read(realtimeControllerProvider).handleChannelStatus,
|
||||
onOfflineData: () async {
|
||||
final all = await cachedListFromBrick<SwapRequest>();
|
||||
final filtered = isAdmin
|
||||
? all
|
||||
: all
|
||||
.where(
|
||||
(r) => r.requesterId == profileId || r.recipientId == profileId,
|
||||
)
|
||||
.toList();
|
||||
filtered.sort((a, b) => b.createdAt.compareTo(a.createdAt));
|
||||
return filtered;
|
||||
},
|
||||
onCacheMirror: (rows) =>
|
||||
mirrorBatchToBrick<SwapRequest>(rows, tag: 'swap_requests'),
|
||||
);
|
||||
|
||||
ref.onDispose(wrapper.dispose);
|
||||
|
||||
Reference in New Issue
Block a user