parent
7007c9af89
commit
b55a6e0e83
3 changed files with 42 additions and 22 deletions
|
|
@ -17,7 +17,9 @@ class SelectedRoomController extends Notifier<String?> {
|
||||||
(space) => space?.allChildRooms
|
(space) => space?.allChildRooms
|
||||||
.map((room) => room.metadata?.id)
|
.map((room) => room.metadata?.id)
|
||||||
.nonNulls
|
.nonNulls
|
||||||
.toIList(),
|
.toIList()
|
||||||
|
// Real spaces have a timeline of their own
|
||||||
|
.addAll([?space.room?.metadata?.id]),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (roomIds == null) return roomId;
|
if (roomIds == null) return roomId;
|
||||||
|
|
|
||||||
|
|
@ -4,20 +4,28 @@ import "package:navigation_rail_m3e/navigation_rail_m3e.dart";
|
||||||
import "package:nexus/models/room.dart";
|
import "package:nexus/models/room.dart";
|
||||||
import "package:nexus/widgets/avatar_or_hash.dart";
|
import "package:nexus/widgets/avatar_or_hash.dart";
|
||||||
|
|
||||||
extension RoomDestinations on IList<Room> {
|
extension RoomDestination on Room {
|
||||||
List<NavigationRailM3EDestination> toDestinations({required bool isDm}) =>
|
NavigationRailM3EDestination toDestination({
|
||||||
map(
|
required bool isDm,
|
||||||
(room) => NavigationRailM3EDestination(
|
String? label,
|
||||||
label: room.metadata?.name ?? "Unnamed Room",
|
Widget? icon,
|
||||||
badgeCount: switch (room.metadata?.unreadNotifications) {
|
}) => NavigationRailM3EDestination(
|
||||||
0 || null => room.metadata?.unreadMessages == 0 ? null : 0,
|
label: label ?? metadata?.name ?? "Unnamed Room",
|
||||||
|
badgeCount: switch (metadata?.unreadNotifications) {
|
||||||
|
0 || null => metadata?.unreadMessages == 0 ? null : 0,
|
||||||
int unread => unread,
|
int unread => unread,
|
||||||
},
|
},
|
||||||
icon: AvatarOrHash(
|
icon:
|
||||||
room.metadata?.avatar,
|
icon ??
|
||||||
room.metadata?.name ?? "Unnamed Room",
|
AvatarOrHash(
|
||||||
|
metadata?.avatar,
|
||||||
|
metadata?.name ?? "Unnamed Room",
|
||||||
fallback: isDm ? null : const Icon(Icons.numbers),
|
fallback: isDm ? null : const Icon(Icons.numbers),
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
).toList();
|
}
|
||||||
|
|
||||||
|
extension RoomDestinations on IList<Room> {
|
||||||
|
List<NavigationRailM3EDestination> toDestinations({required bool isDm}) =>
|
||||||
|
map((room) => room.toDestination(isDm: isDm)).toList();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import "dart:math";
|
import "dart:math";
|
||||||
|
|
||||||
|
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||||
import "package:hooks_riverpod/hooks_riverpod.dart";
|
import "package:hooks_riverpod/hooks_riverpod.dart";
|
||||||
import "package:material_ui/material_ui.dart";
|
import "package:material_ui/material_ui.dart";
|
||||||
import "package:m3e_design/m3e_design.dart";
|
import "package:m3e_design/m3e_design.dart";
|
||||||
|
|
@ -222,6 +223,9 @@ class const RoomsPane({super.key}) extends ConsumerWidget {
|
||||||
final selectedSpace = ref.watch(SelectedSpaceController.provider)!;
|
final selectedSpace = ref.watch(SelectedSpaceController.provider)!;
|
||||||
final isDm = selectedSpace.id == "dms";
|
final isDm = selectedSpace.id == "dms";
|
||||||
final spaceMetadata = selectedSpace.room?.metadata;
|
final spaceMetadata = selectedSpace.room?.metadata;
|
||||||
|
// In the order the rail shows them, with the space's own timeline first
|
||||||
|
final destinationIds = IList<String?>([?spaceMetadata?.id])
|
||||||
|
.addAll(selectedSpace.allChildRooms.map((room) => room.metadata?.id));
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
|
|
@ -287,13 +291,19 @@ class const RoomsPane({super.key}) extends ConsumerWidget {
|
||||||
scrollable: true,
|
scrollable: true,
|
||||||
background: Colors.transparent,
|
background: Colors.transparent,
|
||||||
type: .alwaysExpand,
|
type: .alwaysExpand,
|
||||||
selectedIndex: max(
|
selectedIndex: max(0, destinationIds.indexOf(selectedRoomId)),
|
||||||
0,
|
|
||||||
selectedSpace.allChildRooms.indexWhere(
|
|
||||||
(room) => room.metadata?.id == selectedRoomId,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
sections: [
|
sections: [
|
||||||
|
if (selectedSpace.room case final room?
|
||||||
|
when spaceMetadata != null)
|
||||||
|
.new(
|
||||||
|
destinations: [
|
||||||
|
room.toDestination(
|
||||||
|
isDm: isDm,
|
||||||
|
label: "Space timeline",
|
||||||
|
icon: const Icon(Icons.forum),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
.new(
|
.new(
|
||||||
header: selectedSpace.room == null
|
header: selectedSpace.room == null
|
||||||
? null
|
? null
|
||||||
|
|
@ -339,7 +349,7 @@ class const RoomsPane({super.key}) extends ConsumerWidget {
|
||||||
KeyController.provider(KeyController.roomKey)
|
KeyController.provider(KeyController.roomKey)
|
||||||
.notifier,
|
.notifier,
|
||||||
)
|
)
|
||||||
.set(selectedSpace.allChildRooms[value].metadata?.id);
|
.set(destinationIds[value]);
|
||||||
if (Navigator.of(context).canPop()) {
|
if (Navigator.of(context).canPop()) {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue