diff --git a/demo/app/Sharp/Posts/PostForm.php b/demo/app/Sharp/Posts/PostForm.php index bd0c6538f..e7538daea 100644 --- a/demo/app/Sharp/Posts/PostForm.php +++ b/demo/app/Sharp/Posts/PostForm.php @@ -233,6 +233,12 @@ public function update($id, array $data) ->ignore(auth()->user()->isAdmin() ? [] : ['author_id']) ->save($post, $data); + if ($this->isPreview) { + return view('pages.post', [ + 'post' => $post, + ]); + } + if (sharp()->context()->isCreation()) { $this->notify('Your post was created, but not published yet.'); } diff --git a/resources/js/Pages/Form/Form.vue b/resources/js/Pages/Form/Form.vue index bb8e4c1eb..a08b868f3 100644 --- a/resources/js/Pages/Form/Form.vue +++ b/resources/js/Pages/Form/Form.vue @@ -12,6 +12,7 @@ import { Button } from '@/components/ui/button'; import { useResizeObserver } from "@vueuse/core"; import { slugify } from "@/utils"; + import { api } from "@/api/api"; const props = defineProps<{ form: FormData, @@ -71,6 +72,18 @@ }); } }, { immediate: true }); + + const previewHtml = ref(''); + let timeout: number; + watch(() => form.data, () => { + clearTimeout(timeout); + timeout = window.setTimeout(() => { + api.post(route('code16.sharp.api.form.preview', { entityKey, instanceId }), form.data) + .then(response => { + previewHtml.value = response.data.data.html; + }); + }, timeout ? 200 : 0); + }, { immediate: true, deep: true });