Skip to content

Commit

Permalink
[gui] add info provider that allows manual data retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-toterman committed Dec 17, 2024
1 parent 7f7d7fd commit 93e8e78
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/client/gui/lib/providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,24 @@ final daemonAvailableProvider = Provider((ref) {
return false;
});

class AllVmInfosNotifier extends Notifier<List<DetailedInfoItem>> {
@override
List<DetailedInfoItem> build() {
return ref.watch(vmInfosStreamProvider).valueOrNull ?? const [];
}

Future<void> update() async {
state = await ref.read(grpcClientProvider).info();
}
}

final allVmInfosProvider =
NotifierProvider<AllVmInfosNotifier, List<DetailedInfoItem>>(
AllVmInfosNotifier.new);

final vmInfosProvider = Provider((ref) {
final vmInfos = ref.watch(vmInfosStreamProvider).valueOrNull ?? const [];
final existingVms = vmInfos
final existingVms = ref
.watch(allVmInfosProvider)
.where((info) => info.instanceStatus.status != Status.DELETED)
.toBuiltList();
final existingVmNames = existingVms.map((i) => i.name).toSet();
Expand Down Expand Up @@ -112,8 +127,8 @@ final vmNamesProvider = Provider((ref) {
});

final deletedVmsProvider = Provider((ref) {
final vmInfos = ref.watch(vmInfosStreamProvider).valueOrNull ?? const [];
return vmInfos
return ref
.watch(allVmInfosProvider)
.where((info) => info.instanceStatus.status == Status.DELETED)
.map((info) => info.name)
.toBuiltSet();
Expand Down

0 comments on commit 93e8e78

Please sign in to comment.