Clean up thread create initial values

This commit is contained in:
Jon Staab 2026-08-17 11:18:38 -07:00
parent dfb971e7dd
commit b06b855a42
3 changed files with 20 additions and 18 deletions

View file

@ -1,6 +1,7 @@
<script lang="ts">
import * as nip19 from "nostr-tools/nip19"
import type {TrustedEvent} from "@welshman/util"
import {tagSpec, tagValue} from "@welshman/util"
import {tagSpec, tagValue, toNostrURI} from "@welshman/util"
import Code2 from "@assets/icons/code-2.svg?dataurl"
import GalleryWide from "@assets/icons/gallery-wide.svg?dataurl"
import TrashBin2 from "@assets/icons/trash-bin-2.svg?dataurl"
@ -42,7 +43,11 @@
const createThread = () => {
onClick()
pushModal(ThreadCreate, {url, h, parent: event})
pushModal(ThreadCreate, {
url,
h,
initialValues: {content: toNostrURI(nip19.neventEncode({...event, relays: [url]}))},
})
}
const report = () => {

View file

@ -1,7 +1,8 @@
<script lang="ts">
import type {NativeEmoji} from "emoji-picker-element/shared"
import type {TrustedEvent} from "@welshman/util"
import {getIdOrAddress, tagSpec, tagValue} from "@welshman/util"
import * as nip19 from "nostr-tools/nip19"
import {getIdOrAddress, tagSpec, tagValue, toNostrURI} from "@welshman/util"
import Bolt from "@assets/icons/bolt.svg?dataurl"
import Reply from "@assets/icons/reply-2.svg?dataurl"
import Code2 from "@assets/icons/code-2.svg?dataurl"
@ -52,7 +53,12 @@
const showEmojiPicker = () => pushModal(EmojiPicker, {onClick: onEmoji}, {replaceState: true})
const createThread = () => pushModal(ThreadCreate, {url, h, parent: event}, {replaceState: true})
const createThread = () =>
pushModal(
ThreadCreate,
{url, h, initialValues: {content: toNostrURI(nip19.neventEncode({...event, relays: [url]}))}},
{replaceState: true},
)
const sendReply = () => {
history.back()

View file

@ -1,10 +1,7 @@
<script lang="ts">
import {writable} from "svelte/store"
import * as nip19 from "nostr-tools/nip19"
import {Thread} from "@welshman/domain"
import {publish} from "@welshman/app"
import {toNostrURI} from "@welshman/util"
import type {TrustedEvent} from "@welshman/util"
import {isMobile, preventDefault} from "@lib/html"
import Paperclip from "@assets/icons/paperclip-2.svg?dataurl"
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
@ -34,18 +31,12 @@
url: string
h?: string
shareToChat?: boolean
// pre-fills the thread body with an embedded quote of this event (see
// "Create a Thread" in RoomItemMenu/RoomItemMenuMobile) — an unrelated
// in-progress draft still wins, same as opening this modal any other way.
parent?: TrustedEvent
initialValues?: Values
}
const {url, h, shareToChat = false, parent}: Props = $props()
const pointerContent = parent
? toNostrURI(nip19.neventEncode({...parent, relays: [url]}))
: undefined
const {url, h, shareToChat = false, initialValues}: Props = $props()
const draftKey = new DraftKey<Values>(`thread:${url}:${h ?? ""}`)
const initialValues = draftKey.get()
const draft = draftKey.get()
const shouldProtect = $relays.hasNip(url, 70)
const uploading = writable(false)
@ -109,8 +100,8 @@
let loading = $state(false)
let title = $state(initialValues?.title ?? "")
let content = $state(initialValues?.content ?? pointerContent ?? "")
let title = $state(initialValues?.title ?? draft?.title ?? "")
let content = $state(initialValues?.content ?? draft?.content ?? "")
const onChange = (json: object) => {
content = json