1
0
Fork 0
mirror of synced 2024-07-06 15:00:49 +12:00

fix preview save

This commit is contained in:
Martin McKeaveney 2020-12-02 13:41:00 +00:00
parent 1c2a869e26
commit ffc7e14bb2
5 changed files with 24 additions and 18 deletions

View file

@ -198,10 +198,11 @@ export const getFrontendStore = () => {
preview: { preview: {
saveSelected: async () => { saveSelected: async () => {
const state = get(store) const state = get(store)
const selectedAsset = get(currentAsset)
if (state.currentFrontEndType !== FrontendTypes.LAYOUT) { if (state.currentFrontEndType !== FrontendTypes.LAYOUT) {
await store.actions.screens.save(currentAsset) await store.actions.screens.save(selectedAsset)
} }
await store.actions.layouts.save(currentAsset) await store.actions.layouts.save(selectedAsset)
}, },
}, },
layouts: { layouts: {
@ -236,9 +237,10 @@ export const getFrontendStore = () => {
await Promise.all(cssPromises) await Promise.all(cssPromises)
}, },
save: async layout => { save: async layout => {
const response = await api.post(`/api/layouts`, { const layoutToSave = cloneDeep(layout)
...layout, delete layoutToSave._css
})
const response = await api.post(`/api/layouts`, layoutToSave)
const json = await response.json() const json = await response.json()

View file

@ -1,5 +1,6 @@
<script> <script>
import { onMount } from "svelte" import { onMount } from "svelte"
import { goto } from "@sveltech/routify"
import { store, currentAsset } from "builderStore" import { store, currentAsset } from "builderStore"
import { FrontendTypes } from "constants" import { FrontendTypes } from "constants"
import api from "builderStore/api" import api from "builderStore/api"
@ -12,17 +13,22 @@
const tabs = [ const tabs = [
{ {
title: "Screens", title: "Screens",
key: "SCREENS", key: "screens",
}, },
{ {
title: "Layouts", title: "Layouts",
key: "LAYOUTS", key: "layouts",
}, },
] ]
let modal let modal
let routes = {} let routes = {}
let tab = "SCREENS" let tab = "screens"
function reroute({ detail }) {
if (!detail) return
$goto(`./${detail.heading.key}`)
}
onMount(() => { onMount(() => {
store.actions.routing.fetch() store.actions.routing.fetch()
@ -30,8 +36,8 @@
</script> </script>
<div class="title"> <div class="title">
<Switcher headings={tabs} bind:value={tab}> <Switcher headings={tabs} bind:value={tab} on:change={reroute}>
{#if tab === 'SCREENS'} {#if tab === 'screens'}
<i <i
on:click={modal.show} on:click={modal.show}
data-cy="new-screen" data-cy="new-screen"
@ -46,7 +52,7 @@
<Modal bind:this={modal}> <Modal bind:this={modal}>
<NewScreenModal /> <NewScreenModal />
</Modal> </Modal>
{:else if tab === 'LAYOUTS'} {:else if tab === 'layouts'}
<Layout /> <Layout />
{/if} {/if}

View file

@ -0,0 +1,4 @@
<script>
// import { goto } from "@sveltech/routify"
// $goto("../layout/main")
</script>

View file

@ -8,12 +8,6 @@
const currentScreenId = decodeURI($params.screen) const currentScreenId = decodeURI($params.screen)
const validScreen = $allScreens.some(screen => screen._id === currentScreenId) const validScreen = $allScreens.some(screen => screen._id === currentScreenId)
console.log({
validScreen,
currentScreenId,
componentIds
})
if (!validScreen) { if (!validScreen) {
// Go to main layout if URL set to invalid screen // Go to main layout if URL set to invalid screen
console.error("Invalid screen", $params.screen) console.error("Invalid screen", $params.screen)
@ -28,7 +22,7 @@
if ($leftover) { if ($leftover) {
console.log("leftover", $params.screen) console.log("leftover", $params.screen)
// Get the correct screen children. // Get the correct screen children.
const screenChildren = allScreens.find( const screenChildren = $allScreens.find(
screen => screen =>
screen._id === $params.screen || screen._id === $params.screen ||
screen._id === decodeURIComponent($params.screen) screen._id === decodeURIComponent($params.screen)