Compare commits

..
6 changed files with 129 additions and 101 deletions

View file

@ -18,9 +18,8 @@ extension ShowLeaveRoomSheet on BuildContext {
),
TextButton(
onPressed: () {
final client = ProviderScope.containerOf(
context,
).read(ClientController.provider.notifier);
final client = ProviderScope.containerOf(context)
.read(ClientController.provider.notifier);
context.withProgressSnackbar(
"Leaving $name...",
() => client.leaveRoom(roomId),

View file

@ -3,6 +3,7 @@ import "package:nexus/models/content/create.dart";
import "package:nexus/models/content/membership.dart";
import "package:nexus/models/join_rule.dart";
import "package:nexus/models/membership_status.dart";
import "package:nexus/models/room_metadata.dart";
part "room_summary.freezed.dart";
part "room_summary.g.dart";
@ -40,6 +41,16 @@ class const RoomSummary({
/// Whether this is an invite to a direct message.
@JsonKey(includeFromJson: false) final bool isDirect = false,
}) with _$RoomSummary {
/// A summary of a room the user is in, from its synced metadata.
factory RoomSummary.fromMetadata(RoomMetadata metadata) => .new(
roomId: metadata.id,
joinedMembers: metadata.lazyLoadSummary?.joinedMemberCount,
avatarUrl: metadata.avatar,
canonicalAlias: metadata.canonicalAlias,
name: metadata.name,
topic: metadata.topic,
);
factory RoomSummary.fromJson(Map<String, Object?> json) =>
_$RoomSummaryFromJson(json);
}

View file

@ -13,6 +13,9 @@ final class const Appbar({
final double? scrolledUnderElevation,
final IList<Widget> actions = const .empty(),
final VoidCallback? onTap,
/// Whether to show the minimize, maximize and close buttons on desktop.
final bool windowControls = true,
super.key,
}) extends ConsumerWidget implements PreferredSizeWidget {
@override
@ -50,7 +53,7 @@ final class const Appbar({
flexibleSpace: GestureDetector(onDoubleTap: maximize),
actions: [
...actions,
if (!(Platform.isAndroid || Platform.isIOS)) ...[
if (windowControls && !(Platform.isAndroid || Platform.isIOS)) ...[
if (ref
.watch(SettingsController.provider)
.whenOrNull(

View file

@ -7,6 +7,7 @@ import "package:nexus/widgets/avatar_or_hash.dart";
import "package:nexus/widgets/count_badge.dart";
import "package:nexus/widgets/room_menu_button.dart";
import "package:nexus/widgets/room_summary_sheet.dart";
import "package:nexus/widgets/room_title.dart";
import "package:nexus/widgets/sidebar.dart";
final class const RoomAppbar({
@ -30,17 +31,7 @@ final class const RoomAppbar({
onTap: room?.metadata == null
? null
: () => context.showAdaptiveSheet(
(context) => RoomSummarySheet(
.new(
roomId: room!.metadata!.id,
joinedMembers:
room.metadata!.lazyLoadSummary?.joinedMemberCount,
avatarUrl: room.metadata?.avatar,
canonicalAlias: room.metadata?.canonicalAlias,
name: room.metadata?.name,
topic: room.metadata?.topic,
),
),
(context) => RoomSummarySheet(.fromMetadata(room!.metadata!)),
),
leading: isDesktop
? room == null
@ -62,24 +53,9 @@ final class const RoomAppbar({
scrolledUnderElevation: 0,
title: room == null
? null
: Column(
crossAxisAlignment: .start,
children: [
Text(
room.metadata?.name ?? "Unnamed Room",
overflow: .ellipsis,
maxLines: 1,
),
if (room.metadata?.topic?.isNotEmpty == true)
Text(
room.metadata!.topic!,
maxLines: 1,
overflow: .ellipsis,
style: Theme.of(context).textTheme.labelMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
],
: RoomTitle(
room.metadata?.name ?? "Unnamed Room",
topic: room.metadata?.topic,
),
actions: .new(
room == null

View file

@ -9,6 +9,8 @@ import "package:nexus/helpers/extensions/room_destinations.dart";
import "package:nexus/helpers/extensions/show_adaptive_sheet.dart";
import "package:nexus/widgets/adaptive_menu_button.dart";
import "package:nexus/models/nav_page.dart";
import "package:nexus/widgets/appbar.dart";
import "package:nexus/widgets/room_title.dart";
import "package:nexus/widgets/avatar_or_hash.dart";
import "package:nexus/widgets/create_room_sheet.dart";
import "package:nexus/widgets/start_dm_sheet.dart";
@ -16,6 +18,7 @@ import "package:nexus/widgets/divider_widget.dart";
import "package:nexus/widgets/error_dialog.dart";
import "package:nexus/widgets/pages/settings.dart";
import "package:nexus/widgets/join_sheet.dart";
import "package:nexus/widgets/room_summary_sheet.dart";
import "package:nexus/widgets/room_menu_button.dart";
import "package:nexus/widgets/space_hierarchy_sheet.dart";
import "package:nexus/controllers/key.dart";
@ -188,7 +191,7 @@ class const SpacesRail({super.key}) extends ConsumerWidget {
icon: const Icon(Icons.add),
),
const IconButton(
tooltip: "Explore other rooms",
tooltip: "Explore other rooms (Not yet implemented)",
onPressed: null,
icon: Icon(Icons.explore),
),
@ -232,25 +235,33 @@ class const RoomsPane({super.key}) extends ConsumerWidget {
}),
);
final isDm = selectedSpace.id == "dms";
final spaceMetadata = selectedSpace.room?.metadata;
return Scaffold(
backgroundColor: Colors.transparent,
appBar: AppBar(
appBar: Appbar(
// Home and DMs aren't real spaces, so they don't have a summary.
onTap: spaceMetadata == null
? null
: () => context.showAdaptiveSheet(
(_) => RoomSummarySheet(.fromMetadata(spaceMetadata)),
),
windowControls: false,
leading: AvatarOrHash(
selectedSpace.room?.metadata?.avatar,
spaceMetadata?.avatar,
fallback: selectedSpace.icon == null
? null
: Icon(selectedSpace.icon),
selectedSpace.title,
),
title: Text(selectedSpace.title, overflow: .ellipsis),
title: RoomTitle(selectedSpace.title, topic: spaceMetadata?.topic),
backgroundColor: Colors.transparent,
actions: [
actions: .new([
RoomMenuButton(
selectedSpace.room,
children: selectedSpace.allChildRooms,
),
],
]),
),
body: MaterialUiCompatibilityBridge(
child: Builder(
@ -273,75 +284,81 @@ class const RoomsPane({super.key}) extends ConsumerWidget {
),
],
),
child: NavigationRailM3E(
fab: selectedSpace.room == null
? null
: .new(
icon: const Icon(Icons.explore),
label: "Browse space",
tooltip: "Browse and join rooms in this space",
onPressed: () => context.showAdaptiveSheet(
(_) => SpaceHierarchySheet(selectedSpace.id),
child: Padding(
padding: const .only(top: 4),
child: NavigationRailM3E(
fab: selectedSpace.room == null
? null
: .new(
icon: const Icon(Icons.explore),
label: "Browse space",
tooltip: "Browse and join rooms in this space",
onPressed: () => context.showAdaptiveSheet(
(_) => SpaceHierarchySheet(selectedSpace.id),
),
),
),
expandedWidth: double.infinity,
scrollable: true,
background: Colors.transparent,
type: .alwaysExpand,
selectedIndex: max(
0,
selectedSpace.allChildRooms.indexWhere(
(room) => room.metadata?.id == selectedRoomId,
),
),
sections: [
.new(
header: selectedSpace.room == null
? null
: const DividerWidget(Text("Rooms")),
destinations: selectedSpace.children.toDestinations(
isDm: isDm,
expandedWidth: double.infinity,
scrollable: true,
background: Colors.transparent,
type: .alwaysExpand,
selectedIndex: max(
0,
selectedSpace.allChildRooms.indexWhere(
(room) => room.metadata?.id == selectedRoomId,
),
),
...selectedSpace.subSpaces.map(
(subSpace) => NavigationRailM3ESection(
header: DividerWidget(
Row(
mainAxisSize: .min,
spacing: 8,
children: [
if (subSpace.room.metadata?.avatar != null)
AvatarOrHash(
subSpace.room.metadata?.avatar,
subSpace.room.metadata?.name ?? "Unnamed Room",
dimension: 16,
),
Flexible(
child: Text(
subSpace.room.metadata?.name ?? "Unnamed Space",
maxLines: 1,
overflow: .ellipsis,
),
),
],
),
),
destinations: subSpace.children.toDestinations(
sections: [
.new(
header: selectedSpace.room == null
? null
: const DividerWidget(Text("Rooms")),
destinations: selectedSpace.children.toDestinations(
isDm: isDm,
),
),
),
],
onDestinationSelected: (value) {
ref
.read(
KeyController.provider(KeyController.roomKey).notifier,
)
.set(selectedSpace.allChildRooms[value].metadata?.id);
if (Navigator.of(context).canPop()) {
Navigator.of(context).pop();
}
},
...selectedSpace.subSpaces.map(
(subSpace) => NavigationRailM3ESection(
header: DividerWidget(
Row(
mainAxisSize: .min,
spacing: 8,
children: [
if (subSpace.room.metadata?.avatar != null)
AvatarOrHash(
subSpace.room.metadata?.avatar,
subSpace.room.metadata?.name ??
"Unnamed Room",
dimension: 16,
),
Flexible(
child: Text(
subSpace.room.metadata?.name ??
"Unnamed Space",
maxLines: 1,
overflow: .ellipsis,
),
),
],
),
),
destinations: subSpace.children.toDestinations(
isDm: isDm,
),
),
),
],
onDestinationSelected: (value) {
ref
.read(
KeyController.provider(KeyController.roomKey)
.notifier,
)
.set(selectedSpace.allChildRooms[value].metadata?.id);
if (Navigator.of(context).canPop()) {
Navigator.of(context).pop();
}
},
),
),
);
},

View file

@ -0,0 +1,22 @@
import "package:material_ui/material_ui.dart";
/// A room or space's name, with its topic underneath if it has one, for app
/// bars.
class const RoomTitle(final String name, {final String? topic, super.key})
extends StatelessWidget {
@override
Widget build(BuildContext context) => Column(
crossAxisAlignment: .start,
children: [
Text(name, overflow: .ellipsis, maxLines: 1),
if (topic?.isNotEmpty == true)
Text(
topic!,
maxLines: 1,
overflow: .ellipsis,
style: Theme.of(context).textTheme.labelMedium
?.copyWith(color: Theme.of(context).colorScheme.onSurfaceVariant),
),
],
);
}