Skip to content

Commit a130711

Browse files
author
chimnayajith
committed
home: Display current organization's name and icon atop menu
Fixes #1037
1 parent bbcc4c9 commit a130711

11 files changed

+115
-0
lines changed

assets/l10n/app_en.arb

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
"@switchAccountButton": {
2424
"description": "Label for main-menu button leading to the choose-account page."
2525
},
26+
"organizationsButtonLabel": "Organizations",
27+
"@organizationsButtonLabel": {
28+
"description": "Button text to view and switch between different organizations."
29+
},
2630
"tryAnotherAccountMessage": "Your account at {url} is taking a while to load.",
2731
"@tryAnotherAccountMessage": {
2832
"description": "Message that appears on the loading screen after waiting for some time.",

lib/generated/l10n/zulip_localizations.dart

+6
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ abstract class ZulipLocalizations {
141141
/// **'Switch account'**
142142
String get switchAccountButton;
143143

144+
/// Button text to view and switch between different organizations.
145+
///
146+
/// In en, this message translates to:
147+
/// **'Organizations'**
148+
String get organizationsButtonLabel;
149+
144150
/// Message that appears on the loading screen after waiting for some time.
145151
///
146152
/// In en, this message translates to:

lib/generated/l10n/zulip_localizations_ar.dart

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class ZulipLocalizationsAr extends ZulipLocalizations {
2626
@override
2727
String get switchAccountButton => 'Switch account';
2828

29+
@override
30+
String get organizationsButtonLabel => 'Organizations';
31+
2932
@override
3033
String tryAnotherAccountMessage(Object url) {
3134
return 'Your account at $url is taking a while to load.';

lib/generated/l10n/zulip_localizations_en.dart

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class ZulipLocalizationsEn extends ZulipLocalizations {
2626
@override
2727
String get switchAccountButton => 'Switch account';
2828

29+
@override
30+
String get organizationsButtonLabel => 'Organizations';
31+
2932
@override
3033
String tryAnotherAccountMessage(Object url) {
3134
return 'Your account at $url is taking a while to load.';

lib/generated/l10n/zulip_localizations_ja.dart

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class ZulipLocalizationsJa extends ZulipLocalizations {
2626
@override
2727
String get switchAccountButton => 'Switch account';
2828

29+
@override
30+
String get organizationsButtonLabel => 'Organizations';
31+
2932
@override
3033
String tryAnotherAccountMessage(Object url) {
3134
return 'Your account at $url is taking a while to load.';

lib/generated/l10n/zulip_localizations_nb.dart

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class ZulipLocalizationsNb extends ZulipLocalizations {
2626
@override
2727
String get switchAccountButton => 'Switch account';
2828

29+
@override
30+
String get organizationsButtonLabel => 'Organizations';
31+
2932
@override
3033
String tryAnotherAccountMessage(Object url) {
3134
return 'Your account at $url is taking a while to load.';

lib/generated/l10n/zulip_localizations_pl.dart

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class ZulipLocalizationsPl extends ZulipLocalizations {
2626
@override
2727
String get switchAccountButton => 'Przełącz konto';
2828

29+
@override
30+
String get organizationsButtonLabel => 'Organizations';
31+
2932
@override
3033
String tryAnotherAccountMessage(Object url) {
3134
return 'Twoje konto na $url wymaga jeszcze chwili na załadowanie.';

lib/generated/l10n/zulip_localizations_ru.dart

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class ZulipLocalizationsRu extends ZulipLocalizations {
2626
@override
2727
String get switchAccountButton => 'Сменить учетную запись';
2828

29+
@override
30+
String get organizationsButtonLabel => 'Organizations';
31+
2932
@override
3033
String tryAnotherAccountMessage(Object url) {
3134
return 'Ваша учетная запись на $url загружается медленно.';

lib/generated/l10n/zulip_localizations_sk.dart

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class ZulipLocalizationsSk extends ZulipLocalizations {
2626
@override
2727
String get switchAccountButton => 'Zmeniť účet';
2828

29+
@override
30+
String get organizationsButtonLabel => 'Organizations';
31+
2932
@override
3033
String tryAnotherAccountMessage(Object url) {
3134
return 'Načítavanie vášho konta na adrese $url chvílu trvá.';

lib/widgets/home.dart

+67
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ void _showMainMenu(BuildContext context, {
310310
crossAxisAlignment: CrossAxisAlignment.stretch,
311311
mainAxisSize: MainAxisSize.min,
312312
children: [
313+
_OrganizationHeader(),
313314
Flexible(child: InsetShadowBox(
314315
top: 8, bottom: 8,
315316
color: designVariables.bgBotBar,
@@ -326,6 +327,72 @@ void _showMainMenu(BuildContext context, {
326327
});
327328
}
328329

330+
class _OrganizationHeader extends StatelessWidget {
331+
@override
332+
Widget build(BuildContext context) {
333+
final store = PerAccountStoreWidget.of(context);
334+
final designVariables = DesignVariables.of(context);
335+
final zulipLocalizations = ZulipLocalizations.of(context);
336+
337+
String organizationName = store.realmName;
338+
Uri? organizationIcon = store.tryResolveUrl(store.realmIcon);
339+
final buttonStyle = TextButton.styleFrom(
340+
splashFactory: NoSplash.splashFactory,
341+
overlayColor: Colors.transparent
342+
);
343+
344+
return Padding(
345+
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
346+
child: Row(
347+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
348+
children: [
349+
Expanded(
350+
child: Row(
351+
children: [
352+
Image.network(
353+
organizationIcon.toString(),
354+
width: 28,
355+
height: 28,
356+
fit: BoxFit.contain,
357+
errorBuilder: (context, error, stackTrace) {
358+
return const Icon(Icons.broken_image, size: 28);
359+
},
360+
),
361+
const SizedBox(width: 8),
362+
Expanded(
363+
child: Text(
364+
organizationName,
365+
style: const TextStyle(
366+
fontWeight: FontWeight.bold,
367+
fontSize: 20,
368+
),
369+
overflow: TextOverflow.ellipsis,
370+
maxLines: 1,
371+
),
372+
),
373+
],
374+
),
375+
),
376+
TextButton(
377+
onPressed: () {
378+
Navigator.of(context).push(MaterialWidgetRoute(page: const ChooseAccountPage()));
379+
},
380+
style: buttonStyle,
381+
child: Text(
382+
zulipLocalizations.organizationsButtonLabel,
383+
style: TextStyle(
384+
fontSize: 19,
385+
fontWeight: FontWeight.w500,
386+
color: designVariables.icon,
387+
),
388+
),
389+
),
390+
],
391+
),
392+
);
393+
}
394+
}
395+
329396
abstract class _MenuButton extends StatelessWidget {
330397
const _MenuButton();
331398

test/widgets/home_test.dart

+17
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,23 @@ void main () {
248248
check(find.byType(BottomSheet)).findsNothing();
249249
});
250250

251+
testWidgets('organization header shows realm info and navigation works', (tester) async {
252+
await prepare(tester);
253+
final store = await testBinding.globalStore.perAccount(eg.selfAccount.id);
254+
await tapOpenMenu(tester);
255+
256+
check(find.text(store.realmName)).findsOne();
257+
check(find.byType(Image)).findsOne();
258+
259+
final organizationsButton = find.text('Organizations');
260+
check(organizationsButton).findsOne();
261+
262+
await tester.tap(organizationsButton);
263+
await tester.pump(Duration.zero);
264+
await tester.pump(const Duration(milliseconds: 250)); // wait for animation
265+
266+
check(find.byType(ChooseAccountPage)).findsOne();
267+
});
251268
testWidgets('_MyProfileButton', (tester) async {
252269
await prepare(tester);
253270
await tapOpenMenu(tester);

0 commit comments

Comments
 (0)