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

[TECH] Supprimer le store Vuex (PIX-1468). #320

Merged
merged 4 commits into from
Nov 8, 2021
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
18 changes: 12 additions & 6 deletions components/FooterSliceZone.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<footer class="footer" role="contentinfo">
<div class="footer__left">
<div
v-for="(slice, index) in usedMainFooter.data.body"
v-for="(slice, index) in usedMainFooter"
:key="`footer-slice-left-${index}`"
>
<template v-if="slice.slice_type === 'logos_zone'">
Expand Down Expand Up @@ -42,33 +42,39 @@
</template>

<script>
import { mapState } from 'vuex'
import { keyBy } from '~/services/key-by'
import { documentFetcher, documents } from '~/services/document-fetcher'

export default {
name: 'FooterSliceZone',
data() {
return {
socialMediasHoverMap: {},
mainFooters: null,
}
},
async fetch() {
this.mainFooters = await documentFetcher(
this.$prismic,
this.$i18n
).findByType(documents.mainFooter)
Comment on lines +57 to +60
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion(non bloquant): Je ne sais pas si c'est possible techniquement, est-ce qu'on pourrait faire un plugin pour injecter le documentFetcher ? Comme ça on ferait :

Suggested change
this.mainFooters = await documentFetcher(
this.$prismic,
this.$i18n
).findByType(documents.mainFooter)
this.mainFooters = await this.$documentFetcher.findByType(documents.mainFooter)

cf le 1er exemple où ils injectent un $hello : https://nuxtjs.org/docs/directory-structure/plugins/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si j'y ai pensé, je pense le faire dans une autre PR !

},
computed: {
isPixPro() {
return process.env.isPixPro
},
...mapState(['mainFooters']),
usedMainFooter() {
const mainFooterBySite = keyBy(
this.mainFooters,
(mainFooter) => mainFooter?.data?.footer_for
)
if (this.isPixPro && mainFooterBySite['pix-pro']) {
return mainFooterBySite['pix-pro']
return mainFooterBySite['pix-pro'].data.body
}
return mainFooterBySite['pix-site']
return mainFooterBySite['pix-site'].data.body
},
navigationGroups() {
return this.usedMainFooter.data.body.filter(
return this.usedMainFooter.filter(
(slice) => slice.slice_type === 'navigation_group'
)
},
Expand Down
11 changes: 9 additions & 2 deletions components/HotNewsBanner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,23 @@
</template>

<script>
import { mapState } from 'vuex'
import { documentFetcher, documents } from '~/services/document-fetcher'

export default {
name: 'HotNewsBanner',
data() {
return {
isOpen: true,
hotNews: null,
}
},
computed: mapState(['hotNews']),
async fetch() {
const hotNews = await documentFetcher(this.$prismic, this.$i18n).findByType(
documents.hotNews
)

this.hotNews = hotNews?.data?.description
},
methods: {
closeBanner() {
this.isOpen = false
Expand Down
14 changes: 12 additions & 2 deletions components/NavigationSliceZone.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,26 @@
</template>

<script>
import { mapState } from 'vuex'
import { keyBy } from '~/services/key-by'
import { documentFetcher, documents } from '~/services/document-fetcher'

export default {
name: 'NavigationSliceZone',
data() {
return {
mainNavigations: [],
}
},
async fetch() {
this.mainNavigations = await documentFetcher(
this.$prismic,
this.$i18n
).findByType(documents.mainNavigation)
},
computed: {
isPixPro() {
return process.env.isPixPro
},
...mapState(['mainNavigations']),

usedMainNavigation() {
const mainNavBySite = keyBy(
Expand Down
47 changes: 0 additions & 47 deletions store/index.js

This file was deleted.

41 changes: 16 additions & 25 deletions tests/components/slices/NavigationSliceZone.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ jest.mock('~/services/document-fetcher')

describe('NavigationSliceZone', () => {
let component
let store
const stubs = {
'client-only': true,
'slide-menu': true,
Expand Down Expand Up @@ -66,19 +65,16 @@ describe('NavigationSliceZone', () => {

describe('#usedMainNavigation', () => {
describe('When we are in pix-site and we have the site navigation', () => {
beforeEach(() => {
store = {
state: {
mainNavigations: [expectedSiteNavigation, expectedProNavigation],
},
}
})

it('should return the site navigation', () => {
// given
component = shallowMount(NavigationSliceZone, {
mocks: {
$store: store,
data() {
return {
mainNavigations: [
expectedSiteNavigation,
expectedProNavigation,
],
}
},
stubs,
})
Expand All @@ -96,18 +92,18 @@ describe('NavigationSliceZone', () => {
process.env = {
isPixPro: true,
}
store = {
state: {
mainNavigations: [expectedSiteNavigation, expectedProNavigation],
},
}
})

it('should return the pro navigation', () => {
// given
component = shallowMount(NavigationSliceZone, {
mocks: {
$store: store,
data() {
return {
mainNavigations: [
expectedSiteNavigation,
expectedProNavigation,
],
}
},
stubs,
})
Expand All @@ -125,18 +121,13 @@ describe('NavigationSliceZone', () => {
process.env = {
isPixPro: true,
}
store = {
state: {
mainNavigations: [expectedSiteNavigation],
},
}
})

it('should return the site navigation', () => {
// given
component = shallowMount(NavigationSliceZone, {
mocks: {
$store: store,
data() {
return { mainNavigations: [expectedSiteNavigation] }
},
stubs,
})
Expand Down