parent
9e024fb6f2
commit
281bab0202
9 changed files with 230 additions and 204 deletions
36
lib/helpers/extensions/focus_room.dart
Normal file
36
lib/helpers/extensions/focus_room.dart
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import "package:collection/collection.dart";
|
||||
import "package:flutter_riverpod/experimental/mutation.dart";
|
||||
import "package:nexus/controllers/key.dart";
|
||||
import "package:nexus/controllers/spaces.dart";
|
||||
import "package:nexus/models/space.dart";
|
||||
|
||||
extension FocusRoom on MutationTarget {
|
||||
Future<void> focusRoom(String id) async {
|
||||
final spaces = container.read(SpacesController.provider);
|
||||
|
||||
if (spaces.firstWhereOrNull((space) => space.id == id) case Space _?) {
|
||||
return await container
|
||||
.read(KeyController.provider(KeyController.spaceKey).notifier)
|
||||
.set(id);
|
||||
}
|
||||
|
||||
final parent = spaces.firstWhereOrNull(
|
||||
(space) =>
|
||||
space.children.any((room) => room.metadata?.id == id) ||
|
||||
space.subSpaces.any(
|
||||
(sub) =>
|
||||
sub.room.metadata?.id == id ||
|
||||
sub.children.any((room) => room.metadata?.id == id),
|
||||
),
|
||||
);
|
||||
if (parent == null) return;
|
||||
|
||||
await container
|
||||
.read(KeyController.provider(KeyController.spaceKey).notifier)
|
||||
.set(parent.id);
|
||||
|
||||
await container
|
||||
.read(KeyController.provider(KeyController.roomKey).notifier)
|
||||
.set(id);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue