From c27617368283e6f77685861ef2f34afd88bd6f49 Mon Sep 17 00:00:00 2001 From: Jonathan Boiser Date: Mon, 1 Feb 2021 12:43:42 -0800 Subject: [PATCH] Fix logic for search page exit route Fixes #7769 --- .../learn/assets/src/views/LearnIndex.vue | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/kolibri/plugins/learn/assets/src/views/LearnIndex.vue b/kolibri/plugins/learn/assets/src/views/LearnIndex.vue index 0afa10b7970..2233a3962f5 100644 --- a/kolibri/plugins/learn/assets/src/views/LearnIndex.vue +++ b/kolibri/plugins/learn/assets/src/views/LearnIndex.vue @@ -109,7 +109,7 @@ mixins: [commonCoreStrings, commonLearnStrings, responsiveWindowMixin], data() { return { - lastRoute: null, + searchPageExitRoute: null, demographicInfo: null, }; }, @@ -178,8 +178,9 @@ return { appBarTitle: this.coreString('searchLabel'), immersivePage: true, - // Default to the Learn root page if there is no lastRoute to return to. - immersivePageRoute: this.lastRoute || this.$router.getRoute(PageNames.TOPICS_ROOT), + // Default to the Learn root page if there is no searchPageExitRoute to return to. + immersivePageRoute: + this.searchPageExitRoute || this.$router.getRoute(PageNames.TOPICS_ROOT), immersivePagePrimary: true, immersivePageIcon: 'close', }; @@ -275,20 +276,26 @@ }, watch: { $route: function(newRoute, oldRoute) { - // Return if the user is leaving or entering the Search page. - // This ensures we never set this.lastRoute to be any kind of - // SEARCH route and avoids infinite loops. - if (newRoute.name === 'SEARCH' || oldRoute.name === 'SEARCH') { - return; + const topicRouteNames = [ + PageNames.TOPICS_ROOT, + PageNames.TOPICS_CHANNEL, + PageNames.TOPICS_TOPIC, + ]; + // If going from topic -> search, save the topic route parameters for the + // exit link. + // But, if we go from search -> content, we do not edit `searchPageExitRoute` + // preserve the backwards linking from content -> search -> topic + if (topicRouteNames.includes(oldRoute.name) && newRoute.name === PageNames.SEARCH) { + this.searchPageExitRoute = { + name: oldRoute.name, + query: oldRoute.query, + params: oldRoute.params, + }; + } else if (oldRoute.name === PageNames.SEARCH && topicRouteNames.includes(newRoute.name)) { + // If going from search -> topic (either by clicking "X" or clicking a topic card + // in the results), clear out the exit route. + this.searchPageExitRoute = null; } - - // Destructure the oldRoute into an object with 3 specific properties. - // Setting this.lastRoute = oldRoute causes issues for some reason. - this.lastRoute = { - name: oldRoute.name, - query: oldRoute.query, - params: oldRoute.params, - }; }, }, mounted() {