feat(frontend): Add app preview (#993)

This commit is contained in:
Faton Ramadani
2022-12-05 14:48:07 +01:00
committed by GitHub
parent 9138cd247c
commit 50e19f2b57
2 changed files with 71 additions and 4 deletions

View File

@@ -0,0 +1,66 @@
<script lang="ts">
import { onMount, setContext } from 'svelte'
import { writable } from 'svelte/store'
import { buildWorld, type World } from '../rx'
import type {
App,
AppEditorContext,
ConnectingInput,
EditorBreakpoint,
EditorMode,
InputType
} from '../types'
import GridEditor from './GridEditor.svelte'
import { classNames } from '$lib/utils'
export let app: App
export let initialMode: EditorMode = 'dnd'
const appStore = writable<App>(app)
const worldStore = writable<World | undefined>(undefined)
const staticOutputs = writable<Record<string, string[]>>({})
const selectedComponent = writable<string | undefined>(undefined)
const mode = writable<EditorMode>(initialMode)
const breakpoint = writable<EditorBreakpoint>('lg')
const connectingInput = writable<ConnectingInput<InputType, any>>({
opened: false,
input: undefined
})
setContext<AppEditorContext>('AppEditorContext', {
worldStore,
staticOutputs,
app: appStore,
selectedComponent,
mode,
connectingInput,
breakpoint
})
function clearSelectionOnPreview() {
if ($mode === 'preview') {
$selectedComponent = undefined
}
}
let mounted = false
onMount(() => {
mounted = true
})
$: mounted && ($worldStore = buildWorld($staticOutputs))
$: $mode && $selectedComponent && clearSelectionOnPreview()
$: width = $breakpoint === 'sm' ? 'w-[640px]' : 'w-full '
</script>
<div class="h-full w-full">
{#if $appStore.grid}
<div class={classNames('mx-auto h-full', width)}>
<GridEditor />
</div>
{/if}
</div>

View File

@@ -9,6 +9,7 @@
<script lang="ts">
import { page } from '$app/stores'
import AppEditor from '$lib/components/apps/editor/AppEditor.svelte'
import AppPreview from '$lib/components/apps/editor/AppPreview.svelte'
import CenteredPage from '$lib/components/CenteredPage.svelte'
import { Skeleton } from '$lib/components/common'
@@ -32,16 +33,16 @@
<CenteredPage>
{#if app}
<div class="flex justify-between my-2 items-center">
<div>{app.value.title}</div>
<div class="flex justify-between items-center py-4">
<h2>{app.value.title}</h2>
<Button size="xs" href="/apps/edit/{$page.params.path}" startIcon={{ icon: faPen }}>
Edit
</Button>
</div>
<div class="h-screen">
<AppEditor app={app.value} path={app.path} initialMode="preview" />
<div class="border rounded-md p-2">
<AppPreview app={app.value} initialMode="preview" />
</div>
{/if}
</CenteredPage>