diff --git a/frontend/lib/notifications/notification_list.dart b/frontend/lib/notifications/notification_list.dart index 1ee561f..a1c1ad3 100644 --- a/frontend/lib/notifications/notification_list.dart +++ b/frontend/lib/notifications/notification_list.dart @@ -32,6 +32,20 @@ class _NotificationListState extends State { }, ); + Future _markAllAsRead(BuildContext context) async { + await BackendAPI.instance.markAllNotificationsAsRead(); + _pagingController.refresh(); + if (context.mounted) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('All notifications marked as read'), + behavior: SnackBarBehavior.floating, + showCloseIcon: true, + ), + ); + } + } + Future _markAsRead( BuildContext context, oott_model.Notification item, @@ -102,50 +116,59 @@ class _NotificationListState extends State { @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar(title: const Text('Notifications')), - body: - // Paginated list start - PagingListener( - controller: _pagingController, - builder: (context, state, fetchNextPage) => CustomScrollView( - slivers: [ - // Filters go here - SliverToBoxAdapter( - child: Container( - height: 50, - alignment: Alignment.centerRight, - child: Wrap( - spacing: 8.0, - children: [ - ChoiceChip( - label: Text('New'), - selected: _filterChoice == 1, - onSelected: (bool selected) { - _filterChoice = 1; - _pagingController.refresh(); - }, - ), - ChoiceChip( - label: Text('Old'), - selected: _filterChoice == 2, - onSelected: (bool selected) { - _filterChoice = 2; - _pagingController.refresh(); - }, - ), - ChoiceChip( - label: Text('All'), - selected: _filterChoice == 3, - onSelected: (bool selected) { - _filterChoice = 3; - _pagingController.refresh(); - }, - ), - ], + // Paginated list start + return PagingListener( + controller: _pagingController, + builder: (context, state, fetchNextPage) => Scaffold( + appBar: AppBar( + title: const Text('Notifications'), + actions: [ + if (_filterChoice == 1 && (state.items?.isNotEmpty ?? false)) + IconButton( + onPressed: () => _markAllAsRead(context), + icon: const Icon(Icons.done_all), + tooltip: 'Mark all as read', + ), + ], + ), + body: CustomScrollView( + slivers: [ + // Filters go here + SliverToBoxAdapter( + child: Container( + height: 50, + alignment: Alignment.centerRight, + child: Wrap( + spacing: 8.0, + children: [ + ChoiceChip( + label: Text('New'), + selected: _filterChoice == 1, + onSelected: (bool selected) { + _filterChoice = 1; + _pagingController.refresh(); + }, ), - ), + ChoiceChip( + label: Text('Old'), + selected: _filterChoice == 2, + onSelected: (bool selected) { + _filterChoice = 2; + _pagingController.refresh(); + }, + ), + ChoiceChip( + label: Text('All'), + selected: _filterChoice == 3, + onSelected: (bool selected) { + _filterChoice = 3; + _pagingController.refresh(); + }, + ), + ], ), + ), + ), PagedSliverList( state: state, fetchNextPage: fetchNextPage, @@ -231,7 +254,7 @@ class _NotificationListState extends State { ], ), ), - ); + ); // Paginated list end } diff --git a/frontend/lib/utils/oott_api.dart b/frontend/lib/utils/oott_api.dart index 0447166..cf9a830 100644 --- a/frontend/lib/utils/oott_api.dart +++ b/frontend/lib/utils/oott_api.dart @@ -76,6 +76,11 @@ class BackendAPI { await _dio.post('/notifications/$id/mark_as_new'); } + Future markAllNotificationsAsRead() async { + print('About to call /notifications/mark_all_as_old'); + await _dio.post('/notifications/mark_all_as_old'); + } + Future> listNotifications(bool? isNew, int offset) async { print('About to call /notifications');