From e5ed2bc996a2a7d80e5601ea8815bf4100e3349f Mon Sep 17 00:00:00 2001 From: melanieb Date: Fri, 9 Oct 2020 16:42:43 +0200 Subject: [PATCH] [Clean] remplace mainNavigation by mainNavigations Replace the object for the state : https://vuex.vuejs.org/fr/guide/mutations.html#les-mutations-suivent-les-regles-de-reactivite-de-vue --- components/NavigationSliceZone.vue | 4 ++-- plugins/i18n.js | 2 +- store/index.js | 16 ++++++++-------- .../slices/NavigationSliceZone.test.js | 10 +++++----- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/components/NavigationSliceZone.vue b/components/NavigationSliceZone.vue index 0e6107d4a..295f52ca3 100644 --- a/components/NavigationSliceZone.vue +++ b/components/NavigationSliceZone.vue @@ -74,10 +74,10 @@ export default { ) }, - ...mapState(['mainNavigation', 'organizationNavItems']), + ...mapState(['mainNavigations', 'organizationNavItems']), usedMainNavigation() { - const groupBySite = groupBy(this.mainNavigation, 'data.navigation_for') + const groupBySite = groupBy(this.mainNavigations, 'data.navigation_for') if (this.isPixPro && groupBySite['pix-pro']) { return groupBySite['pix-pro'][0] } diff --git a/plugins/i18n.js b/plugins/i18n.js index a5e7b6a15..dbc9b35e6 100644 --- a/plugins/i18n.js +++ b/plugins/i18n.js @@ -1,6 +1,6 @@ export default function ({ app: { $prismic, i18n, store } }) { i18n.onLanguageSwitched = () => { store.dispatch('updateNavigation', { prismic: $prismic, i18n }) - store.dispatch('updateMainNavigation', { prismic: $prismic, i18n }) + store.dispatch('updateMainNavigations', { prismic: $prismic, i18n }) } } diff --git a/store/index.js b/store/index.js index abcd509ab..8385ea642 100644 --- a/store/index.js +++ b/store/index.js @@ -6,14 +6,14 @@ export const state = () => ({ aboutNavItems: [], hotNews: null, host: null, - mainNavigation: [], + mainNavigations: [], }) export const actions = { async nuxtServerInit({ commit }, { app, req }) { commit('updateNavigation', await getNavigation(app.$prismic, app.i18n)) commit( - 'updateMainNavigation', - await getMainNavigation(app.$prismic, app.i18n) + 'updateMainNavigations', + await getMainNavigations(app.$prismic, app.i18n) ) commit('updateHotNews', await getHotNews(app.$prismic, app.i18n)) commit('updateHost', req) @@ -21,8 +21,8 @@ export const actions = { async updateNavigation({ commit }, { i18n, prismic }) { commit('updateNavigation', await getNavigation(prismic, i18n)) }, - async updateMainNavigation({ commit }, { i18n, prismic }) { - commit('updateMainNavigation', await getMainNavigation(prismic, i18n)) + async updateMainNavigations({ commit }, { i18n, prismic }) { + commit('updateMainNavigations', await getMainNavigations(prismic, i18n)) }, } export const mutations = { @@ -50,8 +50,8 @@ export const mutations = { state.resourcesNavItems = navItems(navigations, 'ressources-nav') state.aboutNavItems = navItems(navigations, 'about-nav') }, - updateMainNavigation(state, navigations) { - state.mainNavigation = navigations + updateMainNavigations(state, navigations) { + state.mainNavigations = [...navigations] }, updateHotNews(state, hotNews) { state.hotNews = hotNews && hotNews.data ? hotNews.data.description : null @@ -62,7 +62,7 @@ function getNavigation(prismic, i18n) { return documentFetcher(prismic, i18n).get(documents.navigation) } -function getMainNavigation(prismic, i18n) { +function getMainNavigations(prismic, i18n) { return documentFetcher(prismic, i18n).findByType(documents.mainNavigation) } diff --git a/tests/components/slices/NavigationSliceZone.test.js b/tests/components/slices/NavigationSliceZone.test.js index 76a42a7dd..76924512d 100644 --- a/tests/components/slices/NavigationSliceZone.test.js +++ b/tests/components/slices/NavigationSliceZone.test.js @@ -70,7 +70,7 @@ describe('NavigationSliceZone', () => { beforeEach(() => { store = { state: { - mainNavigation: [expectedSiteNavigation, expectedProNavigation], + mainNavigations: [expectedSiteNavigation, expectedProNavigation], }, } }) @@ -99,7 +99,7 @@ describe('NavigationSliceZone', () => { } store = { state: { - mainNavigation: [expectedSiteNavigation, expectedProNavigation], + mainNavigations: [expectedSiteNavigation, expectedProNavigation], }, } }) @@ -128,7 +128,7 @@ describe('NavigationSliceZone', () => { } store = { state: { - mainNavigation: [expectedSiteNavigation], + mainNavigations: [expectedSiteNavigation], }, } }) @@ -160,7 +160,7 @@ describe('NavigationSliceZone', () => { store = { state: { - mainNavigation: [expectedSiteNavigation, expectedProNavigation], + mainNavigations: [expectedSiteNavigation, expectedProNavigation], }, } }) @@ -190,7 +190,7 @@ describe('NavigationSliceZone', () => { store = { state: { - mainNavigation: [expectedSiteNavigation], + mainNavigations: [expectedSiteNavigation], }, } })