Merge pull request #1530 from Budibase/enhance-email-preview

Enhance email preview
This commit is contained in:
Andrew Kingston 2021-05-21 14:43:48 +01:00 committed by GitHub
commit 4add50287e
4 changed files with 26 additions and 11 deletions

View File

@ -9,8 +9,6 @@
StatusLight, StatusLight,
} from "@budibase/bbui" } from "@budibase/bbui"
import { gradient } from "actions" import { gradient } from "actions"
import { auth } from "stores/portal"
import { AppStatus } from "constants"
export let app export let app
export let exportApp export let exportApp

View File

@ -8,7 +8,6 @@
MenuItem, MenuItem,
StatusLight, StatusLight,
} from "@budibase/bbui" } from "@budibase/bbui"
import { auth } from "stores/portal"
export let app export let app
export let exportApp export let exportApp

View File

@ -22,11 +22,13 @@
let htmlEditor let htmlEditor
let mounted = false let mounted = false
$: selectedTemplate = $email?.templates?.find( $: selectedTemplate = $email.templates?.find(
({ purpose }) => purpose === template ({ purpose }) => purpose === template
) )
$: baseTemplate = $email.templates?.find(({ purpose }) => purpose === "base")
$: templateBindings = $: templateBindings =
$email.definitions?.bindings?.[selectedTemplate.purpose] || [] $email.definitions?.bindings?.[selectedTemplate.purpose] || []
$: previewContent = makePreviewContent(baseTemplate, selectedTemplate)
async function saveTemplate() { async function saveTemplate() {
try { try {
@ -41,12 +43,23 @@
function setTemplateBinding(binding) { function setTemplateBinding(binding) {
htmlEditor.update((selectedTemplate.contents += `{{ ${binding.name} }}`)) htmlEditor.update((selectedTemplate.contents += `{{ ${binding.name} }}`))
} }
const makePreviewContent = (baseTemplate, selectedTemplate) => {
if (!selectedTemplate) {
return ""
}
if (selectedTemplate.purpose === "base") {
return selectedTemplate.contents
}
const base = baseTemplate?.contents ?? ""
return base.replace("{{ body }}", selectedTemplate?.contents ?? "")
}
onMount(() => { onMount(() => {
mounted = true mounted = true
}) })
async function fixMountBug({ detail }) { async function fixMountBug({ detail }) {
console.log(detail)
if (detail === "Edit") { if (detail === "Edit") {
await tick() await tick()
mounted = true mounted = true
@ -112,11 +125,11 @@
</Tabs> </Tabs>
{/if} {/if}
</div> </div>
</div></Tab </div>
> </Tab>
<Tab title="Preview"> <Tab title="Preview">
<div class="preview"> <div class="preview">
{@html selectedTemplate?.contents} <iframe srcdoc={previewContent} />
</div> </div>
</Tab> </Tab>
</Tabs> </Tabs>
@ -138,8 +151,13 @@
} }
.preview { .preview {
background: white;
height: 800px; height: 800px;
padding: var(--spacing-xl); padding: var(--spacing-xl) 0;
position: relative;
}
iframe {
width: 100%;
height: 100%;
border: none;
} }
</style> </style>

View File

@ -2,7 +2,7 @@ import { writable } from "svelte/store"
import api from "builderStore/api" import api from "builderStore/api"
export function createEmailStore() { export function createEmailStore() {
const store = writable([]) const store = writable({})
return { return {
subscribe: store.subscribe, subscribe: store.subscribe,