From 960258381b74dcb4de3163035b456e081606e28c Mon Sep 17 00:00:00 2001 From: Anders Ekelund Date: Wed, 19 Feb 2020 15:16:37 +0100 Subject: [PATCH 1/2] Add CurrentPageMixin.ts --- components/CurrentPageMixin.ts | 49 ++++++++++++++++++++++++++++++++++ components/SharedMixin.ts | 11 ++++++-- 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 components/CurrentPageMixin.ts diff --git a/components/CurrentPageMixin.ts b/components/CurrentPageMixin.ts new file mode 100644 index 0000000..dbdb6ce --- /dev/null +++ b/components/CurrentPageMixin.ts @@ -0,0 +1,49 @@ +import { isServer } from '@vue-storefront/core/helpers' +import { RouterManager } from '@vue-storefront/core/lib/router-manager' + +export default { + data () { + return { + currentRouteComponent: null + } + }, + watch: { + '$route.name': function () { + this.setCurrentPage() + } + }, + computed: { + canGoBack () { + return !this.isHistoryEmpty() && this.isProductPage + }, + isProductPage () { + return this.currentRouteComponent == 'Product' + }, + isCategoryPage () { + return this.currentRouteComponent == 'Category' + }, + isStoryblokPage () { + return this.currentRouteComponent == 'StoryblokPage' + }, + isCheckoutPage () { + return this.currentRouteComponent == 'Checkout' + }, + }, + created () { + this.setCurrentPage() + }, + methods: { + setCurrentPage () { + const route = RouterManager.findByName(this.$route.name) + this.currentRouteComponent = route && route.component && route.component.name + }, + // Check if history is empty + isHistoryEmpty () { + if (!isServer) { + return window.history.length <= 1 + } + + return false + } + } +} diff --git a/components/SharedMixin.ts b/components/SharedMixin.ts index d04d881..9218b89 100644 --- a/components/SharedMixin.ts +++ b/components/SharedMixin.ts @@ -5,10 +5,11 @@ import { localizedRoute, removeStoreCodeFromRoute } from '@vue-storefront/core/l import get from 'lodash.get' import StoryblokMixin from 'src/modules/vsf-storyblok-module/components/StoryblokMixin' import config from 'config' +import CurrentPageMixin from './CurrentPageMixin' export default { name: 'StorePickerMixin', - mixins: [StoryblokMixin], + mixins: [StoryblokMixin, CurrentPageMixin], computed: { ...mapGetters({ current: 'store-picker/currentStoreView', @@ -27,7 +28,13 @@ export default { } // Are we on a Storyblok CMS page? - if(this.story && !this.story.full_slug.endsWith('/home')){ + if (this.isProductPage) { + return this.localizedRoute(url, view).replace(/\/$/, "") + '?posterpage' + } + else if (this.isCategoryPage) { + return this.localizedRoute(url, view).replace(/\/$/, "") + '?categorypage' + } + else if (this.isStoryblokPage && !this.story.full_slug.endsWith('/home')){ // Try to find an alternate story for the target storeview let alternateStory = this.story.alternates.find((alternate) => { return alternate.full_slug.startsWith(view.storeCode + '/') From b2c1b8dd268055d7254b63f0cc666262877e85b7 Mon Sep 17 00:00:00 2001 From: Anders Ekelund Date: Fri, 21 Feb 2020 21:20:45 +0100 Subject: [PATCH 2/2] refactoring --- components/CurrentPageMixin.ts | 26 ++++++++------------------ components/SharedMixin.ts | 1 + 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/components/CurrentPageMixin.ts b/components/CurrentPageMixin.ts index dbdb6ce..f7bb443 100644 --- a/components/CurrentPageMixin.ts +++ b/components/CurrentPageMixin.ts @@ -4,29 +4,26 @@ import { RouterManager } from '@vue-storefront/core/lib/router-manager' export default { data () { return { - currentRouteComponent: null + currentRouteComponentName: null } }, watch: { - '$route.name': function () { + '$route': function () { this.setCurrentPage() } }, computed: { - canGoBack () { - return !this.isHistoryEmpty() && this.isProductPage - }, isProductPage () { - return this.currentRouteComponent == 'Product' + return this.currentRouteComponentName == 'Product' }, isCategoryPage () { - return this.currentRouteComponent == 'Category' + return this.currentRouteComponentName == 'Category' }, isStoryblokPage () { - return this.currentRouteComponent == 'StoryblokPage' + return this.currentRouteComponentName == 'StoryblokPage' }, isCheckoutPage () { - return this.currentRouteComponent == 'Checkout' + return this.currentRouteComponentName == 'Checkout' }, }, created () { @@ -35,15 +32,8 @@ export default { methods: { setCurrentPage () { const route = RouterManager.findByName(this.$route.name) - this.currentRouteComponent = route && route.component && route.component.name - }, - // Check if history is empty - isHistoryEmpty () { - if (!isServer) { - return window.history.length <= 1 - } - - return false + console.log({pageType: route.component.name}) + this.currentRouteComponentName = route && route.component && route.component.name } } } diff --git a/components/SharedMixin.ts b/components/SharedMixin.ts index 9218b89..d5b1967 100644 --- a/components/SharedMixin.ts +++ b/components/SharedMixin.ts @@ -6,6 +6,7 @@ import get from 'lodash.get' import StoryblokMixin from 'src/modules/vsf-storyblok-module/components/StoryblokMixin' import config from 'config' import CurrentPageMixin from './CurrentPageMixin' +import { findCategoryByPath } from '../findCategoryByPath' export default { name: 'StorePickerMixin',