Skip to content

Commit 8ba5c37

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

11 files changed

+128
-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

+79
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,84 @@ 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 SizedBox(
359+
width: 28,
360+
height: 28,
361+
child: Placeholder(),
362+
);
363+
},
364+
loadingBuilder: (context, child, loadingProgress) {
365+
if (loadingProgress == null) return child;
366+
return const SizedBox(
367+
width: 28,
368+
height: 28,
369+
child: CircularProgressIndicator(),
370+
);
371+
},
372+
),
373+
const SizedBox(width: 8),
374+
Expanded(
375+
child: Text(
376+
organizationName,
377+
style: const TextStyle(
378+
fontWeight: FontWeight.bold,
379+
fontSize: 20,
380+
),
381+
overflow: TextOverflow.ellipsis,
382+
maxLines: 1,
383+
),
384+
),
385+
],
386+
),
387+
),
388+
TextButton(
389+
onPressed: () {
390+
Navigator.of(context).push(MaterialWidgetRoute(page: const ChooseAccountPage()));
391+
},
392+
style: buttonStyle,
393+
child: Text(
394+
zulipLocalizations.organizationsButtonLabel,
395+
style: TextStyle(
396+
fontSize: 19,
397+
fontWeight: FontWeight.w500,
398+
color: designVariables.icon,
399+
),
400+
),
401+
),
402+
],
403+
),
404+
);
405+
}
406+
}
407+
329408
abstract class _MenuButton extends StatelessWidget {
330409
const _MenuButton();
331410

test/widgets/home_test.dart

+18
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,24 @@ 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+
});
268+
251269
testWidgets('_MyProfileButton', (tester) async {
252270
await prepare(tester);
253271
await tapOpenMenu(tester);

0 commit comments

Comments
 (0)