diff --git a/CHANGELOG.md b/CHANGELOG.md index db4def0992..8e3d25e0dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [1.11.2] - UNRELEASED +### Added +- Add `isBackRoute` that informs if user returns to route, skip loading products for category if he does - @gibkigonzo (issue#4066) + ### Changed / Improved - optimizations - improved prefetch strategy - @gibkigonzo (#4080) @@ -16,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix possibility to add same SKU with different custom options to the cart - @Michal-Dziedzinski (#3595) - Fix `calculateProductTax` to find matching tax rules from ES for current product - @DylannCordel (#4056) - Set `totals` in products in cart always in reactive way - @psmyrek (#4079) +- Add currentRoute to url module and return cached requests - @gibkigonzo (pr#4077, issue#4066) ## [1.11.1] - 2020.02.05 @@ -52,7 +56,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix v-model not working in BaseRadioButton - @lukeromanowicz (#4035) - always keep filters values as array of object - @gibkigonzo (#4045) - Fix ecosystem config to work with ts-node - @andrzejewsky (#3981) -- Add currentRoute to url module and return cached requests - @gibkigonzo (#4045) ## [1.11.0] - 2019.12.20 diff --git a/config/default.json b/config/default.json index 5399fe6cd8..de2e7033d2 100644 --- a/config/default.json +++ b/config/default.json @@ -449,7 +449,7 @@ "i18n": { "defaultCountry": "US", "defaultLanguage": "EN", - "availableLocale": ["en-US","de-DE","fr-FR","es-ES","nl-NL", "ja-JP", "ru-RU", "it-IT", "pt-BR", "pl-PL", "cs-CZ"], + "availableLocale": ["en-US"], "defaultLocale": "en-US", "currencyCode": "USD", "currencySign": "$", @@ -457,7 +457,7 @@ "dateFormat": "HH:mm D/M/YYYY", "fullCountryName": "United States", "fullLanguageName": "English", - "bundleAllStoreviewLanguages": true + "bundleAllStoreviewLanguages": false }, "expireHeaders": { "default": "30d", diff --git a/core/client-entry.ts b/core/client-entry.ts index edc20abd62..10ca462da2 100755 --- a/core/client-entry.ts +++ b/core/client-entry.ts @@ -104,7 +104,7 @@ const invokeClientEntry = async () => { return next() } - store.dispatch('url/setCurrentRoute', to) + store.dispatch('url/setCurrentRoute', {to, from}) Promise.all(matched.map((c: any) => { // TODO: update me for mixins support const components = c.mixins && globalConfig.ssr.executeMixedinAsyncData ? Array.from(c.mixins) : [] diff --git a/core/modules/url/store/actions.ts b/core/modules/url/store/actions.ts index 07ad84f966..2532b8d6df 100644 --- a/core/modules/url/store/actions.ts +++ b/core/modules/url/store/actions.ts @@ -9,6 +9,7 @@ import SearchQuery from '@vue-storefront/core/lib/search/searchQuery' import { preProcessDynamicRoutes, normalizeUrlPath, parametrizeRouteData, getFallbackRouteData } from '../helpers' import { removeStoreCodeFromRoute, currentStoreView, localizedDispatcherRouteName } from '@vue-storefront/core/lib/multistore' import storeCodeFromRoute from '@vue-storefront/core/lib/storeCodeFromRoute' +import isEqual from 'lodash-es/isEqual' // it's a good practice for all actions to return Promises with effect of their execution export const actions: ActionTree = { @@ -94,7 +95,9 @@ export const actions: ActionTree = { } } }, - setCurrentRoute ({ commit }, payload) { - commit(types.SET_CURRENT_ROUTE, payload) + setCurrentRoute ({ commit, state }, {to, from} = {}) { + commit(types.SET_CURRENT_ROUTE, to) + commit(types.IS_BACK_ROUTE, isEqual(state.prevRoute, state.currentRoute) && state.currentRoute.path !== from.path) + commit(types.SET_PREV_ROUTE, from) } } diff --git a/core/modules/url/store/getters.ts b/core/modules/url/store/getters.ts index eac527f75c..ee3e1a36c4 100644 --- a/core/modules/url/store/getters.ts +++ b/core/modules/url/store/getters.ts @@ -1,3 +1,4 @@ export const getters = { - getCurrentRoute: (state) => state.currentRoute + getCurrentRoute: (state) => state.currentRoute, + isBackRoute: (state) => state.isBackRoute } diff --git a/core/modules/url/store/mutation-types.ts b/core/modules/url/store/mutation-types.ts index ec7537f0c5..7d47ee8ca4 100644 --- a/core/modules/url/store/mutation-types.ts +++ b/core/modules/url/store/mutation-types.ts @@ -1,2 +1,4 @@ export const REGISTER_MAPPING = 'URL/REGISTER_MAPPING' export const SET_CURRENT_ROUTE = 'URL/SET_CURRENT_ROUTE' +export const SET_PREV_ROUTE = 'URL/SET_PREV_ROUTE' +export const IS_BACK_ROUTE = 'URL/IS_BACK_ROUTE' diff --git a/core/modules/url/store/mutations.ts b/core/modules/url/store/mutations.ts index d4a3ed6c67..6523420c47 100644 --- a/core/modules/url/store/mutations.ts +++ b/core/modules/url/store/mutations.ts @@ -8,5 +8,11 @@ export const mutations: MutationTree = { }, [types.SET_CURRENT_ROUTE] (state, payload = {}) { state.currentRoute = omit(payload, ['matched']) + }, + [types.SET_PREV_ROUTE] (state, payload = {}) { + state.prevRoute = omit(payload, ['matched']) + }, + [types.IS_BACK_ROUTE] (state, payload) { + state.isBackRoute = payload } } diff --git a/core/modules/url/store/state.ts b/core/modules/url/store/state.ts index f4dc5af317..bc87f84916 100644 --- a/core/modules/url/store/state.ts +++ b/core/modules/url/store/state.ts @@ -2,5 +2,7 @@ import { UrlState } from '../types/UrlState' export const state: UrlState = { dispatcherMap: {}, - currentRoute: {} + currentRoute: {}, + prevRoute: {}, + isBackRoute: false } diff --git a/core/modules/url/types/UrlState.ts b/core/modules/url/types/UrlState.ts index d526a981ea..20c65b976c 100644 --- a/core/modules/url/types/UrlState.ts +++ b/core/modules/url/types/UrlState.ts @@ -5,5 +5,7 @@ import { LocalizedRoute } from '@vue-storefront/core/lib/types' // It's a good practice is to name this interface accordingly to the KET (for example mailchimpState) export interface UrlState { dispatcherMap: { [path: string]: LocalizedRoute}, - currentRoute: Partial + currentRoute: Partial, + prevRoute: Partial, + isBackRoute: boolean } diff --git a/core/server-entry.ts b/core/server-entry.ts index 8d054ff45d..18fc502220 100755 --- a/core/server-entry.ts +++ b/core/server-entry.ts @@ -78,7 +78,7 @@ export default async context => { if (!matchedComponents.length || !matchedComponents[0]) { return reject(new HttpError('No components matched', 404)) // TODO - don't redirect if already on page-not-found } - store.dispatch('url/setCurrentRoute', router.currentRoute) + store.dispatch('url/setCurrentRoute', { to: router.currentRoute }) Promise.all(matchedComponents.map((Component: any) => { const components = Component.mixins ? Array.from(Component.mixins) : [] union(components, [Component]).map(SubComponent => { diff --git a/src/themes/default/pages/Category.vue b/src/themes/default/pages/Category.vue index 8182d3366a..3725346ec9 100644 --- a/src/themes/default/pages/Category.vue +++ b/src/themes/default/pages/Category.vue @@ -102,7 +102,9 @@ const composeInitialPageState = async (store, route, forceLoad = false) => { const filters = getSearchOptionsFromRouteParams(route.params) const cachedCategory = store.getters['category-next/getCategoryFrom'](route.path) const currentCategory = cachedCategory && !forceLoad ? cachedCategory : await store.dispatch('category-next/loadCategory', { filters }) - await store.dispatch('category-next/loadCategoryProducts', {route, category: currentCategory, pageSize: THEME_PAGE_SIZE}) + if (!store.getters['url/isBackRoute']) { + await store.dispatch('category-next/loadCategoryProducts', {route, category: currentCategory, pageSize: THEME_PAGE_SIZE}) + } const breadCrumbsLoader = store.dispatch('category-next/loadCategoryBreadcrumbs', { category: currentCategory, currentRouteName: currentCategory.name, omitCurrent: true }) if (isServer) await breadCrumbsLoader