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>
{#if initialValues}
<CalendarEventForm {url} {initialValues}>
<CalendarEventForm {url} h={timeEvent.room()} {initialValues}>
{#snippet header()}
<ModalHeader>
<ModalTitle>Edit this Event</ModalTitle>

View file

@ -53,9 +53,11 @@
defaultEnd,
}: 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()
}
@ -123,7 +125,7 @@
return pushToast({theme: "error", message: error})
}
draftKey.clear()
draftKey?.clear()
history.back()
if (shareToChat) {
@ -153,7 +155,7 @@
const editor = makeEditor({url, submit, uploading, onChange, content})
$effect(() => {
draftKey.set({d, title, location, start, end, content})
draftKey?.set({d, title, location, start, end, content})
})
</script>

View file

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

View file

@ -48,9 +48,11 @@
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()
}
@ -125,7 +127,7 @@
return pushToast({theme: "error", message: error})
}
draftKey.clear()
draftKey?.clear()
history.back()
if (shareToChat) {
@ -157,7 +159,7 @@
const editor = makeEditor({url, submit, onChange, content})
$effect(() => {
draftKey.set({d, title, status, price, currency, images, topics, content})
draftKey?.set({d, title, status, price, currency, images, topics, content})
})
</script>
@ -227,7 +229,7 @@
</div>
{/snippet}
</Field>
{#if initialValues}
{#if editing}
<Field>
{#snippet label()}
<p>Status*</p>

View file

@ -40,17 +40,14 @@
type Props = {
url: string
h?: string
initialValues?: Values
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 ?? ""}`)
if (!initialValues) {
initialValues = draftKey.get()
}
const initialValues = draftKey.get()
const shouldProtect = $relays.hasNip(url, 70)