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(
|
MaterialPageRoute(
|
||||||
builder: (_) => NotificationsPage(
|
builder: (_) => NotificationsPage(
|
||||||
highlightedEventId: eventId,
|
highlightedEventId: eventId,
|
||||||
jumpToEvent: (eventId) {},
|
|
||||||
defaultToAllNotifications: true,
|
defaultToAllNotifications: true,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
@ -63,7 +62,6 @@ class NotificationController
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (_) => NotificationsPage(
|
builder: (_) => NotificationsPage(
|
||||||
highlightedEventId: eventId,
|
highlightedEventId: eventId,
|
||||||
jumpToEvent: (eventId) {},
|
|
||||||
defaultToAllNotifications: true,
|
defaultToAllNotifications: true,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import "package:flutter_hooks/flutter_hooks.dart";
|
|
||||||
import "package:material_ui/material_ui.dart";
|
import "package:material_ui/material_ui.dart";
|
||||||
import "package:hooks_riverpod/hooks_riverpod.dart";
|
import "package:hooks_riverpod/hooks_riverpod.dart";
|
||||||
import "package:nexus/controllers/init_complete.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/controllers/key.dart";
|
||||||
import "package:nexus/widgets/appbar.dart";
|
import "package:nexus/widgets/appbar.dart";
|
||||||
import "package:nexus/widgets/sidebar.dart";
|
import "package:nexus/widgets/sidebar.dart";
|
||||||
|
|
@ -10,10 +10,7 @@ import "package:nexus/widgets/loading.dart";
|
||||||
|
|
||||||
class const ChatPage({super.key}) extends HookConsumerWidget {
|
class const ChatPage({super.key}) extends HookConsumerWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) => LayoutBuilder(
|
||||||
final initialHighlightedEvent = useState<String?>(null);
|
|
||||||
|
|
||||||
return LayoutBuilder(
|
|
||||||
builder: (context, constraints) {
|
builder: (context, constraints) {
|
||||||
final isDesktop = constraints.maxWidth > 650;
|
final isDesktop = constraints.maxWidth > 650;
|
||||||
final showMembersByDefault = constraints.maxWidth > 1000;
|
final showMembersByDefault = constraints.maxWidth > 1000;
|
||||||
|
|
@ -28,23 +25,21 @@ class const ChatPage({super.key}) extends HookConsumerWidget {
|
||||||
body: initComplete
|
body: initComplete
|
||||||
? Row(
|
? Row(
|
||||||
children: [
|
children: [
|
||||||
if (isDesktop)
|
if (isDesktop) Sidebar(isDesktop: isDesktop),
|
||||||
Sidebar(
|
|
||||||
isDesktop: isDesktop,
|
|
||||||
jumpToEvent: (eventId) =>
|
|
||||||
initialHighlightedEvent.value = eventId,
|
|
||||||
),
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: RoomChat(
|
child: Consumer(
|
||||||
key: ValueKey((
|
builder: (context, ref, _) {
|
||||||
roomId,
|
final initialHighlight = ref.watch(
|
||||||
initialHighlightedEvent.value,
|
JumpToEventController.provider,
|
||||||
)),
|
);
|
||||||
|
return RoomChat(
|
||||||
|
key: ValueKey((roomId, initialHighlight)),
|
||||||
roomId: roomId,
|
roomId: roomId,
|
||||||
isDesktop: isDesktop,
|
isDesktop: isDesktop,
|
||||||
|
initialHighlightedEvent: initialHighlight,
|
||||||
showMembersByDefault: showMembersByDefault,
|
showMembersByDefault: showMembersByDefault,
|
||||||
initialHighlightedEvent:
|
);
|
||||||
initialHighlightedEvent.value,
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
@ -57,14 +52,9 @@ class const ChatPage({super.key}) extends HookConsumerWidget {
|
||||||
),
|
),
|
||||||
drawer: isDesktop || !initComplete
|
drawer: isDesktop || !initComplete
|
||||||
? null
|
? null
|
||||||
: Sidebar(
|
: Sidebar(isDesktop: isDesktop),
|
||||||
isDesktop: isDesktop,
|
|
||||||
jumpToEvent: (eventId) =>
|
|
||||||
initialHighlightedEvent.value = eventId,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import "package:m3e_buttons/m3e_buttons.dart";
|
||||||
import "package:material_ui/material_ui.dart";
|
import "package:material_ui/material_ui.dart";
|
||||||
import "package:flutter_hooks/flutter_hooks.dart";
|
import "package:flutter_hooks/flutter_hooks.dart";
|
||||||
import "package:hooks_riverpod/hooks_riverpod.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/key.dart";
|
||||||
import "package:nexus/controllers/notifications.dart";
|
import "package:nexus/controllers/notifications.dart";
|
||||||
import "package:nexus/controllers/spaces.dart";
|
import "package:nexus/controllers/spaces.dart";
|
||||||
|
|
@ -19,7 +20,6 @@ import "package:super_sliver_list/super_sliver_list.dart";
|
||||||
class const NotificationsPage({
|
class const NotificationsPage({
|
||||||
final String? highlightedEventId,
|
final String? highlightedEventId,
|
||||||
final bool defaultToAllNotifications = false,
|
final bool defaultToAllNotifications = false,
|
||||||
required final void Function(String eventId) jumpToEvent,
|
|
||||||
super.key,
|
super.key,
|
||||||
}) extends HookConsumerWidget {
|
}) extends HookConsumerWidget {
|
||||||
@override
|
@override
|
||||||
|
|
@ -166,7 +166,13 @@ class const NotificationsPage({
|
||||||
).notifier,
|
).notifier,
|
||||||
)
|
)
|
||||||
.set(event.roomId);
|
.set(event.roomId);
|
||||||
jumpToEvent(event.eventId);
|
ref
|
||||||
|
.read(
|
||||||
|
JumpToEventController
|
||||||
|
.provider
|
||||||
|
.notifier,
|
||||||
|
)
|
||||||
|
.set(event.eventId);
|
||||||
|
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,8 @@ import "package:nexus/widgets/room_menu.dart";
|
||||||
// Needed for navigation_rail_m3e (#65).
|
// Needed for navigation_rail_m3e (#65).
|
||||||
import "package:flutter/material.dart" as old_mat;
|
import "package:flutter/material.dart" as old_mat;
|
||||||
|
|
||||||
class const Sidebar({
|
class const Sidebar({required final bool isDesktop, super.key})
|
||||||
required final bool isDesktop,
|
extends HookConsumerWidget {
|
||||||
required final void Function(String eventId) jumpToEvent,
|
|
||||||
super.key,
|
|
||||||
}) extends HookConsumerWidget {
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final selectedSpaceProvider = KeyController.provider(
|
final selectedSpaceProvider = KeyController.provider(
|
||||||
|
|
@ -197,8 +194,7 @@ class const Sidebar({
|
||||||
tooltip: "Open notifications",
|
tooltip: "Open notifications",
|
||||||
onPressed: () => Navigator.of(context).push(
|
onPressed: () => Navigator.of(context).push(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (_) =>
|
builder: (_) => NotificationsPage(),
|
||||||
NotificationsPage(jumpToEvent: jumpToEvent),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
icon: Icon(Icons.notifications),
|
icon: Icon(Icons.notifications),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue