Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Avoir une navigation principale pour Pix Pro (PIX-1368). #190

Merged
merged 6 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion components/BurgerMenuNav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</li>
</ul>
</div>
<div v-if="isPixPro" class="nav-middle">
<div v-if="isPixPro && showProItems" class="nav-middle">
<hr class="nav-middle__bar" />
<p>Pix Pro</p>
<ul>
Expand All @@ -35,6 +35,10 @@ export default {
type: Array,
default: null,
},
showProItems: {
type: Boolean,
default: true,
},
},
computed: {
isPixPro() {
Expand Down
31 changes: 25 additions & 6 deletions components/NavigationSliceZone.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<burger-menu-nav
:items="burgerMenuLinks"
:pro-items="organizationNavItems"
:show-pro-items="showSubNav"
/>
</push-menu>
</client-only>
Expand All @@ -14,7 +15,7 @@
<div class="navigation-slice-zone__content">
<div class="navigation-slice-zone-content__left-side">
<section
v-for="(slice, index) in mainNavigation.data.body"
v-for="(slice, index) in usedMainNavigation.data.body"
:key="`navigation-slice-left-${index}`"
>
<template v-if="slice.slice_type === 'logos_zone'">
Expand All @@ -26,7 +27,7 @@
</section>
</div>
<section
v-for="(slice, index) in mainNavigation.data.body"
v-for="(slice, index) in usedMainNavigation.data.body"
:key="`navigation-slice-right-${index}`"
class="navigation-slice-zone-wrapper__right-side"
>
Expand All @@ -36,13 +37,14 @@
</section>
</div>
</div>
<pix-pro-sub-nav v-if="isPixPro" :nav-items="organizationNavItems" />
<pix-pro-sub-nav v-if="showSubNav" :nav-items="organizationNavItems" />
</div>
</div>
</template>

<script>
import { mapState } from 'vuex'
import { groupBy } from 'lodash'
MelanieMEB marked this conversation as resolved.
Show resolved Hide resolved
import LogosZone from '@/components/slices/LogosZone'
import NavigationZone from '@/components/slices/NavigationZone'
import ActionsZone from '@/components/slices/ActionsZone'
Expand All @@ -64,12 +66,29 @@ export default {
isPixPro() {
return process.env.isPixPro
},
...mapState(['mainNavigation', 'organizationNavItems']),

showSubNav() {
return (
this.isPixPro &&
this.usedMainNavigation.data.navigation_for === 'pix-site'
celineung marked this conversation as resolved.
Show resolved Hide resolved
)
},

...mapState(['mainNavigations', 'organizationNavItems']),

usedMainNavigation() {
const groupBySite = groupBy(this.mainNavigations, 'data.navigation_for')
if (this.isPixPro && groupBySite['pix-pro']) {
return groupBySite['pix-pro'][0]
}
return groupBySite['pix-site'][0]
},

burgerMenuLinks() {
const navigationZone = this.mainNavigation.data.body.find(
const navigationZone = this.usedMainNavigation.data.body.find(
(slice) => slice.slice_type === 'navigation_zone'
)
const actionsZone = this.mainNavigation.data.body.find(
const actionsZone = this.usedMainNavigation.data.body.find(
(slice) => slice.slice_type === 'actions_zone'
)
return [...navigationZone.items, ...actionsZone.items]
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@nuxtjs/dotenv": "^1.4.1",
"@nuxtjs/prismic": "^1.2.3",
"chart.js": "2.9.3",
"lodash": "^4.17.20",
"nuxt": "^2.13.3",
"nuxt-fontawesome": "0.4.0",
"nuxt-i18n": "6.13.1",
Expand Down
2 changes: 1 addition & 1 deletion plugins/i18n.js
Original file line number Diff line number Diff line change
@@ -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 })
}
}
7 changes: 7 additions & 0 deletions services/document-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ export function documentFetcher(
const lang = i18n.locale || i18n.defaultLocale
return {
get: getSingle,
findByType: async (type) => {
const documents = await prismic.api.query(
prismic.predicates.at('document.type', type),
{ lang }
)
return documents.results
},
getEmployers: async () => {
const document = await prismic.api.getSingle('employers', {
lang,
Expand Down
18 changes: 9 additions & 9 deletions store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ 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)
},
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 = {
Expand Down Expand Up @@ -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
Expand All @@ -62,8 +62,8 @@ function getNavigation(prismic, i18n) {
return documentFetcher(prismic, i18n).get(documents.navigation)
}

function getMainNavigation(prismic, i18n) {
return documentFetcher(prismic, i18n).get(documents.mainNavigation)
function getMainNavigations(prismic, i18n) {
return documentFetcher(prismic, i18n).findByType(documents.mainNavigation)
}

function getHotNews(prismic, i18n) {
Expand Down
Loading