Skip to content

Commit 185839f

Browse files
committed
feat: added playground draft
1 parent a7bcb3b commit 185839f

File tree

1 file changed

+50
-6
lines changed

1 file changed

+50
-6
lines changed

web/src/routes/play/+page.svelte

+50-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,58 @@
11
<script lang="ts">
2-
import Combobox from "$lib/components/ui/combobox/combobox.svelte";
2+
import {Textarea} from "$lib/components/ui/textarea"
3+
import {cn} from "$lib/utils";
4+
5+
let template: string
6+
let parsedTemplate: string = ""
7+
let errors: string[] = []
8+
9+
const api = "https://api.gttp.dev/api/v1/parse"
10+
11+
function keyDown(e: KeyboardEvent) {
12+
if (e.key === "Tab") {
13+
e.preventDefault()
14+
const start = this.selectionStart
15+
const end = this.selectionEnd
16+
template = template.substring(0, start) + " " + template.substring(end)
17+
this.selectionStart = this.selectionEnd = start + 2
18+
}
19+
20+
fetch(api, {
21+
method: "POST",
22+
headers: {
23+
"Content-Type": "application/json"
24+
},
25+
body: JSON.stringify({template})
26+
}).then(res => res.json()).then(data => {
27+
parsedTemplate = data.rendered
28+
errors = []
29+
errors = data.errors
30+
})
31+
}
332
</script>
433
<div class="flex justify-center">
534
<div class="max-w-screen-lg w-full px-8">
635
<div>
7-
<Combobox options={[
8-
{value: "a", label: "A"},
9-
{value: "b", label: "B"},
10-
{value: "c", label: "C"},
11-
]} multi={true}/>
36+
<Textarea
37+
on:keyup={keyDown}
38+
class={cn("h-96")}
39+
bind:value={template}
40+
/>
41+
</div>
42+
<div class="mt-16">
43+
{#if errors && errors.length > 0}
44+
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative" role="alert">
45+
<strong class="font-bold">Error</strong>
46+
<ul class="list-disc list-inside">
47+
{#each errors as error}
48+
<li>{error}</li>
49+
{/each}
50+
</ul>
51+
</div>
52+
{/if}
53+
<pre>
54+
{parsedTemplate}
55+
</pre>
1256
</div>
1357
</div>
1458
</div>

0 commit comments

Comments
 (0)