WIP subspace support
This commit is contained in:
parent
7e7e6877e2
commit
6e02cce84f
5 changed files with 54 additions and 25 deletions
|
|
@ -103,12 +103,14 @@ class SpacesController extends Notifier<IList<Space>> {
|
|||
title: "Home",
|
||||
icon: Icons.home,
|
||||
children: homeRooms,
|
||||
subSpaces: .new(),
|
||||
),
|
||||
.new(
|
||||
id: "dms",
|
||||
title: "Direct Messages",
|
||||
icon: Icons.people,
|
||||
children: dmRooms,
|
||||
subSpaces: .new(),
|
||||
),
|
||||
...topLevelSpacesList,
|
||||
]
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
|||
import "package:flutter/widgets.dart";
|
||||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/models/room.dart";
|
||||
import "package:nexus/models/subspace.dart";
|
||||
part "space.freezed.dart";
|
||||
|
||||
@freezed
|
||||
|
|
@ -12,5 +13,6 @@ abstract class Space with _$Space {
|
|||
IconData? icon,
|
||||
Room? room,
|
||||
required IList<Room> children,
|
||||
required IList<Subspace> subSpaces,
|
||||
}) = _Space;
|
||||
}
|
||||
|
|
|
|||
10
lib/models/subspace.dart
Normal file
10
lib/models/subspace.dart
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/models/room.dart";
|
||||
part "subspace.freezed.dart";
|
||||
|
||||
@freezed
|
||||
abstract class Subspace with _$Subspace {
|
||||
const factory Subspace({required Room room, required IList<Room> children}) =
|
||||
_Subspace;
|
||||
}
|
||||
|
|
@ -84,9 +84,15 @@ class JoinDialog extends HookWidget {
|
|||
space?.id ??
|
||||
spaces
|
||||
.firstWhere(
|
||||
(space) => space.children.any(
|
||||
(child) => child.metadata?.id == id,
|
||||
),
|
||||
(space) =>
|
||||
space.children.any(
|
||||
(child) =>
|
||||
child.metadata?.id == id,
|
||||
) ||
|
||||
space.subSpaces.any(
|
||||
(child) =>
|
||||
child.room.metadata?.id == id,
|
||||
),
|
||||
)
|
||||
.id,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
import "package:collection/collection.dart";
|
||||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:flutter/material.dart";
|
||||
import "package:hooks_riverpod/hooks_riverpod.dart";
|
||||
import "package:navigation_rail_m3e/navigation_rail_m3e.dart";
|
||||
import "package:nexus/controllers/key_controller.dart";
|
||||
import "package:nexus/controllers/spaces_controller.dart";
|
||||
import "package:nexus/models/room.dart";
|
||||
import "package:nexus/widgets/avatar_or_hash.dart";
|
||||
import "package:nexus/widgets/join_dialog.dart";
|
||||
import "package:nexus/widgets/room_menu.dart";
|
||||
|
|
@ -43,6 +45,27 @@ class Sidebar extends HookConsumerWidget {
|
|||
? null
|
||||
: indexOfSelectedRoom;
|
||||
|
||||
List<NavigationRailM3EDestination> roomsToDestinations(IList<Room> rooms) =>
|
||||
rooms
|
||||
.map(
|
||||
(room) => NavigationRailM3EDestination(
|
||||
label: room.metadata?.name ?? "Unnamed Room",
|
||||
badgeCount: switch (room.metadata?.unreadNotifications) {
|
||||
0 || null => room.metadata?.unreadMessages == 0 ? null : 0,
|
||||
int unread => unread,
|
||||
},
|
||||
icon: AvatarOrHash(
|
||||
room.metadata?.avatar,
|
||||
room.metadata?.name ?? "Unnamed Room",
|
||||
fallback: selectedSpaceId == "dms"
|
||||
? null
|
||||
: Icon(Icons.numbers),
|
||||
// space.client.headers,
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
|
||||
return Drawer(
|
||||
width: 340,
|
||||
shape: Border(),
|
||||
|
|
@ -189,29 +212,15 @@ class Sidebar extends HookConsumerWidget {
|
|||
selectedIndex: selectedRoomIndex ?? 0,
|
||||
sections: [
|
||||
.new(
|
||||
destinations: selectedSpace.children
|
||||
.map(
|
||||
(room) => NavigationRailM3EDestination(
|
||||
label: room.metadata?.name ?? "Unnamed Room",
|
||||
badgeCount: switch (room
|
||||
.metadata
|
||||
?.unreadNotifications) {
|
||||
0 || null =>
|
||||
room.metadata?.unreadMessages == 0 ? null : 0,
|
||||
int unread => unread,
|
||||
},
|
||||
icon: AvatarOrHash(
|
||||
room.metadata?.avatar,
|
||||
room.metadata?.name ?? "Unnamed Room",
|
||||
fallback: selectedSpaceId == "dms"
|
||||
? null
|
||||
: Icon(Icons.numbers),
|
||||
// space.client.headers,
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
destinations: roomsToDestinations(selectedSpace.children),
|
||||
),
|
||||
for (final subSpace in selectedSpace.subSpaces)
|
||||
.new(
|
||||
header: Text(
|
||||
subSpace.room.metadata?.name ?? "Unnamed Room",
|
||||
),
|
||||
destinations: roomsToDestinations(subSpace.children),
|
||||
),
|
||||
],
|
||||
onDestinationSelected: (value) {
|
||||
selectedRoomIdNotifier.set(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue