From e2987a44b7ec700a1e96c89ccd85f0bb57f492b2 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Thu, 10 Jun 2021 14:53:53 +0200 Subject: [PATCH] MOBILE-3320 navigation: Remove path tracking --- .../pages/discussion/discussion.page.ts | 4 +-- .../services/handlers/user-send-message.ts | 1 + .../mod/feedback/components/index/index.ts | 1 + src/addons/mod/feedback/pages/form/form.ts | 9 +++---- src/core/services/navigator.ts | 25 +------------------ 5 files changed, 8 insertions(+), 32 deletions(-) diff --git a/src/addons/messages/pages/discussion/discussion.page.ts b/src/addons/messages/pages/discussion/discussion.page.ts index e9eb9b880..89e954d6a 100644 --- a/src/addons/messages/pages/discussion/discussion.page.ts +++ b/src/addons/messages/pages/discussion/discussion.page.ts @@ -158,15 +158,13 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView * Setup code for the page. */ async ngOnInit(): Promise { - // Disable the profile button if we're already coming from a profile. - const backViewPage = CoreNavigator.getPreviousPath(); - this.showInfo = !backViewPage || !CoreTextUtils.matchesGlob(backViewPage, '**/user/profile'); this.route.queryParams.subscribe(async (params) => { const oldConversationId = this.conversationId; const oldUserId = this.userId; this.conversationId = CoreNavigator.getRouteNumberParam('conversationId', { params }) || undefined; this.userId = CoreNavigator.getRouteNumberParam('userId', { params }) || undefined; + this.showInfo = !params.hideInfo; if (oldConversationId != this.conversationId || oldUserId != this.userId) { // Showing reload again can break animations. diff --git a/src/addons/messages/services/handlers/user-send-message.ts b/src/addons/messages/services/handlers/user-send-message.ts index bfb9f3b79..548d69d51 100644 --- a/src/addons/messages/services/handlers/user-send-message.ts +++ b/src/addons/messages/services/handlers/user-send-message.ts @@ -77,6 +77,7 @@ export class AddonMessagesSendMessageUserHandlerService implements CoreUserProfi const pageParams: Params = { showKeyboard: true, userId: user.id, + hideInfo: true, }; CoreNavigator.navigateToSitePath('/messages/discussion', { params: pageParams }); }, diff --git a/src/addons/mod/feedback/components/index/index.ts b/src/addons/mod/feedback/components/index/index.ts index cf2799220..3e77a7941 100644 --- a/src/addons/mod/feedback/components/index/index.ts +++ b/src/addons/mod/feedback/components/index/index.ts @@ -361,6 +361,7 @@ export class AddonModFeedbackIndexComponent extends CoreCourseModuleMainActivity { params: { preview, + fromIndex: true, }, }, ); diff --git a/src/addons/mod/feedback/pages/form/form.ts b/src/addons/mod/feedback/pages/form/form.ts index f365b6a9e..8d8612304 100644 --- a/src/addons/mod/feedback/pages/form/form.ts +++ b/src/addons/mod/feedback/pages/form/form.ts @@ -61,6 +61,7 @@ export class AddonModFeedbackFormPage implements OnInit, OnDestroy, CanLeave { title?: string; preview = false; + fromIndex = false; cmId!: number; courseId!: number; feedback?: AddonModFeedbackWSFeedback; @@ -96,6 +97,7 @@ export class AddonModFeedbackFormPage implements OnInit, OnDestroy, CanLeave { this.currentPage = CoreNavigator.getRouteNumberParam('page'); this.title = CoreNavigator.getRouteParam('title'); this.preview = !!CoreNavigator.getRouteBooleanParam('preview'); + this.fromIndex = !!CoreNavigator.getRouteBooleanParam('fromIndex'); await this.fetchData(); @@ -373,10 +375,7 @@ export class AddonModFeedbackFormPage implements OnInit, OnDestroy, CanLeave { * Function to link implemented features. */ showAnalysis(): void { - const indexPath = AddonModFeedbackModuleHandlerService.PAGE_NAME + `/${this.courseId}/${this.cmId}`; - const previousPath = CoreNavigator.getPreviousPath(); - - if (previousPath.match(new RegExp(indexPath + '$'))) { + if (this.fromIndex) { // Previous page is the index page, go back. CoreEvents.trigger(AddonModFeedbackProvider.FORM_SUBMITTED, { feedbackId: this.feedback!.id, @@ -389,7 +388,7 @@ export class AddonModFeedbackFormPage implements OnInit, OnDestroy, CanLeave { return; } - CoreNavigator.navigateToSitePath(indexPath, { + CoreNavigator.navigateToSitePath(AddonModFeedbackModuleHandlerService.PAGE_NAME + `/${this.courseId}/${this.cmId}`, { params: { module: this.module, tab: 'analysis', diff --git a/src/core/services/navigator.ts b/src/core/services/navigator.ts index da03518ff..a70122071 100644 --- a/src/core/services/navigator.ts +++ b/src/core/services/navigator.ts @@ -13,7 +13,7 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { ActivatedRoute, NavigationStart, Params, Router as RouterService } from '@angular/router'; +import { ActivatedRoute, Params } from '@angular/router'; import { NavigationOptions } from '@ionic/angular/providers/nav-controller'; @@ -28,7 +28,6 @@ import { CoreUrlUtils } from '@services/utils/url'; import { CoreTextUtils } from '@services/utils/text'; import { makeSingleton, NavController, Router } from '@singletons'; import { CoreScreen } from './screen'; -import { filter } from 'rxjs/operators'; import { CoreApp } from './app'; import { CoreSitePlugins } from '@features/siteplugins/services/siteplugins'; @@ -75,17 +74,6 @@ export class CoreNavigatorService { protected storedParams: Record = {}; protected lastParamId = 0; - protected currentPath?: string; - protected previousPath?: string; - - // @todo Param router is an optional param to let the mocking work. - constructor(router?: RouterService) { - router?.events.pipe(filter(event => event instanceof NavigationStart)).subscribe((routerEvent: NavigationStart) => { - // Using NavigationStart instead of NavigationEnd so it can be check on ngOnInit. - this.previousPath = this.currentPath; - this.currentPath = routerEvent.url; - }); - } /** * Check whether the active route is using the given path. @@ -267,17 +255,6 @@ export class CoreNavigatorService { return CoreUrlUtils.removeUrlParams(Router.url); } - /** - * Get the previous navigation route path. - * - * @return Previous path. - */ - getPreviousPath(): string { - // @todo: Remove this method and the used attributes. - // This is a quick workarround to avoid loops. Ie, in messages we can navigate to user profile and there to messages. - return CoreUrlUtils.removeUrlParams(this.previousPath || ''); - } - /** * Iterately get the params checking parent routes. *