MOBILE-3633 notifications: Use the new CoreNavigator

main
Dani Palou 2021-01-20 12:56:26 +01:00
parent 8db2d4c199
commit 1800beed31
9 changed files with 42 additions and 22 deletions

View File

@ -37,7 +37,7 @@ import {
AddonNotificationsPreferencesNotificationFormatted,
AddonNotificationsPreferencesProcessorFormatted,
} from '@addons/notifications/services/notifications-helper';
import { CoreNavHelper } from '@services/nav-helper';
import { CoreNavigator } from '@services/navigator';
// import { CoreSplitViewComponent } from '@components/split-view/split-view';
/**
@ -201,7 +201,7 @@ export class AddonNotificationsSettingsPage implements OnInit, OnDestroy {
openExtraPreferences(handlerData: AddonMessageOutputHandlerData): void {
// Decide which navCtrl to use. If this page is inside a split view, use the split view's master nav.
// @todo const navCtrl = this.svComponent ? this.svComponent.getMasterNav() : this.navCtrl;
CoreNavHelper.instance.goInCurrentMainMenuTab(handlerData.page, handlerData.pageParams);
CoreNavigator.instance.navigateToSitePath(handlerData.page, { params: handlerData.pageParams });
}
/**

View File

@ -14,7 +14,7 @@
import { Injectable } from '@angular/core';
import { CoreNavHelper } from '@services/nav-helper';
import { CoreNavigator } from '@services/navigator';
import { CoreTextUtils } from '@services/utils/text';
import { CoreUtils } from '@services/utils/utils';
import { makeSingleton } from '@singletons';
@ -23,6 +23,7 @@ import { CorePushNotificationsClickHandler } from '@features/pushnotifications/s
import { CorePushNotificationsNotificationBasicData } from '@features/pushnotifications/services/pushnotifications';
import { CoreContentLinksHelper } from '@features/contentlinks/services/contentlinks-helper';
import { AddonNotifications, AddonNotificationsProvider } from '../notifications';
import { AddonNotificationsMainMenuHandlerService } from './mainmenu';
/**
* Handler for non-messaging push notifications clicks.
@ -122,7 +123,10 @@ export class AddonNotificationsPushClickHandlerService implements CorePushNotifi
// No contexturl or cannot be handled by the app. Open the notifications page.
await CoreUtils.instance.ignoreErrors(AddonNotifications.instance.invalidateNotificationsList(notification.site));
await CoreNavHelper.instance.goInSite('notifications', {}, notification.site);
await CoreNavigator.instance.navigateToSitePath(
AddonNotificationsMainMenuHandlerService.PAGE_NAME,
{ siteId: notification.site },
);
}
}

View File

@ -24,6 +24,7 @@ import { resolveModuleRoutes } from '@/app/app-routing.module';
import { MAIN_MENU_ROUTES } from './mainmenu-routing.module';
import { CoreMainMenuPage } from './pages/menu/menu';
import { CoreMainMenuHomeHandlerService } from './services/handlers/mainmenu';
import { CoreMainMenuProvider } from './services/mainmenu';
function buildRoutes(injector: Injector): Routes {
const routes = resolveModuleRoutes(injector, MAIN_MENU_ROUTES);
@ -43,7 +44,7 @@ function buildRoutes(injector: Injector): Routes {
loadChildren: () => import('./pages/home/home.module').then(m => m.CoreMainMenuHomePageModule),
},
{
path: 'more',
path: CoreMainMenuProvider.MORE_PAGE_NAME,
loadChildren: () => import('./pages/more/more.module').then(m => m.CoreMainMenuMorePageModule),
},
...routes.children,

View File

@ -9,7 +9,7 @@
<ion-badge *ngIf="tab.badge">{{ tab.badge }}</ion-badge>
</ion-tab-button>
<ion-tab-button (ionTabButtonClick)="tabClicked($event, 'more')" [hidden]="!loaded" tab="more" layout="label-hide">
<ion-tab-button (ionTabButtonClick)="tabClicked($event, morePageName)" [hidden]="!loaded" [tab]="morePageName" layout="label-hide">
<ion-icon name="fas-bars"></ion-icon>
<ion-label>{{ 'core.more' | translate }}</ion-label>
</ion-tab-button>

View File

@ -21,7 +21,7 @@ import { CoreApp } from '@services/app';
import { CoreSites } from '@services/sites';
import { CoreTextUtils } from '@services/utils/text';
import { CoreEvents, CoreEventObserver } from '@singletons/events';
import { CoreMainMenu } from '../../services/mainmenu';
import { CoreMainMenu, CoreMainMenuProvider } from '../../services/mainmenu';
import { CoreMainMenuDelegate, CoreMainMenuHandlerToDisplay } from '../../services/mainmenu-delegate';
import { CoreDomUtils } from '@services/utils/dom';
import { Translate } from '@singletons';
@ -43,6 +43,7 @@ export class CoreMainMenuPage implements OnInit, OnDestroy {
showTabs = false;
tabsPlacement = 'bottom';
hidden = false;
morePageName = CoreMainMenuProvider.MORE_PAGE_NAME;
protected subscription?: Subscription;
protected redirectObs?: CoreEventObserver;
@ -152,7 +153,7 @@ export class CoreMainMenuPage implements OnInit, OnDestroy {
if (this.loaded && this.mainTabs && !this.mainTabs.getSelected()) {
// Select the first tab.
setTimeout(() => {
this.mainTabs!.select(this.tabs[0]?.page || 'more');
this.mainTabs!.select(this.tabs[0]?.page || this.morePageName);
});
}
}

View File

@ -29,6 +29,7 @@ export class CoreMainMenuProvider {
static readonly NUM_MAIN_HANDLERS = 4;
static readonly ITEM_MIN_WIDTH = 72; // Min with of every item, based on 5 items on a 360 pixel wide screen.
static readonly MORE_PAGE_NAME = 'more';
protected tablet = false;
@ -191,11 +192,24 @@ export class CoreMainMenuProvider {
return tablet ? 'side' : 'bottom';
}
/**
* Check if a certain page is the root of a main menu tab.
*
* @param page Name of the page.
* @return Promise resolved with boolean: whether it's the root of a main menu tab.
*/
async isMainMenuTab(pageName: string): Promise<boolean> {
if (pageName == CoreMainMenuProvider.MORE_PAGE_NAME) {
return true;
}
return this.isCurrentMainMenuHandler(pageName);
}
/**
* Check if a certain page is the root of a main menu handler currently displayed.
*
* @param page Name of the page.
* @param pageParams Page params.
* @return Promise resolved with boolean: whether it's the root of a main menu handler.
*/
async isCurrentMainMenuHandler(pageName: string): Promise<boolean> {

View File

@ -26,7 +26,7 @@ import { CoreSettingsHelper, CoreSiteSpaceUsage } from '../../services/settings-
import { CoreApp } from '@services/app';
import { CoreSiteInfo } from '@classes/site';
import { Translate } from '@singletons';
import { CoreNavHelper } from '@services/nav-helper';
import { CoreNavigator } from '@services/navigator';
/**
* Page that displays the list of site settings pages.
@ -183,7 +183,7 @@ export class CoreSitePreferencesPage implements OnInit, OnDestroy {
openHandler(page: string, params?: Params): void {
this.selectedPage = page;
// this.splitviewCtrl.push(page, params);
CoreNavHelper.instance.goInCurrentMainMenuTab(page, params);
CoreNavigator.instance.navigateToSitePath(page, { params });
}
/**

View File

@ -203,6 +203,7 @@ export class CoreNavigatorService {
* If the path belongs to a visible tab, that tab will be selected.
* If it doesn't, the current tab or the default tab will be used instead.
*
* @param path Main menu path.
* @param options Navigation options.
* @return Whether navigation suceeded.
*/
@ -213,22 +214,21 @@ export class CoreNavigatorService {
path = path.replace(/^(\.|\/main)?\//, '');
// Open the path within the corresponding main tab.
const pathRoot = /^[^/]+/.exec(path)?.[0] ?? '';
const isCurrentMainMenuHandler = await CoreUtils.instance.ignoreErrors(
CoreMainMenu.instance.isCurrentMainMenuHandler(pathRoot),
const currentMainMenuTab = this.getCurrentMainMenuTab();
const isMainMenuTab = await CoreUtils.instance.ignoreErrors(
CoreMainMenu.instance.isMainMenuTab(pathRoot),
false,
);
if (isCurrentMainMenuHandler) {
return this.navigate(`/main/${path}`, options);
// Open the path within the current main tab.
if (currentMainMenuTab && (!isMainMenuTab || pathRoot !== currentMainMenuTab)) {
return this.navigate(`/main/${currentMainMenuTab}/${path}`, options);
}
// Open the path within the current main tab.
const currentMainMenuTab = this.getCurrentMainMenuTab();
if (currentMainMenuTab) {
return this.navigate(`/main/${currentMainMenuTab}/${path}`, options);
// Open the path within the corresponding main tab.
if (isMainMenuTab) {
return this.navigate(`/main/${path}`, options);
}
// Open the path within the default main tab.

View File

@ -44,7 +44,7 @@ describe('CoreNavigator', () => {
mockSingleton(CoreUtils, new CoreUtilsProvider(mock()));
mockSingleton(CoreUrlUtils, new CoreUrlUtilsProvider());
mockSingleton(CoreSites, { getCurrentSiteId: () => 42, isLoggedIn: () => true });
mockSingleton(CoreMainMenu, { isCurrentMainMenuHandler: path => Promise.resolve(currentMainMenuHandlers.includes(path)) });
mockSingleton(CoreMainMenu, { isMainMenuTab: path => Promise.resolve(currentMainMenuHandlers.includes(path)) });
});
it('matches against current path', () => {