Skip to content

Commit

Permalink
Fix logic for search page exit route
Browse files Browse the repository at this point in the history
  • Loading branch information
jonboiser committed Feb 1, 2021
1 parent 2f30a85 commit c276173
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions kolibri/plugins/learn/assets/src/views/LearnIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
mixins: [commonCoreStrings, commonLearnStrings, responsiveWindowMixin],
data() {
return {
lastRoute: null,
searchPageExitRoute: null,
demographicInfo: null,
};
},
Expand Down Expand Up @@ -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',
};
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit c276173

Please sign in to comment.