forked from coracle/flotilla
feat: persist composer drafts in memory across navigation
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
import EditorContent from "@app/editor/EditorContent.svelte"
|
||||
import {PROTECTED} from "@app/core/state"
|
||||
import {makeEditor} from "@app/editor"
|
||||
import {getDraft, setDraft, clearDraft} from "@app/util/drafts"
|
||||
import {pushToast} from "@app/util/toast"
|
||||
import {canEnforceNip70} from "@app/core/commands"
|
||||
|
||||
@@ -37,7 +38,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
const {url, h, header, initialValues}: Props = $props()
|
||||
let {url, h, header, initialValues}: Props = $props()
|
||||
|
||||
const draftKey = `calendar:${url}:${h ?? ""}`
|
||||
const draft = getDraft(draftKey)
|
||||
if (!initialValues) {
|
||||
initialValues = draft as unknown as typeof initialValues
|
||||
}
|
||||
|
||||
const shouldProtect = canEnforceNip70(url)
|
||||
|
||||
@@ -95,17 +102,34 @@
|
||||
|
||||
pushToast({message: "Your event has been saved!"})
|
||||
publishThunk({event, relays: [url]})
|
||||
clearDraft(draftKey)
|
||||
history.back()
|
||||
}
|
||||
|
||||
const content = initialValues?.content || ""
|
||||
const editor = makeEditor({url, submit, uploading, content})
|
||||
const onChange = (json: unknown) => {
|
||||
setDraft(draftKey, {editorContent: json, title, location})
|
||||
}
|
||||
const editor = makeEditor({
|
||||
url,
|
||||
submit,
|
||||
uploading,
|
||||
onChange,
|
||||
content: draft.editorContent ?? initialValues?.content ?? "",
|
||||
})
|
||||
|
||||
let title = $state(initialValues?.title || "")
|
||||
let location = $state(initialValues?.location || "")
|
||||
let title = $state(initialValues?.title ?? "")
|
||||
let location = $state(initialValues?.location ?? "")
|
||||
let start: number | undefined = $state(initialValues?.start)
|
||||
let end: number | undefined = $state(initialValues?.end)
|
||||
let endDirty = Boolean(initialValues?.end)
|
||||
let endDirty = $state(Boolean(initialValues?.end))
|
||||
|
||||
$effect(() => {
|
||||
setDraft(draftKey, {
|
||||
...getDraft(draftKey),
|
||||
title,
|
||||
location,
|
||||
})
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
if (!endDirty && start) {
|
||||
|
||||
Reference in New Issue
Block a user