From bab5ec63a886398ffe4059550cf1acc2d0037603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 14 Mar 2018 11:29:22 +0100 Subject: [PATCH] MOBILE-2349 mainmenu: Update badges without event triggering --- .../components/discussions/discussions.html | 4 +- .../messages/providers/mainmenu-handler.ts | 37 ++++++++----------- src/app/app.scss | 4 +- src/core/mainmenu/pages/menu/menu.ts | 11 ------ src/core/mainmenu/pages/more/more.ts | 11 ------ src/core/mainmenu/providers/delegate.ts | 2 - 6 files changed, 21 insertions(+), 48 deletions(-) diff --git a/src/addon/messages/components/discussions/discussions.html b/src/addon/messages/components/discussions/discussions.html index 2e7f4f993..cade6e7c3 100644 --- a/src/addon/messages/components/discussions/discussions.html +++ b/src/addon/messages/components/discussions/discussions.html @@ -33,8 +33,8 @@

-
{{discussion.message.timecreated / 1000 | coreDateDayOrTime}}
-
+ + {{discussion.message.timecreated / 1000 | coreDateDayOrTime}}

diff --git a/src/addon/messages/providers/mainmenu-handler.ts b/src/addon/messages/providers/mainmenu-handler.ts index f49660b56..8afb58d63 100644 --- a/src/addon/messages/providers/mainmenu-handler.ts +++ b/src/addon/messages/providers/mainmenu-handler.ts @@ -32,8 +32,15 @@ import { AddonPushNotificationsDelegate } from '@addon/pushnotifications/provide export class AddonMessagesMainMenuHandler implements CoreMainMenuHandler, CoreCronHandler { name = 'AddonMessages'; priority = 800; - protected badge = ''; - protected loading = true; + protected handler: CoreMainMenuHandlerToDisplay = { + icon: 'chatbubbles', + title: 'addon.messages.messages', + page: 'AddonMessagesIndexPage', + class: 'addon-messages-handler', + showBadge: true, // Do not check isMessageCountEnabled because we'll use fallback it not enabled. + badge: '', + loading: true + }; constructor(private messagesProvider: AddonMessagesProvider, private sitesProvider: CoreSitesProvider, private eventsProvider: CoreEventsProvider, private appProvider: CoreAppProvider, @@ -51,8 +58,8 @@ export class AddonMessagesMainMenuHandler implements CoreMainMenuHandler, CoreCr // Reset info on logout. eventsProvider.on(CoreEventsProvider.LOGOUT, (data) => { - this.badge = ''; - this.loading = true; + this.handler.badge = ''; + this.handler.loading = true; }); // If a message push notification is received, refresh the count. @@ -82,19 +89,11 @@ export class AddonMessagesMainMenuHandler implements CoreMainMenuHandler, CoreCr * @return {CoreMainMenuHandlerToDisplay} Data needed to render the handler. */ getDisplayData(): CoreMainMenuHandlerToDisplay { - if (this.loading) { + if (this.handler.loading) { this.updateBadge(); } - return { - icon: 'chatbubbles', - title: 'addon.messages.messages', - page: 'AddonMessagesIndexPage', - class: 'addon-messages-handler', - showBadge: true, // Do not check isMessageCountEnabled because we'll use fallback it not enabled. - badge: this.badge, - loading: this.loading - }; + return this.handler; } /** @@ -110,17 +109,13 @@ export class AddonMessagesMainMenuHandler implements CoreMainMenuHandler, CoreCr this.messagesProvider.getUnreadConversationsCount(undefined, siteId).then((unread) => { // Leave badge enter if there is a 0+ or a 0. - this.badge = parseInt(unread, 10) > 0 ? unread : ''; + this.handler.badge = parseInt(unread, 10) > 0 ? unread : ''; // Update badge. this.pushNotificationsProvider.updateAddonCounter('AddonMessages', unread, siteId); }).catch(() => { - this.badge = ''; + this.handler.badge = ''; }).finally(() => { - this.loading = false; - this.eventsProvider.trigger(CoreMainMenuDelegate.UPDATE_BADGE_EVENT, { - name: this.name, - badge: this.badge - }, siteId); + this.handler.loading = false; }); } diff --git a/src/app/app.scss b/src/app/app.scss index d5fd9b7ce..84557fa0e 100644 --- a/src/app/app.scss +++ b/src/app/app.scss @@ -483,10 +483,12 @@ textarea { .core-circle:before { content: ' \25CF'; - font-size: 20px; } @each $color-name, $color-base, $color-contrast in get-colors($colors) { + .core-#{$color-name}-circle { + margin: 0 4px; + } .core-#{$color-name}-circle:before { @extend .core-circle:before; color: $color-base; diff --git a/src/core/mainmenu/pages/menu/menu.ts b/src/core/mainmenu/pages/menu/menu.ts index d909aa13a..19476a899 100644 --- a/src/core/mainmenu/pages/menu/menu.ts +++ b/src/core/mainmenu/pages/menu/menu.ts @@ -64,7 +64,6 @@ export class CoreMainMenuPage implements OnDestroy { }; protected moreTabAdded = false; protected redirectPageLoaded = false; - protected updateBadgeObserver; constructor(private menuDelegate: CoreMainMenuDelegate, private sitesProvider: CoreSitesProvider, navParams: NavParams, private navCtrl: NavController, private eventsProvider: CoreEventsProvider) { @@ -85,15 +84,6 @@ export class CoreMainMenuPage implements OnDestroy { const site = this.sitesProvider.getCurrentSite(), displaySiteHome = site.getInfo() && site.getInfo().userhomepage === 0; - this.updateBadgeObserver = this.eventsProvider.on(CoreMainMenuDelegate.UPDATE_BADGE_EVENT, (data) => { - const tab = this.tabs.find((tab) => { - return tab.showBadge && tab['name'] == data.name; - }); - if (tab) { - tab.badge = data.badge; - } - }, site.getId()); - this.subscription = this.menuDelegate.getHandlers().subscribe((handlers) => { handlers = handlers.slice(0, CoreMainMenuProvider.NUM_MAIN_HANDLERS); // Get main handlers. @@ -138,6 +128,5 @@ export class CoreMainMenuPage implements OnDestroy { */ ngOnDestroy(): void { this.subscription && this.subscription.unsubscribe(); - this.updateBadgeObserver && this.updateBadgeObserver.off(); } } diff --git a/src/core/mainmenu/pages/more/more.ts b/src/core/mainmenu/pages/more/more.ts index 0c396bfd9..8f36a3101 100644 --- a/src/core/mainmenu/pages/more/more.ts +++ b/src/core/mainmenu/pages/more/more.ts @@ -40,7 +40,6 @@ export class CoreMainMenuMorePage implements OnDestroy { protected subscription; protected langObserver; protected updateSiteObserver; - protected updateBadgeObserver; constructor(private menuDelegate: CoreMainMenuDelegate, private sitesProvider: CoreSitesProvider, private navCtrl: NavController, private mainMenuProvider: CoreMainMenuProvider, @@ -61,15 +60,6 @@ export class CoreMainMenuMorePage implements OnDestroy { this.handlers = handlers.slice(CoreMainMenuProvider.NUM_MAIN_HANDLERS); // Remove the main handlers. this.handlersLoaded = this.menuDelegate.areHandlersLoaded(); }); - - this.updateBadgeObserver = this.eventsProvider.on(CoreMainMenuDelegate.UPDATE_BADGE_EVENT, (data) => { - const handler = this.handlers.find((handler) => { - return handler.showBadge && handler['name'] == data.name; - }); - if (handler) { - handler.badge = data.badge; - } - }, this.sitesProvider.getCurrentSiteId()); } /** @@ -79,7 +69,6 @@ export class CoreMainMenuMorePage implements OnDestroy { if (this.subscription) { this.subscription.unsubscribe(); } - this.updateBadgeObserver && this.updateBadgeObserver.off(); } /** diff --git a/src/core/mainmenu/providers/delegate.ts b/src/core/mainmenu/providers/delegate.ts index ef87d35f3..23ac7e847 100644 --- a/src/core/mainmenu/providers/delegate.ts +++ b/src/core/mainmenu/providers/delegate.ts @@ -113,8 +113,6 @@ export class CoreMainMenuDelegate extends CoreDelegate { protected siteHandlers: Subject = new BehaviorSubject([]); protected featurePrefix = '$mmSideMenuDelegate_'; - static UPDATE_BADGE_EVENT = 'update_main_menu_badge'; - constructor(protected loggerProvider: CoreLoggerProvider, protected sitesProvider: CoreSitesProvider, protected eventsProvider: CoreEventsProvider) { super('CoreMainMenuDelegate', loggerProvider, sitesProvider, eventsProvider);