feat: complete leave approval MVP
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import 'package:aioa_mobile/core/auth/authenticated_http_client.dart';
|
||||
import 'package:aioa_mobile/core/config/runtime_config.dart';
|
||||
import 'package:aioa_mobile/features/tasks/data/notification_repository.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
final notificationRepositoryProvider = Provider<NotificationRepository>(
|
||||
(ref) => NotificationRepository(
|
||||
client: ref.watch(authenticatedHttpClientProvider),
|
||||
baseUrl: RuntimeConfig.apiBaseUrl,
|
||||
),
|
||||
);
|
||||
|
||||
final notificationProvider =
|
||||
AsyncNotifierProvider<NotificationController, List<AppNotification>>(
|
||||
NotificationController.new,
|
||||
);
|
||||
|
||||
class NotificationController extends AsyncNotifier<List<AppNotification>> {
|
||||
@override
|
||||
Future<List<AppNotification>> build() =>
|
||||
ref.read(notificationRepositoryProvider).list();
|
||||
|
||||
Future<void> refresh() async {
|
||||
state = const AsyncLoading();
|
||||
state = await AsyncValue.guard(
|
||||
() => ref.read(notificationRepositoryProvider).list(),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> markRead(String id) async {
|
||||
final current = state.value;
|
||||
if (current == null) return;
|
||||
final updated = await ref.read(notificationRepositoryProvider).markRead(id);
|
||||
state = AsyncData([
|
||||
for (final item in current)
|
||||
if (item.id == id) updated else item,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user