forked from Henry-Hiles/nexus
working sidebar
This commit is contained in:
parent
f51d773885
commit
7b0fea3a07
13 changed files with 491 additions and 436 deletions
|
|
@ -1,87 +1,87 @@
|
|||
import "package:collection/collection.dart";
|
||||
import "package:flutter/material.dart";
|
||||
import "package:hooks_riverpod/hooks_riverpod.dart";
|
||||
import "package:matrix/matrix.dart";
|
||||
import "package:nexus/controllers/client_controller.dart";
|
||||
import "package:nexus/controllers/key_controller.dart";
|
||||
import "package:nexus/controllers/spaces_controller.dart";
|
||||
|
||||
extension JoinRoomWithSnackbars on Client {
|
||||
extension JoinRoomWithSnackbars on ClientController {
|
||||
Future<void> joinRoomWithSnackBars(
|
||||
BuildContext context,
|
||||
String roomAlias,
|
||||
WidgetRef ref,
|
||||
) async {
|
||||
final parsed = roomAlias.parseIdentifierIntoParts();
|
||||
final alias = parsed?.primaryIdentifier ?? roomAlias;
|
||||
// final parsed = roomAlias.parseIdentifierIntoParts();
|
||||
// final alias = parsed?.primaryIdentifier ?? roomAlias;
|
||||
|
||||
final scaffoldMessenger = ScaffoldMessenger.of(context);
|
||||
// final scaffoldMessenger = ScaffoldMessenger.of(context);
|
||||
|
||||
final snackbar = scaffoldMessenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text("Joining room $alias."),
|
||||
duration: Duration(days: 999),
|
||||
),
|
||||
);
|
||||
// final snackbar = scaffoldMessenger.showSnackBar(
|
||||
// SnackBar(
|
||||
// content: Text("Joining room $alias."),
|
||||
// duration: Duration(days: 999),
|
||||
// ),
|
||||
// );
|
||||
|
||||
try {
|
||||
final id = await joinRoom(alias, via: parsed?.via.toList());
|
||||
// try {
|
||||
// final id = await joinRoom(alias, via: parsed?.via.toList());
|
||||
|
||||
snackbar.close();
|
||||
// snackbar.close();
|
||||
|
||||
scaffoldMessenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text("Room $alias successfully joined."),
|
||||
action: SnackBarAction(
|
||||
label: "Open",
|
||||
onPressed: () async {
|
||||
final spaces = await ref.refresh(
|
||||
SpacesController.provider.future,
|
||||
);
|
||||
final space = spaces.firstWhereOrNull((space) => space.id == id);
|
||||
// scaffoldMessenger.showSnackBar(
|
||||
// SnackBar(
|
||||
// content: Text("Room $alias successfully joined."),
|
||||
// action: SnackBarAction(
|
||||
// label: "Open",
|
||||
// onPressed: () async {
|
||||
// final spaces = await ref.refresh(
|
||||
// SpacesController.provider.future,
|
||||
// );
|
||||
// final space = spaces.firstWhereOrNull((space) => space.id == id);
|
||||
|
||||
await ref
|
||||
.watch(
|
||||
KeyController.provider(KeyController.spaceKey).notifier,
|
||||
)
|
||||
.set(
|
||||
space?.id ??
|
||||
spaces
|
||||
.firstWhere(
|
||||
(space) =>
|
||||
space.children.firstWhereOrNull(
|
||||
(child) => child.roomData.id == id,
|
||||
) !=
|
||||
null,
|
||||
)
|
||||
.id,
|
||||
);
|
||||
// await ref
|
||||
// .watch(
|
||||
// KeyController.provider(KeyController.spaceKey).notifier,
|
||||
// )
|
||||
// .set(
|
||||
// space?.id ??
|
||||
// spaces
|
||||
// .firstWhere(
|
||||
// (space) =>
|
||||
// space.children.firstWhereOrNull(
|
||||
// (child) => child.roomData.id == id,
|
||||
// ) !=
|
||||
// null,
|
||||
// )
|
||||
// .id,
|
||||
// );
|
||||
|
||||
if (space == null) {
|
||||
await ref
|
||||
.watch(
|
||||
KeyController.provider(KeyController.roomKey).notifier,
|
||||
)
|
||||
.set(id);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
} catch (error) {
|
||||
snackbar.close();
|
||||
if (context.mounted) {
|
||||
scaffoldMessenger.showSnackBar(
|
||||
SnackBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.errorContainer,
|
||||
content: Text(
|
||||
error.toString(),
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.onErrorContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
// if (space == null) {
|
||||
// await ref
|
||||
// .watch(
|
||||
// KeyController.provider(KeyController.roomKey).notifier,
|
||||
// )
|
||||
// .set(id);
|
||||
// }
|
||||
// },
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// } catch (error) {
|
||||
// snackbar.close();
|
||||
// if (context.mounted) {
|
||||
// scaffoldMessenger.showSnackBar(
|
||||
// SnackBar(
|
||||
// backgroundColor: Theme.of(context).colorScheme.errorContainer,
|
||||
// content: Text(
|
||||
// error.toString(),
|
||||
// style: TextStyle(
|
||||
// color: Theme.of(context).colorScheme.onErrorContainer,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue