Skip to content

Commit

Permalink
page [nfc]: Add interface to get account ID for most of our routes
Browse files Browse the repository at this point in the history
  • Loading branch information
gnprice authored and rajveermalviya committed Feb 7, 2025
1 parent e263d1d commit d11b519
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/widgets/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ enum _HomePageTab {
class HomePage extends StatefulWidget {
const HomePage({super.key});

static Route<void> buildRoute({required int accountId}) {
static AccountRoute<void> buildRoute({required int accountId}) {
return MaterialAccountWidgetRoute(accountId: accountId,
loadingPlaceholderPage: _LoadingPlaceholderPage(accountId: accountId),
page: const HomePage());
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/message_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ abstract class MessageListPageState {
class MessageListPage extends StatefulWidget {
const MessageListPage({super.key, required this.initNarrow});

static Route<void> buildRoute({int? accountId, BuildContext? context,
static AccountRoute<void> buildRoute({int? accountId, BuildContext? context,
required Narrow narrow}) {
return MaterialAccountWidgetRoute(accountId: accountId, context: context,
page: MessageListPage(initNarrow: narrow));
Expand Down
10 changes: 9 additions & 1 deletion lib/widgets/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ abstract class WidgetRoute<T extends Object?> extends PageRoute<T> {
Widget get page;
}

/// A page route that specifies a particular Zulip account to use, by ID.
abstract class AccountRoute<T extends Object?> extends PageRoute<T> {
/// 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.
Expand All @@ -32,8 +38,10 @@ class MaterialWidgetRoute<T extends Object?> extends MaterialPageRoute<T> implem
}

/// A mixin for providing a given account's per-account store on a page route.
mixin AccountPageRouteMixin<T extends Object?> on PageRoute<T> {
mixin AccountPageRouteMixin<T extends Object?> on PageRoute<T> implements AccountRoute<T> {
@override
int get accountId;

Widget? get loadingPlaceholderPage;

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ProfilePage extends StatelessWidget {

final int userId;

static Route<void> buildRoute({int? accountId, BuildContext? context,
static AccountRoute<void> buildRoute({int? accountId, BuildContext? context,
required int userId}) {
return MaterialAccountWidgetRoute(accountId: accountId, context: context,
page: ProfilePage(userId: userId));
Expand Down
2 changes: 1 addition & 1 deletion test/widgets/page_checks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ extension WidgetRouteChecks<T> on Subject<WidgetRoute<T>> {
Subject<Widget> get page => has((x) => x.page, 'page');
}

extension AccountPageRouteMixinChecks<T> on Subject<AccountPageRouteMixin<T>> {
extension AccountRouteChecks<T> on Subject<AccountRoute<T>> {
Subject<int> get accountId => has((x) => x.accountId, 'accountId');
}

0 comments on commit d11b519

Please sign in to comment.