Enhanced material design 3 implementation
This commit is contained in:
@@ -28,15 +28,22 @@ final attendanceUserFilterProvider = StateProvider<List<String>>((ref) => []);
|
||||
/// All visible attendance logs (own for standard, all for admin/dispatcher/it_staff).
|
||||
final attendanceLogsProvider = StreamProvider<List<AttendanceLog>>((ref) {
|
||||
final client = ref.watch(supabaseClientProvider);
|
||||
final profileAsync = ref.watch(currentProfileProvider);
|
||||
final profile = profileAsync.valueOrNull;
|
||||
if (profile == null) return Stream.value(const <AttendanceLog>[]);
|
||||
|
||||
// Use .select() so the stream is only recreated when the user id or role
|
||||
// actually changes (not on avatar/name edits, etc.).
|
||||
final profileId = ref.watch(
|
||||
currentProfileProvider.select((p) => p.valueOrNull?.id),
|
||||
);
|
||||
final profileRole = ref.watch(
|
||||
currentProfileProvider.select((p) => p.valueOrNull?.role),
|
||||
);
|
||||
if (profileId == null) return Stream.value(const <AttendanceLog>[]);
|
||||
|
||||
final hasFullAccess =
|
||||
profile.role == 'admin' ||
|
||||
profile.role == 'programmer' ||
|
||||
profile.role == 'dispatcher' ||
|
||||
profile.role == 'it_staff';
|
||||
profileRole == 'admin' ||
|
||||
profileRole == 'programmer' ||
|
||||
profileRole == 'dispatcher' ||
|
||||
profileRole == 'it_staff';
|
||||
|
||||
final wrapper = StreamRecoveryWrapper<AttendanceLog>(
|
||||
stream: hasFullAccess
|
||||
@@ -47,14 +54,14 @@ final attendanceLogsProvider = StreamProvider<List<AttendanceLog>>((ref) {
|
||||
: client
|
||||
.from('attendance_logs')
|
||||
.stream(primaryKey: ['id'])
|
||||
.eq('user_id', profile.id)
|
||||
.eq('user_id', profileId)
|
||||
.order('check_in_at', ascending: false),
|
||||
onPollData: () async {
|
||||
final query = client.from('attendance_logs').select();
|
||||
final data = hasFullAccess
|
||||
? await query.order('check_in_at', ascending: false)
|
||||
: await query
|
||||
.eq('user_id', profile.id)
|
||||
.eq('user_id', profileId)
|
||||
.order('check_in_at', ascending: false);
|
||||
return data.map(AttendanceLog.fromMap).toList();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user