Skip to content

Commit

Permalink
home: Display current organization's name and icon atop menu
Browse files Browse the repository at this point in the history
  • Loading branch information
chimnayajith committed Jan 31, 2025
1 parent aed085b commit 76c1e8a
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 0 deletions.
4 changes: 4 additions & 0 deletions assets/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
"@switchAccountButton": {
"description": "Label for main-menu button leading to the choose-account page."
},
"organizationsButtonLabel": "Organizations",
"@organizationsButtonLabel": {
"description": "Button text to view and switch between different organizations."
},
"tryAnotherAccountMessage": "Your account at {url} is taking a while to load.",
"@tryAnotherAccountMessage": {
"description": "Message that appears on the loading screen after waiting for some time.",
Expand Down
6 changes: 6 additions & 0 deletions lib/generated/l10n/zulip_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ abstract class ZulipLocalizations {
/// **'Switch account'**
String get switchAccountButton;

/// Button text to view and switch between different organizations.
///
/// In en, this message translates to:
/// **'Organizations'**
String get organizationsButtonLabel;

/// Message that appears on the loading screen after waiting for some time.
///
/// In en, this message translates to:
Expand Down
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_ar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class ZulipLocalizationsAr extends ZulipLocalizations {
@override
String get switchAccountButton => 'Switch account';

@override
String get organizationsButtonLabel => 'Organizations';

@override
String tryAnotherAccountMessage(Object url) {
return 'Your account at $url is taking a while to load.';
Expand Down
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class ZulipLocalizationsEn extends ZulipLocalizations {
@override
String get switchAccountButton => 'Switch account';

@override
String get organizationsButtonLabel => 'Organizations';

@override
String tryAnotherAccountMessage(Object url) {
return 'Your account at $url is taking a while to load.';
Expand Down
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_ja.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class ZulipLocalizationsJa extends ZulipLocalizations {
@override
String get switchAccountButton => 'Switch account';

@override
String get organizationsButtonLabel => 'Organizations';

@override
String tryAnotherAccountMessage(Object url) {
return 'Your account at $url is taking a while to load.';
Expand Down
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_nb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class ZulipLocalizationsNb extends ZulipLocalizations {
@override
String get switchAccountButton => 'Switch account';

@override
String get organizationsButtonLabel => 'Organizations';

@override
String tryAnotherAccountMessage(Object url) {
return 'Your account at $url is taking a while to load.';
Expand Down
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_pl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class ZulipLocalizationsPl extends ZulipLocalizations {
@override
String get switchAccountButton => 'Przełącz konto';

@override
String get organizationsButtonLabel => 'Organizations';

@override
String tryAnotherAccountMessage(Object url) {
return 'Twoje konto na $url wymaga jeszcze chwili na załadowanie.';
Expand Down
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_ru.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class ZulipLocalizationsRu extends ZulipLocalizations {
@override
String get switchAccountButton => 'Сменить учетную запись';

@override
String get organizationsButtonLabel => 'Organizations';

@override
String tryAnotherAccountMessage(Object url) {
return 'Ваша учетная запись на $url загружается медленно.';
Expand Down
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_sk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class ZulipLocalizationsSk extends ZulipLocalizations {
@override
String get switchAccountButton => 'Zmeniť účet';

@override
String get organizationsButtonLabel => 'Organizations';

@override
String tryAnotherAccountMessage(Object url) {
return 'Načítavanie vášho konta na adrese $url chvílu trvá.';
Expand Down
67 changes: 67 additions & 0 deletions lib/widgets/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ void _showMainMenu(BuildContext context, {
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: [
_OrganizationHeader(),
Flexible(child: InsetShadowBox(
top: 8, bottom: 8,
color: designVariables.bgBotBar,
Expand All @@ -326,6 +327,72 @@ void _showMainMenu(BuildContext context, {
});
}

class _OrganizationHeader extends StatelessWidget {
@override
Widget build(BuildContext context) {
final store = PerAccountStoreWidget.of(context);
final designVariables = DesignVariables.of(context);
final zulipLocalizations = ZulipLocalizations.of(context);

String organizationName = store.realmName;
Uri? organizationIcon = store.tryResolveUrl(store.realmIcon);
final buttonStyle = TextButton.styleFrom(
splashFactory: NoSplash.splashFactory,
overlayColor: Colors.transparent
);

return Padding(
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Row(
children: [
Image.network(
organizationIcon.toString(),
width: 28,
height: 28,
fit: BoxFit.contain,
errorBuilder: (context, error, stackTrace) {
return const Icon(Icons.broken_image, size: 28);
},
),
const SizedBox(width: 8),
Expanded(
child: Text(
organizationName,
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
),
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
),
],
),
),
TextButton(
onPressed: () {
Navigator.of(context).push(MaterialWidgetRoute(page: const ChooseAccountPage()));
},
style: buttonStyle,
child: Text(
zulipLocalizations.organizationsButtonLabel,
style: TextStyle(
fontSize: 19,
fontWeight: FontWeight.w500,
color: designVariables.icon,
),
),
),
],
),
);
}
}

abstract class _MenuButton extends StatelessWidget {
const _MenuButton();

Expand Down
17 changes: 17 additions & 0 deletions test/widgets/home_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,23 @@ void main () {
check(find.byType(BottomSheet)).findsNothing();
});

testWidgets('organization header shows realm info and navigation works', (tester) async {
await prepare(tester);
final store = await testBinding.globalStore.perAccount(eg.selfAccount.id);
await tapOpenMenu(tester);

check(find.text(store.realmName)).findsOne();
check(find.byType(Image)).findsOne();

final organizationsButton = find.text('Organizations');
check(organizationsButton).findsOne();

await tester.tap(organizationsButton);
await tester.pump(Duration.zero);
await tester.pump(const Duration(milliseconds: 250)); // wait for animation

check(find.byType(ChooseAccountPage)).findsOne();
});
testWidgets('_MyProfileButton', (tester) async {
await prepare(tester);
await tapOpenMenu(tester);
Expand Down

0 comments on commit 76c1e8a

Please sign in to comment.