Skip to content

Commit 2eae0f9

Browse files
committed
fix: the canAddMirrorSection method wasn't taking the current number of pages in count
1 parent ca7c353 commit 2eae0f9

File tree

9 files changed

+28
-53
lines changed

9 files changed

+28
-53
lines changed

app/frontend/editor/components/page/list/index.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
</template>
1919

2020
<script>
21+
import { mapActions } from 'vuex'
2122
import GroupedDropdownsMixin from '@/mixins/grouped-dropdowns'
2223
import ListItem from './list-item.vue'
2324
@@ -40,9 +41,11 @@ export default {
4041
},
4142
},
4243
methods: {
44+
...mapActions(['setOneSinglePage']),
4345
async fetch() {
4446
this.isLoading = true
4547
this.pages = await this.services.page.findAll({ q: this.q })
48+
this.setOneSinglePage(this.previewablePages.length === 1)
4649
this.isLoading = false
4750
},
4851
},

app/frontend/editor/components/theme-section-list/index.vue

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,16 @@ export default {
5858
return { activeCategory: null }
5959
},
6060
computed: {
61-
...mapGetters(['categoriesByLayoutGroupId', 'layoutGroupDefinition']),
61+
...mapGetters(['categoriesByLayoutGroupId', 'layoutGroupDefinition', 'canAddMirroredSection']),
6262
categories() {
6363
return this.categoriesByLayoutGroupId(this.layoutGroupId)
6464
},
6565
noCategories() {
6666
return this.categories.length === 0
6767
},
68-
canAddMirroredSection() {
69-
return this.services.section.canAddMirroredSection({
70-
numberOfPages: this.currentSite.numberOfPages
71-
})
72-
},
73-
layoutGroup() {
74-
return this.layoutGroupDefinition(this.layoutGroupId)
75-
},
7668
allowSectionMirroring() {
77-
return this.currentTheme.mirrorSection && this.layoutGroup.mirrorSection !== false && this.canAddMirroredSection
78-
}
69+
return this.canAddMirroredSection(this.layoutGroupId)
70+
},
7971
},
8072
}
8173
</script>

app/frontend/editor/services/section.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export const calculateMovingIndices = (sectionIds, sectionId, direction) => {
1515
return { fromIndex, toIndex }
1616
}
1717

18-
export const canAddMirroredSection = ({ numberOfPages, page, sections, mirrorOf }) => {
19-
if (numberOfPages === 1) return false
18+
export const canAddMirroredSection = ({ hasOneSinglePage, page, sections, mirrorOf }) => {
19+
if (hasOneSinglePage) return false
2020

2121
// when canAddMirroredSection is called from the list of sections, let's assume everything is good
2222
if (mirrorOf === undefined) return true

app/frontend/editor/store/actions/page.js

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ export default (services) => ({
2020
commit('SET_PAGE', page)
2121
},
2222

23+
// Set the oneSinglePage flag
24+
setOneSinglePage({ commit }, oneSinglePage) {
25+
commit('SET_ONE_SINGLE_PAGE', oneSinglePage)
26+
},
27+
2328
// Reload a page: get fresh content + reload the preview iframe
2429
async reloadPage({ state, dispatch }, { id }) {
2530
await dispatch('editPage', { id })
@@ -32,43 +37,6 @@ export default (services) => ({
3237
.findById(site, id)
3338
.then((page) => commit('SET_PAGE', page))
3439
},
35-
// Persist the content of a page (including or not the site content)
36-
// async persistPage({
37-
// commit,
38-
// dispatch,
39-
// state: { page, site, style },
40-
// getters: { content, defaultPageAttributes },
41-
// }) {
42-
// console.log('🚨🚨🚨 services.page.persistPage is DEPRECATED')
43-
44-
// commit('SET_SAVE_BUTTON_STATE', 'inProgress')
45-
46-
// const pageAttributes = {
47-
// sections: content.pageSections,
48-
// lockVersion: page.lockVersion,
49-
// ...defaultPageAttributes,
50-
// }
51-
// const siteAttributes = isBlank(content.siteSections)
52-
// ? { style }
53-
// : {
54-
// sections: content.siteSections,
55-
// lockVersion: site.lockVersion,
56-
// style,
57-
// }
58-
59-
// return services.page
60-
// .update(page.id, pageAttributes, siteAttributes)
61-
// .then(() => {
62-
// commit('SET_SAVE_BUTTON_STATE', 'success')
63-
// commit('RESET_TOUCHED_SECTIONS')
64-
// Promise.all([dispatch('fetchPage', page.id), dispatch('fetchSite')])
65-
// })
66-
// .catch(({ response: { status } }) => {
67-
// commit('SET_SAVE_BUTTON_STATE', 'fail')
68-
// console.log('[Maglev] could not save the page', status)
69-
// if (status === 409) commit('OPEN_ERROR_MODAL', 'staleRecord')
70-
// })
71-
// },
7240
setCurrentPageSettings({ commit }, pageSettings) {
7341
commit('SET_PAGE_SETTINGS', pageSettings)
7442
},

app/frontend/editor/store/actions/section.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,5 @@ export default (services) => ({
135135
direction,
136136
)
137137
dispatch('moveSection', { layoutGroupId, from: indices.fromIndex, to: indices.toIndex })
138-
},
138+
}
139139
})

app/frontend/editor/store/actions/site.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export default (services) => ({
55
services.api.setSiteHandle(site.handle)
66
commit('SET_SITE', rawSite)
77
commit('SET_STYLE', style)
8+
commit('SET_ONE_SINGLE_PAGE', site.numberOfPages === 1)
89
})
910
},
1011
loadPublishButtonState({ state, commit }) {

app/frontend/editor/store/default-state.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default {
1818
siteScopedSections: {}, // site-wide sections like headers/footers
1919
editorSettings: {},
2020
touchedSections: [],
21+
oneSinglePage: true,
2122
ui: {
2223
saveButtonState: 'default',
2324
publishButtonState: {

app/frontend/editor/store/getters.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,16 @@ export default (services) => ({
178178
return services.section.getSettings(sectionBlockDefinition, advanced)
179179
},
180180
canAddSection:
181-
({ theme, page: { layoutId } }, { categoriesByLayoutGroupId }) =>
181+
({}, { categoriesByLayoutGroupId }) =>
182182
(layoutGroupId) => {
183183
const categories = categoriesByLayoutGroupId(layoutGroupId)
184184
return categories.some(({ children }) => children.length > 0)
185-
}
185+
},
186+
canAddMirroredSection: ({ theme, oneSinglePage }, { layoutGroupDefinition }) =>
187+
(layoutGroupId) => {
188+
const layoutGroup = layoutGroupDefinition(layoutGroupId)
189+
return theme.mirrorSection && layoutGroup.mirrorSection !== false && services.section.canAddMirroredSection({
190+
hasOneSinglePage: oneSinglePage
191+
})
192+
},
186193
})

app/frontend/editor/store/mutations.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export default (services) => ({
3838
omitEmpty(attributes)
3939
state.page = { ...state.page, ...attributes }
4040
},
41+
SET_ONE_SINGLE_PAGE(state, oneSinglePage) {
42+
state.oneSinglePage = oneSinglePage
43+
},
4144
// === SECTIONS CONTENT ===
4245
SET_SECTIONS_CONTENT(state, content) {
4346
const { entities, result } = services.sectionsContent.normalize(content)

0 commit comments

Comments
 (0)