Added markAll as read for notification
This commit is contained in:
@@ -18,7 +18,8 @@ class NotificationsRepository {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Result<NotificationResponseModel>> markAllAsRead() async {
|
Future<Result<Map<String, dynamic>>> markAllAsRead() async {
|
||||||
return _notificationsService.markAllAsRead();
|
return _notificationsService.markAllAsRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ class NotificationApi {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static const String markAllAsRead = '/api/v1/notifications';
|
static const String markAllAsRead = '/api/v1/notifications/mark';
|
||||||
static const String markAsRead = '/api/v1/notifications/mark-as-read';
|
static const String markAsRead = '/api/v1/notifications/mark-as-read';
|
||||||
static const String tenderApprovalsTender = '/api/v1/notifications';
|
static const String tenderApprovalsTender = '/api/v1/notifications';
|
||||||
static String getTenderApprovalById({required String tenderId}) {
|
static String getTenderApprovalById({required String tenderId}) {
|
||||||
|
|||||||
@@ -24,15 +24,16 @@ class NotificationsService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Result<NotificationResponseModel>> markAllAsRead() async {
|
Future<Result<Map<String, dynamic>>> markAllAsRead() async {
|
||||||
final result = await _networkManager.makeRequest(
|
final result = await _networkManager.makeRequest(
|
||||||
NotificationApi.markAllAsRead,
|
NotificationApi.markAllAsRead,
|
||||||
method: 'POST',
|
method: 'GET',
|
||||||
(json) => NotificationResponseModel.fromJson(json),
|
(json) => json,
|
||||||
);
|
);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Future<Result<NotificationResponseModel>> markAsRead({
|
Future<Result<NotificationResponseModel>> markAsRead({
|
||||||
required String notificationId,
|
required String notificationId,
|
||||||
}) async {
|
}) async {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:tm_app/core/utils/app_toast.dart';
|
||||||
import 'package:tm_app/core/utils/result.dart';
|
import 'package:tm_app/core/utils/result.dart';
|
||||||
import 'package:tm_app/data/repositories/notification_repository.dart';
|
import 'package:tm_app/data/repositories/notification_repository.dart';
|
||||||
import 'package:tm_app/data/services/model/notification__response/notification_response_model.dart';
|
import 'package:tm_app/data/services/model/notification__response/notification_response_model.dart';
|
||||||
@@ -82,14 +83,20 @@ Future<void> getNotifications({int page = 1, bool isMobile = false}) async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Mark all as read
|
/// Mark all as read
|
||||||
Future<void> markAllAsRead() async {
|
Future<void> markAllAsRead(BuildContext context) async {
|
||||||
|
_isLoading = true;
|
||||||
_errorMessage = null;
|
_errorMessage = null;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
||||||
final result = await _repository.markAllAsRead();
|
final result = await _repository.markAllAsRead();
|
||||||
|
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case Ok<NotificationResponseModel>():
|
case Ok<Map<String, dynamic>>():
|
||||||
|
final response = result.value;
|
||||||
|
final success = response['success'] as bool? ?? false;
|
||||||
|
final message = response['message'] as String? ?? 'Unknown response';
|
||||||
|
|
||||||
|
if (success) {
|
||||||
if (_notificationResponseModel?.data?.notifications != null) {
|
if (_notificationResponseModel?.data?.notifications != null) {
|
||||||
final updatedNotifications =
|
final updatedNotifications =
|
||||||
_notificationResponseModel!.data!.notifications!
|
_notificationResponseModel!.data!.notifications!
|
||||||
@@ -102,13 +109,24 @@ Future<void> getNotifications({int page = 1, bool isMobile = false}) async {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await getNotifications(page: 1);
|
||||||
|
|
||||||
|
// toast success
|
||||||
|
AppToast.success(context, 'All notifications marked as read.');
|
||||||
|
} else {
|
||||||
|
_errorMessage = message;
|
||||||
|
AppToast.error(context, message);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Error<NotificationResponseModel>():
|
case Error<Map<String, dynamic>>():
|
||||||
_errorMessage = result.error.toString();
|
_errorMessage = result.error.toString();
|
||||||
|
AppToast.error(context, _errorMessage!);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_isLoading = false;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,12 +4,13 @@ import 'package:tm_app/core/theme/colors.dart';
|
|||||||
import 'package:tm_app/core/utils/size_config.dart';
|
import 'package:tm_app/core/utils/size_config.dart';
|
||||||
import 'package:tm_app/view_models/notification_view_model.dart';
|
import 'package:tm_app/view_models/notification_view_model.dart';
|
||||||
import 'package:tm_app/views/notification/strings/notification_strings.dart';
|
import 'package:tm_app/views/notification/strings/notification_strings.dart';
|
||||||
import 'package:tm_app/views/shared/page_selection_dialog.dart';
|
|
||||||
import 'package:tm_app/views/shared/desktop_navigation_widget.dart';
|
import 'package:tm_app/views/shared/desktop_navigation_widget.dart';
|
||||||
|
import 'package:tm_app/views/shared/page_selection_dialog.dart';
|
||||||
|
|
||||||
|
import '../../shared/main_tab_bar.dart';
|
||||||
import '../widgets/notification_all_tab.dart';
|
import '../widgets/notification_all_tab.dart';
|
||||||
import '../widgets/notification_important_tab.dart';
|
import '../widgets/notification_important_tab.dart';
|
||||||
import '../widgets/notification_unread_tab.dart';
|
import '../widgets/notification_unread_tab.dart';
|
||||||
import '../../shared/main_tab_bar.dart';
|
|
||||||
|
|
||||||
class DesktopNotificationPage extends StatefulWidget {
|
class DesktopNotificationPage extends StatefulWidget {
|
||||||
const DesktopNotificationPage({super.key});
|
const DesktopNotificationPage({super.key});
|
||||||
@@ -65,7 +66,9 @@ class _DesktopNotificationPageState extends State<DesktopNotificationPage>
|
|||||||
child: Align(
|
child: Align(
|
||||||
alignment: Alignment.centerRight,
|
alignment: Alignment.centerRight,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: viewModel.markAllAsRead,
|
onTap: () {
|
||||||
|
viewModel.markAllAsRead(context);
|
||||||
|
},
|
||||||
borderRadius: BorderRadius.circular(99),
|
borderRadius: BorderRadius.circular(99),
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 132.0.w(),
|
width: 132.0.w(),
|
||||||
@@ -116,8 +119,10 @@ class _DesktopNotificationPageState extends State<DesktopNotificationPage>
|
|||||||
onTap: () async {
|
onTap: () async {
|
||||||
final selectedPage = await showDialog<int>(
|
final selectedPage = await showDialog<int>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => PageSelectionDialog(
|
builder:
|
||||||
totalPages: viewModel.totalPages),
|
(context) => PageSelectionDialog(
|
||||||
|
totalPages: viewModel.totalPages,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (selectedPage != null) {
|
if (selectedPage != null) {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class _MobileNotificationPageState extends State<MobileNotificationPage>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final viewModel = context.watch<NotificationViewModel>(); // ✅ وصل به ویومدل
|
final viewModel = context.watch<NotificationViewModel>();
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: AppColors.backgroundColor,
|
backgroundColor: AppColors.backgroundColor,
|
||||||
@@ -72,7 +72,9 @@ class _MobileNotificationPageState extends State<MobileNotificationPage>
|
|||||||
child: Align(
|
child: Align(
|
||||||
alignment: Alignment.centerRight,
|
alignment: Alignment.centerRight,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: viewModel.markAllAsRead, // ✅ مثل دسکتاپ/تبلت
|
onTap: () {
|
||||||
|
viewModel.markAllAsRead(context);
|
||||||
|
},
|
||||||
borderRadius: BorderRadius.circular(99),
|
borderRadius: BorderRadius.circular(99),
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 132.0.w(),
|
width: 132.0.w(),
|
||||||
|
|||||||
@@ -70,7 +70,9 @@ class _TabletNotificationPageState extends State<TabletNotificationPage>
|
|||||||
child: Align(
|
child: Align(
|
||||||
alignment: Alignment.centerRight,
|
alignment: Alignment.centerRight,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: viewModel.markAllAsRead,
|
onTap: () {
|
||||||
|
viewModel.markAllAsRead(context);
|
||||||
|
},
|
||||||
borderRadius: BorderRadius.circular(99),
|
borderRadius: BorderRadius.circular(99),
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 132.0.w(),
|
width: 132.0.w(),
|
||||||
@@ -121,7 +123,8 @@ class _TabletNotificationPageState extends State<TabletNotificationPage>
|
|||||||
onTap: () async {
|
onTap: () async {
|
||||||
final selectedPage = await showDialog<int>(
|
final selectedPage = await showDialog<int>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => PageSelectionDialog(
|
builder:
|
||||||
|
(context) => PageSelectionDialog(
|
||||||
totalPages: viewModel.totalPages,
|
totalPages: viewModel.totalPages,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user