refactor editor file

This commit is contained in:
2026-01-15 15:09:01 +13:00
parent fc7cd5a60a
commit dad55dab39
4 changed files with 125 additions and 56 deletions

View File

@@ -0,0 +1,31 @@
<div id="editor" />
<script>
import Quill from "quill";
import { uploadEntry } from '../utils/quill'
import type { Entry } from "../utils/quill";
const quill = new Quill('#editor', {
modules: {
toolbar: [
['bold', 'italic', 'underline'],
['image']
],
},
placeholder: 'Compose an epic...',
theme: 'snow', // or 'bubble'
});
document.querySelector("#upload")?.addEventListener('click', async () => {
const contents = quill.getContents()
let entry: Entry = {
content: contents,
date: '2026-01-13T10:49:43Z',
location: null
}
await uploadEntry(entry)
})
</script>

View File

@@ -1,64 +1,10 @@
---
import "../styles/global.css"
import Layout from "../component/core/layout.astro"
import Editor from "../component/editor.astro"
---
<script>
import Quill from "quill";
import { uploadEntry } from '../utils/quill'
import type { Entry } from "../utils/quill";
const quill = new Quill('#editor', {
modules: {
toolbar: [
['bold', 'italic', 'underline'],
['image']
],
},
placeholder: 'Compose an epic...',
theme: 'snow', // or 'bubble'
});
document.querySelector("#upload")?.addEventListener('click', async () => {
const contents = quill.getContents()
let entry: Entry = {
content: contents,
date: '2026-01-13T10:49:43Z',
location: null
}
await uploadEntry(entry)
})
</script>
<script>
const el = document.getElementById('result')
document.querySelector('#export')?.addEventListener('click', async () => {
const res = await fetch('/api/entry/all')
const js = await res.json()
el!.innerText = JSON.stringify(js)
})
</script>
<Layout>
<div id="editor">
<p>Hello World!</p>
<p>Some initial <strong>bold</strong> text</p>
<p><br /></p>
</div>
<button id="upload" class="mt-2">
upload
</button>
<button id="export" class="mt-2">
export all
</button>
<div id="result">
</div>
</Layout>