MOBILE-3585 mainmenu: Fix go to root when tab clicked
parent
07e5d2bbf2
commit
3d3890a70d
|
@ -45,6 +45,7 @@ export class AddonPrivateFilesMainMenuHandler implements CoreMainMenuHandler {
|
|||
icon: 'fa-folder',
|
||||
title: 'addon.privatefiles.files',
|
||||
page: 'addon-privatefiles',
|
||||
subPage: 'root',
|
||||
class: 'addon-privatefiles-handler',
|
||||
};
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import { Subscription } from 'rxjs';
|
|||
|
||||
import { CoreApp } from '@services/app';
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { CoreTextUtils } from '@services/utils/text';
|
||||
import { CoreEvents, CoreEventObserver, CoreEventLoadPageMainMenuData } from '@singletons/events';
|
||||
import { CoreMainMenu } from '../../services/mainmenu';
|
||||
import { CoreMainMenuDelegate, CoreMainMenuHandlerToDisplay } from '../../services/mainmenu.delegate';
|
||||
|
@ -242,8 +243,10 @@ export class CoreMainMenuPage implements OnInit, OnDestroy {
|
|||
return;
|
||||
}
|
||||
|
||||
const trimmedUrl = CoreTextUtils.instance.trimCharacter(this.router.url, '/');
|
||||
|
||||
// Current tab was clicked. Check if user is already at root level.
|
||||
if (this.router.url == '/mainmenu/' + page) {
|
||||
if (trimmedUrl == CoreTextUtils.instance.trimCharacter(page, '/')) {
|
||||
// Already at root level, nothing to do.
|
||||
return;
|
||||
}
|
||||
|
@ -255,8 +258,17 @@ export class CoreMainMenuPage implements OnInit, OnDestroy {
|
|||
try {
|
||||
const tab = this.tabs.find((tab) => tab.page == page);
|
||||
|
||||
// Use tab's subPage to check if user is already at root level.
|
||||
if (tab?.subPage && trimmedUrl ==
|
||||
CoreTextUtils.instance.trimCharacter(CoreTextUtils.instance.concatenatePaths(tab.page, tab.subPage), '/')) {
|
||||
// Already at root level, nothing to do.
|
||||
return;
|
||||
}
|
||||
|
||||
if (tab?.title) {
|
||||
await CoreDomUtils.instance.showConfirm(Translate.instance.instant('core.confirmgotabroot', { name: tab.title }));
|
||||
await CoreDomUtils.instance.showConfirm(Translate.instance.instant('core.confirmgotabroot', {
|
||||
name: Translate.instance.instant(tab.title),
|
||||
}));
|
||||
} else {
|
||||
await CoreDomUtils.instance.showConfirm(Translate.instance.instant('core.confirmgotabrootdefault'));
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ export class CoreHomeMainMenuHandler implements CoreMainMenuHandler {
|
|||
icon: 'fa-home',
|
||||
title: 'core.mainmenu.home',
|
||||
page: 'home',
|
||||
// @todo: subPage? The page can change due to core-tabs.
|
||||
class: 'core-home-handler',
|
||||
};
|
||||
}
|
||||
|
|
|
@ -32,6 +32,13 @@ export interface CoreMainMenuHandlerData {
|
|||
*/
|
||||
page: string;
|
||||
|
||||
/**
|
||||
* Sub page loaded when the handler page is loaded.
|
||||
* If your module performs a redirect when it's opened you need to specify the sub page in here.
|
||||
* E.g. if page is 'foo' but it redirects to 'foo/bar' when opened, this value must be 'bar'.
|
||||
*/
|
||||
subPage?: string;
|
||||
|
||||
/**
|
||||
* Title to display for the handler.
|
||||
*/
|
||||
|
|
|
@ -891,6 +891,20 @@ export class CoreTextUtilsProvider {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all ocurrences of a certain character from the start and end of a string.
|
||||
*
|
||||
* @param text Text to treat.
|
||||
* @param character Character to remove.
|
||||
* @return Treated text.
|
||||
*/
|
||||
trimCharacter(text: string, character: string): string {
|
||||
const escaped = this.escapeForRegex(character);
|
||||
const regExp = new RegExp(`^${escaped}+|${escaped}+$`, 'g');
|
||||
|
||||
return text.replace(regExp, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* If a number has only 1 digit, add a leading zero to it.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue