persist drafts in memory (#155)

Co-authored-by: userAdityaa <aditya.chaudhary1558@gmail.com>
Co-committed-by: userAdityaa <aditya.chaudhary1558@gmail.com>
This commit was merged in pull request #155.
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
+15 -1
View File
@@ -10,10 +10,14 @@
import {publishComment, canEnforceNip70} from "@app/core/commands"
import {PROTECTED} from "@app/core/state"
import {makeEditor} from "@app/editor"
import {DraftKey} from "@app/util/drafts"
import {pushToast} from "@app/util/toast"
const {url, event, onClose, onSubmit} = $props()
const draftKey = new DraftKey<{content?: unknown}>(`reply:${event.id}`)
const draft = draftKey.get()
const shouldProtect = canEnforceNip70(url)
const uploading = writable(false)
@@ -38,10 +42,20 @@
})
}
draftKey.clear()
onSubmit(publishComment({event, content, tags, relays: [url]}))
}
const editor = makeEditor({url, submit, uploading, autofocus: !isMobile})
const onChange = (json: unknown) => draftKey.set({content: json})
const editor = makeEditor({
url,
submit,
uploading,
autofocus: !isMobile,
content: draft?.content as string | object | undefined,
onChange,
})
let form: HTMLElement
let spacer: HTMLElement