add JumpToEventController to allow jumping to events from the NotificationsPage when it has been pushed from the NotificationController
This commit is contained in:
parent
c90a1c41b0
commit
1c1f585362
5 changed files with 70 additions and 65 deletions
15
lib/controllers/jump_to_event.dart
Normal file
15
lib/controllers/jump_to_event.dart
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
|
||||
class JumpToEventController extends Notifier<String?> {
|
||||
@override
|
||||
String? build() => null;
|
||||
|
||||
void set(String? eventId) => state = eventId;
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(_, _) => true;
|
||||
|
||||
static final provider = NotifierProvider<JumpToEventController, String?>(
|
||||
JumpToEventController.new,
|
||||
);
|
||||
}
|
||||
|
|
@ -37,7 +37,6 @@ class NotificationController
|
|||
MaterialPageRoute(
|
||||
builder: (_) => NotificationsPage(
|
||||
highlightedEventId: eventId,
|
||||
jumpToEvent: (eventId) {},
|
||||
defaultToAllNotifications: true,
|
||||
),
|
||||
),
|
||||
|
|
@ -63,7 +62,6 @@ class NotificationController
|
|||
MaterialPageRoute(
|
||||
builder: (_) => NotificationsPage(
|
||||
highlightedEventId: eventId,
|
||||
jumpToEvent: (eventId) {},
|
||||
defaultToAllNotifications: true,
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import "package:flutter_hooks/flutter_hooks.dart";
|
||||
import "package:material_ui/material_ui.dart";
|
||||
import "package:hooks_riverpod/hooks_riverpod.dart";
|
||||
import "package:nexus/controllers/init_complete.dart";
|
||||
import "package:nexus/controllers/jump_to_event.dart";
|
||||
import "package:nexus/controllers/key.dart";
|
||||
import "package:nexus/widgets/appbar.dart";
|
||||
import "package:nexus/widgets/sidebar.dart";
|
||||
|
|
@ -10,61 +10,51 @@ import "package:nexus/widgets/loading.dart";
|
|||
|
||||
class const ChatPage({super.key}) extends HookConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final initialHighlightedEvent = useState<String?>(null);
|
||||
Widget build(BuildContext context, WidgetRef ref) => LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final isDesktop = constraints.maxWidth > 650;
|
||||
final showMembersByDefault = constraints.maxWidth > 1000;
|
||||
final initComplete = ref.watch(InitCompleteController.provider);
|
||||
final roomId = ref
|
||||
.watch(KeyController.provider(KeyController.roomKey))
|
||||
.requireValue;
|
||||
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final isDesktop = constraints.maxWidth > 650;
|
||||
final showMembersByDefault = constraints.maxWidth > 1000;
|
||||
final initComplete = ref.watch(InitCompleteController.provider);
|
||||
final roomId = ref
|
||||
.watch(KeyController.provider(KeyController.roomKey))
|
||||
.requireValue;
|
||||
|
||||
return SafeArea(
|
||||
child: Scaffold(
|
||||
appBar: initComplete ? null : Appbar(),
|
||||
body: initComplete
|
||||
? Row(
|
||||
children: [
|
||||
if (isDesktop)
|
||||
Sidebar(
|
||||
isDesktop: isDesktop,
|
||||
jumpToEvent: (eventId) =>
|
||||
initialHighlightedEvent.value = eventId,
|
||||
),
|
||||
Expanded(
|
||||
child: RoomChat(
|
||||
key: ValueKey((
|
||||
roomId,
|
||||
initialHighlightedEvent.value,
|
||||
)),
|
||||
roomId: roomId,
|
||||
isDesktop: isDesktop,
|
||||
showMembersByDefault: showMembersByDefault,
|
||||
initialHighlightedEvent:
|
||||
initialHighlightedEvent.value,
|
||||
),
|
||||
return SafeArea(
|
||||
child: Scaffold(
|
||||
appBar: initComplete ? null : Appbar(),
|
||||
body: initComplete
|
||||
? Row(
|
||||
children: [
|
||||
if (isDesktop) Sidebar(isDesktop: isDesktop),
|
||||
Expanded(
|
||||
child: Consumer(
|
||||
builder: (context, ref, _) {
|
||||
final initialHighlight = ref.watch(
|
||||
JumpToEventController.provider,
|
||||
);
|
||||
return RoomChat(
|
||||
key: ValueKey((roomId, initialHighlight)),
|
||||
roomId: roomId,
|
||||
isDesktop: isDesktop,
|
||||
initialHighlightedEvent: initialHighlight,
|
||||
showMembersByDefault: showMembersByDefault,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
)
|
||||
: Center(
|
||||
child: Column(
|
||||
mainAxisSize: .min,
|
||||
children: [Loading(), Text("Syncing...")],
|
||||
),
|
||||
],
|
||||
)
|
||||
: Center(
|
||||
child: Column(
|
||||
mainAxisSize: .min,
|
||||
children: [Loading(), Text("Syncing...")],
|
||||
),
|
||||
drawer: isDesktop || !initComplete
|
||||
? null
|
||||
: Sidebar(
|
||||
isDesktop: isDesktop,
|
||||
jumpToEvent: (eventId) =>
|
||||
initialHighlightedEvent.value = eventId,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
),
|
||||
drawer: isDesktop || !initComplete
|
||||
? null
|
||||
: Sidebar(isDesktop: isDesktop),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import "package:m3e_buttons/m3e_buttons.dart";
|
|||
import "package:material_ui/material_ui.dart";
|
||||
import "package:flutter_hooks/flutter_hooks.dart";
|
||||
import "package:hooks_riverpod/hooks_riverpod.dart";
|
||||
import "package:nexus/controllers/jump_to_event.dart";
|
||||
import "package:nexus/controllers/key.dart";
|
||||
import "package:nexus/controllers/notifications.dart";
|
||||
import "package:nexus/controllers/spaces.dart";
|
||||
|
|
@ -19,7 +20,6 @@ import "package:super_sliver_list/super_sliver_list.dart";
|
|||
class const NotificationsPage({
|
||||
final String? highlightedEventId,
|
||||
final bool defaultToAllNotifications = false,
|
||||
required final void Function(String eventId) jumpToEvent,
|
||||
super.key,
|
||||
}) extends HookConsumerWidget {
|
||||
@override
|
||||
|
|
@ -166,7 +166,13 @@ class const NotificationsPage({
|
|||
).notifier,
|
||||
)
|
||||
.set(event.roomId);
|
||||
jumpToEvent(event.eventId);
|
||||
ref
|
||||
.read(
|
||||
JumpToEventController
|
||||
.provider
|
||||
.notifier,
|
||||
)
|
||||
.set(event.eventId);
|
||||
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
|
|
|
|||
|
|
@ -16,11 +16,8 @@ import "package:nexus/widgets/room_menu.dart";
|
|||
// Needed for navigation_rail_m3e (#65).
|
||||
import "package:flutter/material.dart" as old_mat;
|
||||
|
||||
class const Sidebar({
|
||||
required final bool isDesktop,
|
||||
required final void Function(String eventId) jumpToEvent,
|
||||
super.key,
|
||||
}) extends HookConsumerWidget {
|
||||
class const Sidebar({required final bool isDesktop, super.key})
|
||||
extends HookConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final selectedSpaceProvider = KeyController.provider(
|
||||
|
|
@ -197,8 +194,7 @@ class const Sidebar({
|
|||
tooltip: "Open notifications",
|
||||
onPressed: () => Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) =>
|
||||
NotificationsPage(jumpToEvent: jumpToEvent),
|
||||
builder: (_) => NotificationsPage(),
|
||||
),
|
||||
),
|
||||
icon: Icon(Icons.notifications),
|
||||
|
|
|
|||
Loading…
Reference in a new issue