mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
Add mark as read action to notifications list
Users can now mark a notification as read via a popup menu on each list item or by swiping left. Both actions call the backend API, remove the item from the list, and show a snackbar confirmation. Swiping an already read notification shows an error snackbar and bounces the item back. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
09b67c2707
commit
913bf0e839
@@ -32,6 +32,34 @@ class _NotificationListState extends State<NotificationList> {
|
||||
},
|
||||
);
|
||||
|
||||
Future<bool> _markAsRead(
|
||||
BuildContext context,
|
||||
oott_model.Notification item,
|
||||
) async {
|
||||
if (!item.isNew) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Notification was already marked as read'),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
showCloseIcon: true,
|
||||
),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
await BackendAPI.instance.markNotificationAsRead(item.id);
|
||||
_pagingController.value = _pagingController.value.filterItems(
|
||||
(n) => n.id != item.id,
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Event marked as read'),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
showCloseIcon: true,
|
||||
),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -87,19 +115,8 @@ class _NotificationListState extends State<NotificationList> {
|
||||
children: [
|
||||
Dismissible(
|
||||
key: UniqueKey(),
|
||||
onDismissed: (direction) {
|
||||
setState(() {
|
||||
// _events!.removeAt(index);
|
||||
});
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Event marked as read'),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
showCloseIcon: true,
|
||||
),
|
||||
);
|
||||
},
|
||||
confirmDismiss: (direction) =>
|
||||
_markAsRead(context, item),
|
||||
background: Container(
|
||||
color: Theme.of(
|
||||
context,
|
||||
@@ -114,7 +131,21 @@ class _NotificationListState extends State<NotificationList> {
|
||||
'${FriendlyDateFormatter().format(item.createdOn)} - ${item.title}',
|
||||
),
|
||||
subtitle: Text(item.body, maxLines: 5),
|
||||
trailing: Icon(Icons.more_vert),
|
||||
trailing: PopupMenuButton<String>(
|
||||
icon: const Icon(Icons.more_vert),
|
||||
onSelected: (value) async {
|
||||
if (value == 'mark_read') {
|
||||
await _markAsRead(context, item);
|
||||
}
|
||||
},
|
||||
itemBuilder: (context) => [
|
||||
if (item.isNew)
|
||||
const PopupMenuItem(
|
||||
value: 'mark_read',
|
||||
child: Text('Mark as read'),
|
||||
),
|
||||
],
|
||||
),
|
||||
onTap: () {},
|
||||
isThreeLine: true,
|
||||
),
|
||||
|
||||
@@ -66,6 +66,11 @@ class BackendAPI {
|
||||
late String _apiKey;
|
||||
late Dio _dio;
|
||||
|
||||
Future<void> markNotificationAsRead(int id) async {
|
||||
print('About to call /notifications/$id');
|
||||
await _dio.get('/notifications/$id');
|
||||
}
|
||||
|
||||
Future<List<Notification>> listNotifications(bool? isNew, int offset) async {
|
||||
print('About to call /notifications');
|
||||
|
||||
|
||||
@@ -244,10 +244,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: matcher
|
||||
sha256: "12956d0ad8390bbcc63ca2e1469c0619946ccb52809807067a7020d57e647aa6"
|
||||
sha256: dc0b7dc7651697ea4ff3e69ef44b0407ea32c487a39fff6a4004fa585e901861
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.12.18"
|
||||
version: "0.12.19"
|
||||
material_color_utilities:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -457,10 +457,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test_api
|
||||
sha256: "93167629bfc610f71560ab9312acdda4959de4df6fac7492c89ff0d3886f6636"
|
||||
sha256: "8161c84903fd860b26bfdefb7963b3f0b68fee7adea0f59ef805ecca346f0c7a"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.7.9"
|
||||
version: "0.7.10"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
Reference in New Issue
Block a user