Skip to content

Commit 0a4ca92

Browse files
committed
feat: reload the preview if the layoutId has changed
1 parent 9a1e1f7 commit 0a4ca92

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

app/frontend/editor/components/page/edit.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ export default {
5858
},
5959
]
6060
},
61+
hasLayoutIdChanged() {
62+
return this.editedPage.layoutId !== this.page.layoutId
63+
}
6164
},
6265
methods: {
6366
updatePage() {
@@ -74,6 +77,9 @@ export default {
7477
...attributes,
7578
lockVersion: headers['page-lock-version'],
7679
})
80+
81+
if (this.hasLayoutIdChanged)
82+
this.$store.dispatch('reloadPage', { id: pageId })
7783
})
7884
.catch(({ response: { status, data } }) => {
7985
console.log('[Maglev] could not update the page', status)

app/frontend/editor/design/components/modal.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
}
2121

2222
.modal-body {
23-
@apply flex flex-col flex-1 overflow-y-visible pt-4;
23+
@apply flex flex-col flex-1 overflow-y-auto pt-4;
2424
}
2525

2626
/*

app/frontend/editor/services/live-preview.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ export const start = (newIframe) => {
6767
listenMessages()
6868
}
6969

70+
export const reload = () => {
71+
if (!iframe) return
72+
iframe.contentWindow.location.reload()
73+
}
74+
7075
const listenMessages = () => {
7176
window.addEventListener('message', ({ data: { type, ...data } }) => {
7277
// a message MUST have a type

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ export default (services) => ({
44
// editPage : Action triggered when the user wants to edit another page
55
// or to change the locale of the current page.
66
async editPage({ state, dispatch }, { id, locale }) {
7-
console.log('editPage', id, locale)
8-
97
// display the loader
108
dispatch('resetPreview')
119

12-
if (state.locale !== locale) {
10+
if (locale && state.locale !== locale) {
1311
dispatch('setLocale', locale)
1412
await Promise.all([dispatch('fetchPage', id), dispatch('fetchSite')])
1513
} else await dispatch('fetchPage', id)
@@ -21,6 +19,13 @@ export default (services) => ({
2119
setPage({ commit }, page) {
2220
commit('SET_PAGE', page)
2321
},
22+
23+
// Reload a page: get fresh content + reload the preview iframe
24+
async reloadPage({ state, dispatch }, { id }) {
25+
await dispatch('editPage', { id })
26+
services.livePreview.reload()
27+
},
28+
2429
// Fetch a page from an id (or a path)
2530
async fetchPage({ commit, state: { site } }, id) {
2631
return services.page

0 commit comments

Comments
 (0)