blah
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
|
||||
import 'package:shoppinglist/models/models.dart';
|
||||
@@ -31,6 +33,28 @@ class ApiService {
|
||||
pb.authStore.clear();
|
||||
}
|
||||
|
||||
Stream<void> watchLists() {
|
||||
if (userId == null) return Stream.value(null);
|
||||
|
||||
late final StreamController<void> controller;
|
||||
Future<void> Function()? unsubscribe;
|
||||
|
||||
controller = StreamController<void>(
|
||||
onListen: () async {
|
||||
unsubscribe = await pb.collection('lists').subscribe('*', (e) {
|
||||
if (!controller.isClosed) {
|
||||
controller.add(null);
|
||||
}
|
||||
}, filter: 'owner = "$userId" || members ?~ "$userId"');
|
||||
},
|
||||
onCancel: () {
|
||||
unsubscribe?.call();
|
||||
},
|
||||
);
|
||||
|
||||
return controller.stream;
|
||||
}
|
||||
|
||||
Future<List<Liste>> getLists() async {
|
||||
if (userId == null) return [];
|
||||
final List<RecordModel> res = await pb
|
||||
@@ -67,6 +91,26 @@ class ApiService {
|
||||
await pb.collection('lists').delete(listId);
|
||||
}
|
||||
|
||||
Stream<void> watchItems(String listId) {
|
||||
late final StreamController<void> controller;
|
||||
Future<void> Function()? unsubscribe;
|
||||
|
||||
controller = StreamController<void>(
|
||||
onListen: () async {
|
||||
unsubscribe = await pb.collection('items').subscribe('*', (e) {
|
||||
if (!controller.isClosed) {
|
||||
controller.add(null);
|
||||
}
|
||||
}, filter: 'list = "$listId"');
|
||||
},
|
||||
onCancel: () {
|
||||
unsubscribe?.call();
|
||||
},
|
||||
);
|
||||
|
||||
return controller.stream;
|
||||
}
|
||||
|
||||
Future<List<Item>> getItems(String listId) async {
|
||||
final List<RecordModel> res = await pb
|
||||
.collection('items')
|
||||
|
||||
Reference in New Issue
Block a user