Badge unseenSalesCount di tab Riwayat (admin only), reset saat tab dibuka
This commit is contained in:
@@ -33,6 +33,16 @@ class AppState extends ChangeNotifier {
|
||||
StreamController<Sale>.broadcast();
|
||||
final Set<String> _notifiedSaleIds = {};
|
||||
|
||||
// Jumlah transaksi baru yang belum dilihat admin (badge di tab Riwayat).
|
||||
int unseenSalesCount = 0;
|
||||
|
||||
void markSalesSeen() {
|
||||
if (unseenSalesCount != 0) {
|
||||
unseenSalesCount = 0;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
// Client dengan service_role key untuk operasi admin (buat/edit/hapus akun kasir).
|
||||
// PERINGATAN: key ini bypass RLS — hanya untuk app POS di device terpercaya.
|
||||
final SupabaseClient _admin = SupabaseClient(supabaseUrl, supabaseServiceKey);
|
||||
@@ -159,6 +169,7 @@ class AppState extends ChangeNotifier {
|
||||
return;
|
||||
}
|
||||
final now = DateTime.now();
|
||||
bool newSeen = false;
|
||||
for (final s in sales) {
|
||||
if (!_notifiedSaleIds.contains(s.id)) {
|
||||
_notifiedSaleIds.add(s.id);
|
||||
@@ -166,12 +177,16 @@ class AppState extends ChangeNotifier {
|
||||
// Lewati juga transaksi sendiri — admin tahu kalau dia yang jualan.
|
||||
if (!_salesFirstLoad &&
|
||||
s.userId != userId &&
|
||||
now.difference(s.date).inMinutes.abs() <= 5 &&
|
||||
!newSaleNotifications.isClosed) {
|
||||
newSaleNotifications.add(s);
|
||||
now.difference(s.date).inMinutes.abs() <= 5) {
|
||||
newSeen = true;
|
||||
unseenSalesCount++;
|
||||
if (!newSaleNotifications.isClosed) {
|
||||
newSaleNotifications.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (newSeen) notifyListeners();
|
||||
_salesFirstLoad = false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user