From d11b519991027c4b12fc52a8c2c6326b29824ecd Mon Sep 17 00:00:00 2001 From: Greg Price Date: Thu, 30 Jan 2025 14:56:21 -0800 Subject: [PATCH] page [nfc]: Add interface to get account ID for most of our routes --- lib/widgets/home.dart | 2 +- lib/widgets/message_list.dart | 2 +- lib/widgets/page.dart | 10 +++++++++- lib/widgets/profile.dart | 2 +- test/widgets/page_checks.dart | 2 +- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/widgets/home.dart b/lib/widgets/home.dart index ad70b57c32b..d7b15850223 100644 --- a/lib/widgets/home.dart +++ b/lib/widgets/home.dart @@ -31,7 +31,7 @@ enum _HomePageTab { class HomePage extends StatefulWidget { const HomePage({super.key}); - static Route buildRoute({required int accountId}) { + static AccountRoute buildRoute({required int accountId}) { return MaterialAccountWidgetRoute(accountId: accountId, loadingPlaceholderPage: _LoadingPlaceholderPage(accountId: accountId), page: const HomePage()); diff --git a/lib/widgets/message_list.dart b/lib/widgets/message_list.dart index a27a8051e92..d3bed0a77d5 100644 --- a/lib/widgets/message_list.dart +++ b/lib/widgets/message_list.dart @@ -188,7 +188,7 @@ abstract class MessageListPageState { class MessageListPage extends StatefulWidget { const MessageListPage({super.key, required this.initNarrow}); - static Route buildRoute({int? accountId, BuildContext? context, + static AccountRoute buildRoute({int? accountId, BuildContext? context, required Narrow narrow}) { return MaterialAccountWidgetRoute(accountId: accountId, context: context, page: MessageListPage(initNarrow: narrow)); diff --git a/lib/widgets/page.dart b/lib/widgets/page.dart index bebb37c22c0..6df14ffcf8b 100644 --- a/lib/widgets/page.dart +++ b/lib/widgets/page.dart @@ -11,6 +11,12 @@ abstract class WidgetRoute extends PageRoute { Widget get page; } +/// A page route that specifies a particular Zulip account to use, by ID. +abstract class AccountRoute extends PageRoute { + /// The [Account.id] of the account to use for this page. + int get accountId; +} + /// A [MaterialPageRoute] that always builds the same widget. /// /// This is useful for making the route more transparent for a test to inspect. @@ -32,8 +38,10 @@ class MaterialWidgetRoute extends MaterialPageRoute implem } /// A mixin for providing a given account's per-account store on a page route. -mixin AccountPageRouteMixin on PageRoute { +mixin AccountPageRouteMixin on PageRoute implements AccountRoute { + @override int get accountId; + Widget? get loadingPlaceholderPage; @override diff --git a/lib/widgets/profile.dart b/lib/widgets/profile.dart index c4f8970ff04..327910f6c09 100644 --- a/lib/widgets/profile.dart +++ b/lib/widgets/profile.dart @@ -30,7 +30,7 @@ class ProfilePage extends StatelessWidget { final int userId; - static Route buildRoute({int? accountId, BuildContext? context, + static AccountRoute buildRoute({int? accountId, BuildContext? context, required int userId}) { return MaterialAccountWidgetRoute(accountId: accountId, context: context, page: ProfilePage(userId: userId)); diff --git a/test/widgets/page_checks.dart b/test/widgets/page_checks.dart index 412a59fc490..a3692273bfc 100644 --- a/test/widgets/page_checks.dart +++ b/test/widgets/page_checks.dart @@ -6,6 +6,6 @@ extension WidgetRouteChecks on Subject> { Subject get page => has((x) => x.page, 'page'); } -extension AccountPageRouteMixinChecks on Subject> { +extension AccountRouteChecks on Subject> { Subject get accountId => has((x) => x.accountId, 'accountId'); }