Keep an edited listing or calendar event in its room and stop edits from writing the create draft

This commit is contained in:
Jon Staab 2026-09-25 15:45:19 -07:00
parent c49650bbca
commit aabd41e017
5 changed files with 17 additions and 16 deletions

View file

@ -29,7 +29,7 @@
</script> </script>
{#if initialValues} {#if initialValues}
<CalendarEventForm {url} {initialValues}> <CalendarEventForm {url} h={timeEvent.room()} {initialValues}>
{#snippet header()} {#snippet header()}
<ModalHeader> <ModalHeader>
<ModalTitle>Edit this Event</ModalTitle> <ModalTitle>Edit this Event</ModalTitle>

View file

@ -53,9 +53,11 @@
defaultEnd, defaultEnd,
}: Props = $props() }: Props = $props()
const draftKey = new DraftKey<Values>(`calendar:${url}:${h ?? ""}`) // An edit starts from the event, and saving it as a draft would carry it into the next create.
const editing = Boolean(initialValues)
const draftKey = editing ? undefined : new DraftKey<Values>(`calendar:${url}:${h ?? ""}`)
if (!initialValues) { if (draftKey) {
initialValues = draftKey.get() initialValues = draftKey.get()
} }
@ -123,7 +125,7 @@
return pushToast({theme: "error", message: error}) return pushToast({theme: "error", message: error})
} }
draftKey.clear() draftKey?.clear()
history.back() history.back()
if (shareToChat) { if (shareToChat) {
@ -153,7 +155,7 @@
const editor = makeEditor({url, submit, uploading, onChange, content}) const editor = makeEditor({url, submit, uploading, onChange, content})
$effect(() => { $effect(() => {
draftKey.set({d, title, location, start, end, content}) draftKey?.set({d, title, location, start, end, content})
}) })
</script> </script>

View file

@ -31,7 +31,7 @@
</script> </script>
{#if initialValues} {#if initialValues}
<ClassifiedForm {url} {initialValues}> <ClassifiedForm {url} h={classified.room()} {initialValues}>
{#snippet header()} {#snippet header()}
<ModalHeader> <ModalHeader>
<ModalTitle>Edit this Listing</ModalTitle> <ModalTitle>Edit this Listing</ModalTitle>

View file

@ -48,9 +48,11 @@
let {url, h, shareToChat = false, header, initialValues}: Props = $props() let {url, h, shareToChat = false, header, initialValues}: Props = $props()
const draftKey = new DraftKey<Values>(`classified:${url}:${h ?? ""}`) // An edit starts from the event, and saving it as a draft would carry it into the next create.
const editing = Boolean(initialValues)
const draftKey = editing ? undefined : new DraftKey<Values>(`classified:${url}:${h ?? ""}`)
if (!initialValues) { if (draftKey) {
initialValues = draftKey.get() initialValues = draftKey.get()
} }
@ -125,7 +127,7 @@
return pushToast({theme: "error", message: error}) return pushToast({theme: "error", message: error})
} }
draftKey.clear() draftKey?.clear()
history.back() history.back()
if (shareToChat) { if (shareToChat) {
@ -157,7 +159,7 @@
const editor = makeEditor({url, submit, onChange, content}) const editor = makeEditor({url, submit, onChange, content})
$effect(() => { $effect(() => {
draftKey.set({d, title, status, price, currency, images, topics, content}) draftKey?.set({d, title, status, price, currency, images, topics, content})
}) })
</script> </script>
@ -227,7 +229,7 @@
</div> </div>
{/snippet} {/snippet}
</Field> </Field>
{#if initialValues} {#if editing}
<Field> <Field>
{#snippet label()} {#snippet label()}
<p>Status*</p> <p>Status*</p>

View file

@ -40,17 +40,14 @@
type Props = { type Props = {
url: string url: string
h?: string h?: string
initialValues?: Values
shareToChat?: boolean shareToChat?: boolean
} }
let {url, h, initialValues, shareToChat = false}: Props = $props() const {url, h, shareToChat = false}: Props = $props()
const draftKey = new DraftKey<Values>(`goal:${url}:${h ?? ""}`) const draftKey = new DraftKey<Values>(`goal:${url}:${h ?? ""}`)
if (!initialValues) { const initialValues = draftKey.get()
initialValues = draftKey.get()
}
const shouldProtect = $relays.hasNip(url, 70) const shouldProtect = $relays.hasNip(url, 70)