refactor editor file
This commit is contained in:
@@ -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>
|
||||
Reference in New Issue
Block a user