persist drafts in memory (#155)

Co-authored-by: userAdityaa <aditya.chaudhary1558@gmail.com>
Co-committed-by: userAdityaa <aditya.chaudhary1558@gmail.com>
This commit is contained in:
2026-04-07 12:06:29 +00:00
committed by hodlbod
parent 0547e9513f
commit 30c2a6ef79
12 changed files with 257 additions and 55 deletions
+20 -1
View File
@@ -12,6 +12,7 @@
import ComposeMenu from "@app/components/ComposeMenu.svelte"
import EditorContent from "@app/editor/EditorContent.svelte"
import {makeEditor} from "@app/editor"
import {DraftKey} from "@app/util/drafts"
import {onDestroy, onMount} from "svelte"
type Props = {
@@ -25,6 +26,11 @@
const {url, h, content, onEscape, onEditPrevious, onSubmit}: Props = $props()
type ComposeDraft = {content?: unknown}
const draftKey = url || h ? new DraftKey<ComposeDraft>(`room:${url ?? ""}:${h ?? ""}`) : undefined
const draft = draftKey?.get()
const autofocus = !isMobile
const uploading = writable(false)
@@ -61,10 +67,23 @@
onSubmit({content, tags})
draftKey?.clear()
ed.chain().clearContent().run()
}
const editor = makeEditor({url, content, autofocus, submit, uploading, aggressive: true})
const onChange = (json: unknown) => {
draftKey?.set({content: json})
}
const editor = makeEditor({
url,
content: content ?? (draft?.content as string | object | undefined),
autofocus,
submit,
uploading,
onChange,
aggressive: true,
})
let popover: Instance | undefined = $state()