178 lines
6.3 KiB
Dart
178 lines
6.3 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'announcements_provider.dart';
|
|
import 'attendance_provider.dart';
|
|
import 'chat_provider.dart';
|
|
import 'it_service_request_provider.dart';
|
|
import 'leave_provider.dart';
|
|
import 'notifications_provider.dart';
|
|
import 'pass_slip_provider.dart';
|
|
import 'profile_provider.dart';
|
|
import 'tasks_provider.dart';
|
|
import 'tickets_provider.dart';
|
|
import 'user_offices_provider.dart';
|
|
|
|
/// Total count of items waiting to sync across all modules.
|
|
/// Used by the offline banner and reconnect overlay for dynamic messaging.
|
|
final pendingSyncCountProvider = Provider<int>((ref) {
|
|
// Tasks
|
|
final tasks = ref.watch(offlinePendingTasksProvider).length;
|
|
final taskUpdates = ref.watch(offlinePendingTaskUpdatesProvider).length;
|
|
final messages = ref.watch(offlinePendingMessagesProvider)
|
|
.values
|
|
.fold<int>(0, (sum, list) => sum + list.length);
|
|
final assignments = ref.watch(offlinePendingAssignmentsProvider).length;
|
|
final activityLogs =
|
|
ref.watch(offlinePendingActivityLogItemsProvider).length;
|
|
|
|
// Leave
|
|
final leaves = ref.watch(offlinePendingLeavesProvider).length;
|
|
final leaveUpdates = ref.watch(offlinePendingLeaveUpdatesProvider).length;
|
|
|
|
// Pass slips
|
|
final passSlips = ref.watch(offlinePendingPassSlipsProvider).length;
|
|
final passSlipUpdates =
|
|
ref.watch(offlinePendingPassSlipUpdatesProvider).length;
|
|
|
|
// Announcements
|
|
final announcements = ref.watch(offlinePendingAnnouncementsProvider).length;
|
|
final announcementUpdates =
|
|
ref.watch(offlinePendingAnnouncementUpdatesProvider).length;
|
|
final announcementComments =
|
|
ref.watch(offlinePendingAnnouncementCommentsProvider).length;
|
|
|
|
// IT Service Requests
|
|
final itRequests =
|
|
ref.watch(offlinePendingItServiceRequestsProvider).length;
|
|
final itRequestUpdates =
|
|
ref.watch(offlinePendingItServiceRequestUpdatesProvider).length;
|
|
final isrActions = ref.watch(offlinePendingIsrActionsProvider).length;
|
|
|
|
// Attendance
|
|
final checkIns = ref.watch(offlinePendingCheckInsProvider).length;
|
|
final attendanceUpdates =
|
|
ref.watch(offlinePendingAttendanceUpdatesProvider).length;
|
|
|
|
// Notifications
|
|
final notifReads =
|
|
ref.watch(offlinePendingNotificationReadsProvider).length;
|
|
final notifBatchReads =
|
|
ref.watch(offlinePendingBatchNotificationReadsProvider).length;
|
|
|
|
// Profile
|
|
final profileUpdates =
|
|
ref.watch(offlinePendingProfileUpdatesProvider).length;
|
|
|
|
// Tickets
|
|
final tickets = ref.watch(offlinePendingTicketsProvider).length;
|
|
final ticketUpdates =
|
|
ref.watch(offlinePendingTicketUpdatesProvider).length;
|
|
|
|
// Offices
|
|
final offices = ref.watch(offlinePendingOfficesProvider).length;
|
|
|
|
// User offices
|
|
final officeOps = ref.watch(offlinePendingUserOfficeOpsProvider).length;
|
|
|
|
// Chat
|
|
final chatMessages = ref.watch(offlinePendingChatMessagesProvider)
|
|
.values
|
|
.fold<int>(0, (sum, list) => sum + list.length);
|
|
|
|
return tasks +
|
|
taskUpdates +
|
|
messages +
|
|
assignments +
|
|
activityLogs +
|
|
leaves +
|
|
leaveUpdates +
|
|
passSlips +
|
|
passSlipUpdates +
|
|
announcements +
|
|
announcementUpdates +
|
|
announcementComments +
|
|
itRequests +
|
|
itRequestUpdates +
|
|
isrActions +
|
|
checkIns +
|
|
attendanceUpdates +
|
|
notifReads +
|
|
notifBatchReads +
|
|
profileUpdates +
|
|
tickets +
|
|
ticketUpdates +
|
|
offices +
|
|
officeOps +
|
|
chatMessages;
|
|
});
|
|
|
|
/// Per-category breakdown of pending-sync items (only non-zero entries).
|
|
/// Keys are stable category identifiers used for icon/label lookup in the UI.
|
|
final pendingSyncBreakdownProvider = Provider<Map<String, int>>((ref) {
|
|
final result = <String, int>{};
|
|
|
|
final tasks = ref.watch(offlinePendingTasksProvider).length +
|
|
ref.watch(offlinePendingTaskUpdatesProvider).length;
|
|
if (tasks > 0) result['tasks'] = tasks;
|
|
|
|
final tickets = ref.watch(offlinePendingTicketsProvider).length +
|
|
ref.watch(offlinePendingTicketUpdatesProvider).length;
|
|
if (tickets > 0) result['tickets'] = tickets;
|
|
|
|
final messages = ref
|
|
.watch(offlinePendingMessagesProvider)
|
|
.values
|
|
.fold<int>(0, (s, l) => s + l.length) +
|
|
ref
|
|
.watch(offlinePendingChatMessagesProvider)
|
|
.values
|
|
.fold<int>(0, (s, l) => s + l.length);
|
|
if (messages > 0) result['messages'] = messages;
|
|
|
|
final assignments = ref.watch(offlinePendingAssignmentsProvider).length;
|
|
if (assignments > 0) result['assignments'] = assignments;
|
|
|
|
final activityLogs =
|
|
ref.watch(offlinePendingActivityLogItemsProvider).length;
|
|
if (activityLogs > 0) result['activity_logs'] = activityLogs;
|
|
|
|
final checkIns = ref.watch(offlinePendingCheckInsProvider).length;
|
|
if (checkIns > 0) result['check_ins'] = checkIns;
|
|
|
|
final attendanceUpdates =
|
|
ref.watch(offlinePendingAttendanceUpdatesProvider).length;
|
|
if (attendanceUpdates > 0) result['attendance'] = attendanceUpdates;
|
|
|
|
final leaves = ref.watch(offlinePendingLeavesProvider).length +
|
|
ref.watch(offlinePendingLeaveUpdatesProvider).length;
|
|
if (leaves > 0) result['leaves'] = leaves;
|
|
|
|
final passSlips = ref.watch(offlinePendingPassSlipsProvider).length +
|
|
ref.watch(offlinePendingPassSlipUpdatesProvider).length;
|
|
if (passSlips > 0) result['pass_slips'] = passSlips;
|
|
|
|
final announcements = ref.watch(offlinePendingAnnouncementsProvider).length +
|
|
ref.watch(offlinePendingAnnouncementUpdatesProvider).length +
|
|
ref.watch(offlinePendingAnnouncementCommentsProvider).length;
|
|
if (announcements > 0) result['announcements'] = announcements;
|
|
|
|
final itRequests = ref.watch(offlinePendingItServiceRequestsProvider).length +
|
|
ref.watch(offlinePendingItServiceRequestUpdatesProvider).length +
|
|
ref.watch(offlinePendingIsrActionsProvider).length;
|
|
if (itRequests > 0) result['it_requests'] = itRequests;
|
|
|
|
final notifReads = ref.watch(offlinePendingNotificationReadsProvider).length +
|
|
ref.watch(offlinePendingBatchNotificationReadsProvider).length;
|
|
if (notifReads > 0) result['notification_reads'] = notifReads;
|
|
|
|
final profileUpdates =
|
|
ref.watch(offlinePendingProfileUpdatesProvider).length;
|
|
if (profileUpdates > 0) result['profile_updates'] = profileUpdates;
|
|
|
|
final officeChanges = ref.watch(offlinePendingOfficesProvider).length +
|
|
ref.watch(offlinePendingUserOfficeOpsProvider).length;
|
|
if (officeChanges > 0) result['office_changes'] = officeChanges;
|
|
|
|
return result;
|
|
});
|