add pagination for pages
This commit is contained in:
@@ -13,89 +13,28 @@ class CustomerModel extends BaseModel {
|
||||
final log = Logger('CustomerModel');
|
||||
PaginatorListener<User>? getCustomers;
|
||||
|
||||
List<User> customers = [];
|
||||
List<User> invitations = [];
|
||||
StreamSubscription<QuerySnapshot>? customerListener;
|
||||
StreamSubscription<QuerySnapshot>? invitationListener;
|
||||
|
||||
@override
|
||||
void privilegeChanged() {
|
||||
super.privilegeChanged();
|
||||
_loadCustomer();
|
||||
_loadInvitations();
|
||||
}
|
||||
|
||||
@override
|
||||
logout() async {
|
||||
if (customerListener != null) customerListener!.cancel();
|
||||
if (invitationListener != null) invitationListener!.cancel();
|
||||
customers = [];
|
||||
invitations = [];
|
||||
getCustomers?.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Future<void> inviteUser(String userName, String phoneNumber) {
|
||||
return Services.instance.userService.inviteUser(userName, phoneNumber);
|
||||
}
|
||||
|
||||
Future<void> deleteInvite(String phoneNumber) {
|
||||
return Services.instance.userService.deleteInvite(phoneNumber);
|
||||
}
|
||||
|
||||
Future<void> acceptRequest(String userID) {
|
||||
return Services.instance.userService.acceptRequest(userID);
|
||||
}
|
||||
|
||||
Future<void> _loadCustomer() async {
|
||||
loadPaginationCustomers() {
|
||||
if (user == null && !user!.hasCustomers()) return;
|
||||
|
||||
try {
|
||||
if (customerListener != null) customerListener!.cancel();
|
||||
String path = "/$user_collection";
|
||||
Query col = FirebaseFirestore.instance
|
||||
.collection(path)
|
||||
.where("is_sys_admin", isEqualTo: false);
|
||||
|
||||
customerListener = FirebaseFirestore.instance
|
||||
.collection("/$user_collection")
|
||||
.where("is_sys_admin", isEqualTo: false)
|
||||
.orderBy("message_time", descending: true)
|
||||
.snapshots()
|
||||
.listen((QuerySnapshot snapshot) {
|
||||
customers.clear();
|
||||
customers = snapshot.docs.map((documentSnapshot) {
|
||||
var user = User.fromMap(
|
||||
documentSnapshot.data() as Map<String, dynamic>,
|
||||
documentSnapshot.id);
|
||||
return user;
|
||||
}).toList();
|
||||
notifyListeners();
|
||||
});
|
||||
} catch (e) {
|
||||
log.warning("error:$e");
|
||||
}
|
||||
}
|
||||
Query pageQuery = FirebaseFirestore.instance
|
||||
.collection(path)
|
||||
.where("is_sys_admin", isEqualTo: false)
|
||||
.orderBy("message_time", descending: true);
|
||||
|
||||
Future<void> _loadInvitations() async {
|
||||
if (user == null && !user!.hasCustomers()) return;
|
||||
|
||||
try {
|
||||
if (invitationListener != null) invitationListener!.cancel();
|
||||
|
||||
invitationListener = FirebaseFirestore.instance
|
||||
.collection("/$invitations_collection")
|
||||
.snapshots()
|
||||
.listen((QuerySnapshot snapshot) {
|
||||
invitations.clear();
|
||||
invitations = snapshot.docs.map((documentSnapshot) {
|
||||
var user = User.fromMap(
|
||||
documentSnapshot.data() as Map<String, dynamic>,
|
||||
documentSnapshot.id);
|
||||
return user;
|
||||
}).toList();
|
||||
notifyListeners();
|
||||
});
|
||||
} catch (e) {
|
||||
log.warning("error:$e");
|
||||
}
|
||||
getCustomers?.close();
|
||||
getCustomers = PaginatorListener<User>(
|
||||
col, pageQuery, (data, id) => User.fromMap(data, id),
|
||||
rowPerLoad: 30);
|
||||
}
|
||||
|
||||
Future<User> getUser(String? id) async {
|
||||
@@ -125,4 +64,16 @@ class CustomerModel extends BaseModel {
|
||||
Future<void> enableUser(User user, bool enabled) {
|
||||
return Services.instance.userService.enableUser(user.id ?? "", enabled);
|
||||
}
|
||||
|
||||
Future<void> inviteUser(String userName, String phoneNumber) {
|
||||
return Services.instance.userService.inviteUser(userName, phoneNumber);
|
||||
}
|
||||
|
||||
Future<void> deleteInvite(String phoneNumber) {
|
||||
return Services.instance.userService.deleteInvite(phoneNumber);
|
||||
}
|
||||
|
||||
Future<void> acceptRequest(String userID) {
|
||||
return Services.instance.userService.acceptRequest(userID);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user