2026-06-23 23:30:54 +00:00
|
|
|
<script module lang="ts">
|
|
|
|
|
export type PinFormValues = {
|
|
|
|
|
title: string
|
|
|
|
|
topics: string[]
|
|
|
|
|
value: string
|
2026-07-06 18:53:12 +00:00
|
|
|
content: string
|
2026-06-23 23:30:54 +00:00
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<script lang="ts">
|
2026-07-06 18:53:12 +00:00
|
|
|
import {writable} from "svelte/store"
|
2026-08-18 21:44:43 +00:00
|
|
|
import {slide} from "@lib/transition"
|
2026-06-23 23:30:54 +00:00
|
|
|
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
|
2026-07-06 18:53:12 +00:00
|
|
|
import GallerySend from "@assets/icons/gallery-send.svg?dataurl"
|
2026-06-23 23:30:54 +00:00
|
|
|
import Spinner from "@lib/components/Spinner.svelte"
|
|
|
|
|
import Button from "@lib/components/Button.svelte"
|
|
|
|
|
import Field from "@lib/components/Field.svelte"
|
|
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
|
|
|
|
import Modal from "@lib/components/Modal.svelte"
|
|
|
|
|
import ModalBody from "@lib/components/ModalBody.svelte"
|
|
|
|
|
import ModalHeader from "@lib/components/ModalHeader.svelte"
|
|
|
|
|
import ModalTitle from "@lib/components/ModalTitle.svelte"
|
|
|
|
|
import ModalSubtitle from "@lib/components/ModalSubtitle.svelte"
|
|
|
|
|
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
|
|
|
|
import StringMultiInput from "@lib/components/StringMultiInput.svelte"
|
|
|
|
|
import RelayName from "@app/components/RelayName.svelte"
|
2026-07-06 18:53:12 +00:00
|
|
|
import EditorContent from "@app/editor/EditorContent.svelte"
|
|
|
|
|
import {makeEditor} from "@app/editor"
|
2026-06-23 23:30:54 +00:00
|
|
|
import {pushToast} from "@app/toast"
|
2026-07-02 18:36:05 +00:00
|
|
|
import {clearModals} from "@app/modal"
|
2026-06-23 23:30:54 +00:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
url: string
|
|
|
|
|
heading: string
|
|
|
|
|
action: string
|
|
|
|
|
successMessage: string
|
|
|
|
|
values?: Partial<PinFormValues>
|
|
|
|
|
submit: (values: PinFormValues) => Promise<string | undefined>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const {url, heading, action, successMessage, values = {}, submit}: Props = $props()
|
|
|
|
|
|
|
|
|
|
let title = $state(values.title ?? "")
|
|
|
|
|
let topics = $state<string[]>(values.topics ?? [])
|
|
|
|
|
let value = $state(values.value ?? "")
|
2026-07-06 18:53:12 +00:00
|
|
|
let content = $state<string | object>(values.content ?? "")
|
2026-06-23 23:30:54 +00:00
|
|
|
let loading = $state(false)
|
|
|
|
|
|
2026-07-06 18:53:12 +00:00
|
|
|
const uploading = writable(false)
|
|
|
|
|
|
2026-06-23 23:30:54 +00:00
|
|
|
const back = () => history.back()
|
|
|
|
|
|
|
|
|
|
const onSubmit = async () => {
|
|
|
|
|
loading = true
|
|
|
|
|
|
|
|
|
|
try {
|
2026-07-06 18:53:12 +00:00
|
|
|
const ed = await editor
|
|
|
|
|
const description = ed.getText({blockSeparator: "\n"}).trim()
|
|
|
|
|
const error = await submit({title, topics, value, content: description})
|
2026-06-23 23:30:54 +00:00
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
pushToast({theme: "error", message: error})
|
|
|
|
|
} else {
|
|
|
|
|
pushToast({message: successMessage})
|
2026-07-02 18:36:05 +00:00
|
|
|
clearModals()
|
2026-06-23 23:30:54 +00:00
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
loading = false
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-07-06 18:53:12 +00:00
|
|
|
|
|
|
|
|
const onChange = (json: object) => {
|
|
|
|
|
content = json
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const editor = makeEditor({url, submit: onSubmit, uploading, onChange, content})
|
|
|
|
|
|
|
|
|
|
const selectFiles = () => editor.then(ed => ed.chain().selectFiles().run())
|
2026-06-23 23:30:54 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<Modal>
|
|
|
|
|
<ModalBody>
|
|
|
|
|
<ModalHeader>
|
|
|
|
|
<ModalTitle>{heading}</ModalTitle>
|
|
|
|
|
<ModalSubtitle>on <RelayName {url} class="text-primary" /></ModalSubtitle>
|
|
|
|
|
</ModalHeader>
|
|
|
|
|
<Field>
|
|
|
|
|
{#snippet label()}
|
|
|
|
|
Link
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet info()}
|
2026-07-27 22:16:21 +00:00
|
|
|
<p>A URL or nostr link (note, nevent, naddr, npub, or nprofile).</p>
|
2026-06-23 23:30:54 +00:00
|
|
|
{/snippet}
|
|
|
|
|
{#snippet input()}
|
2026-07-27 22:38:23 +00:00
|
|
|
<input bind:value class="input w-full" placeholder="URL or nevent..." />
|
2026-06-23 23:30:54 +00:00
|
|
|
{/snippet}
|
|
|
|
|
</Field>
|
2026-08-18 21:44:43 +00:00
|
|
|
{#if value.trim()}
|
|
|
|
|
<div transition:slide class="card card-sm flex flex-col gap-4 opacity-75">
|
|
|
|
|
<Field>
|
|
|
|
|
{#snippet label()}
|
|
|
|
|
Title
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet input()}
|
|
|
|
|
<input bind:value={title} class="input w-full" placeholder="Optional title" />
|
|
|
|
|
{/snippet}
|
|
|
|
|
</Field>
|
|
|
|
|
<Field>
|
|
|
|
|
{#snippet label()}
|
|
|
|
|
Description
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet input()}
|
|
|
|
|
<div class="relative z-feature flex gap-2">
|
|
|
|
|
<div class="input-editor grow overflow-hidden">
|
|
|
|
|
<EditorContent {editor} />
|
|
|
|
|
</div>
|
|
|
|
|
<Button
|
|
|
|
|
data-tip="Add an image"
|
|
|
|
|
class="button button-neutral button-input tip"
|
|
|
|
|
onclick={selectFiles}
|
|
|
|
|
disabled={loading}>
|
|
|
|
|
{#if $uploading}
|
|
|
|
|
<Spinner size="xs" />
|
|
|
|
|
{:else}
|
|
|
|
|
<Icon icon={GallerySend} />
|
|
|
|
|
{/if}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
{/snippet}
|
|
|
|
|
</Field>
|
|
|
|
|
<Field>
|
|
|
|
|
{#snippet label()}
|
|
|
|
|
Topics
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet input()}
|
|
|
|
|
<StringMultiInput bind:value={topics} placeholder="Add a topic..." />
|
|
|
|
|
{/snippet}
|
|
|
|
|
</Field>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
2026-06-23 23:30:54 +00:00
|
|
|
</ModalBody>
|
|
|
|
|
<ModalFooter>
|
|
|
|
|
<Button class="button button-link" onclick={back}>
|
|
|
|
|
<Icon icon={AltArrowLeft} />
|
|
|
|
|
Go back
|
|
|
|
|
</Button>
|
2026-07-06 18:53:12 +00:00
|
|
|
<Button
|
|
|
|
|
class="button button-primary"
|
|
|
|
|
onclick={onSubmit}
|
|
|
|
|
disabled={loading || $uploading || !value.trim()}>
|
2026-06-23 23:30:54 +00:00
|
|
|
<Spinner {loading}>{action}</Spinner>
|
|
|
|
|
</Button>
|
|
|
|
|
</ModalFooter>
|
|
|
|
|
</Modal>
|