2025-11-11 21:39:32 +00:00
|
|
|
<script lang="ts">
|
2026-07-28 16:16:26 +00:00
|
|
|
import {displayRelayUrl} from "@welshman/util"
|
|
|
|
|
import type {RelayInfo} from "@welshman/domain"
|
2026-03-31 20:34:47 +00:00
|
|
|
import Widget from "@assets/icons/widget-4.svg?dataurl"
|
2025-11-11 21:39:32 +00:00
|
|
|
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
|
|
|
|
|
import {preventDefault} from "@lib/html"
|
|
|
|
|
import FieldInline from "@lib/components/FieldInline.svelte"
|
|
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
|
|
|
|
import Spinner from "@lib/components/Spinner.svelte"
|
|
|
|
|
import Button from "@lib/components/Button.svelte"
|
2026-01-30 22:14:12 +00:00
|
|
|
import Modal from "@lib/components/Modal.svelte"
|
|
|
|
|
import ModalBody from "@lib/components/ModalBody.svelte"
|
2025-11-11 21:39:32 +00:00
|
|
|
import ModalHeader from "@lib/components/ModalHeader.svelte"
|
2026-02-02 18:09:14 +00:00
|
|
|
import ModalTitle from "@lib/components/ModalTitle.svelte"
|
|
|
|
|
import ModalSubtitle from "@lib/components/ModalSubtitle.svelte"
|
2025-11-11 21:39:32 +00:00
|
|
|
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
|
|
|
|
import ImageIcon from "@lib/components/ImageIcon.svelte"
|
2026-07-15 16:30:17 +00:00
|
|
|
import IconInput from "@lib/components/IconInput.svelte"
|
2026-06-08 21:14:40 +00:00
|
|
|
import {pushToast} from "@app/toast"
|
|
|
|
|
import {clearModals} from "@app/modal"
|
2026-07-03 20:03:04 +00:00
|
|
|
import {compressFileForUpload, uploadFileOrFallback} from "@app/uploads"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {relayManagement, relays} from "@app/core"
|
2025-11-11 21:39:32 +00:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
url: string
|
2026-07-28 16:16:26 +00:00
|
|
|
initialValues: Partial<RelayInfo>
|
2025-11-11 21:39:32 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-18 02:43:13 +00:00
|
|
|
const {url, initialValues = {}}: Props = $props()
|
2025-11-11 21:39:32 +00:00
|
|
|
|
2026-08-21 15:31:53 +00:00
|
|
|
const values = $state({...initialValues})
|
2025-11-11 21:39:32 +00:00
|
|
|
|
|
|
|
|
const back = () => history.back()
|
|
|
|
|
|
|
|
|
|
const submit = async () => {
|
|
|
|
|
if (values.name != initialValues.name) {
|
2026-07-28 16:16:26 +00:00
|
|
|
const res = await $relayManagement.forUrl(url).changeRelayName(values.name || "")
|
2025-11-11 21:39:32 +00:00
|
|
|
|
|
|
|
|
if (res.error) {
|
|
|
|
|
return pushToast({theme: "error", message: res.error})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (values.description != initialValues.description) {
|
2026-07-28 16:16:26 +00:00
|
|
|
const res = await $relayManagement
|
|
|
|
|
.forUrl(url)
|
|
|
|
|
.changeRelayDescription(values.description || "")
|
2025-11-11 21:39:32 +00:00
|
|
|
|
|
|
|
|
if (res.error) {
|
|
|
|
|
return pushToast({theme: "error", message: res.error})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (imageFile) {
|
2026-07-03 20:03:04 +00:00
|
|
|
const compressedFile = await compressFileForUpload(imageFile, {maxWidth: 128, maxHeight: 128})
|
|
|
|
|
const result = await uploadFileOrFallback(compressedFile)
|
2025-11-11 21:39:32 +00:00
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
const res = await $relayManagement.forUrl(url).changeRelayIcon(result.url)
|
2025-11-11 21:39:32 +00:00
|
|
|
|
|
|
|
|
if (res.error) {
|
|
|
|
|
return pushToast({theme: "error", message: res.error})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pushToast({message: "Your changes have been saved!"})
|
2026-07-28 16:16:26 +00:00
|
|
|
$relays.forceLoad(url)
|
2025-11-11 21:39:32 +00:00
|
|
|
clearModals()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const trySubmit = async () => {
|
|
|
|
|
loading = true
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await submit()
|
|
|
|
|
} finally {
|
|
|
|
|
loading = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let loading = $state(false)
|
|
|
|
|
let imageFile = $state<File | undefined>()
|
|
|
|
|
let imagePreview = $state(initialValues.icon)
|
|
|
|
|
</script>
|
|
|
|
|
|
2026-01-30 22:14:12 +00:00
|
|
|
<Modal tag="form" onsubmit={preventDefault(trySubmit)}>
|
|
|
|
|
<ModalBody>
|
|
|
|
|
<ModalHeader>
|
2026-06-22 20:36:57 +00:00
|
|
|
<ModalTitle>Edit this Space</ModalTitle>
|
2026-02-02 18:09:14 +00:00
|
|
|
<ModalSubtitle><span class="text-primary">{displayRelayUrl(url)}</span></ModalSubtitle>
|
2026-01-30 22:14:12 +00:00
|
|
|
</ModalHeader>
|
|
|
|
|
<FieldInline>
|
|
|
|
|
{#snippet label()}
|
|
|
|
|
<p>Icon</p>
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet input()}
|
2026-07-15 16:30:17 +00:00
|
|
|
<IconInput bind:file={imageFile} bind:preview={imagePreview} />
|
2026-01-30 22:14:12 +00:00
|
|
|
{/snippet}
|
|
|
|
|
</FieldInline>
|
|
|
|
|
<FieldInline>
|
|
|
|
|
{#snippet label()}
|
|
|
|
|
<p>Name</p>
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet input()}
|
2026-06-24 20:56:53 +00:00
|
|
|
<label class="input flex w-full items-center gap-2">
|
2026-01-30 22:14:12 +00:00
|
|
|
{#if imagePreview}
|
|
|
|
|
<ImageIcon src={imagePreview} alt="" />
|
|
|
|
|
{:else}
|
2026-03-31 20:34:47 +00:00
|
|
|
<Icon icon={Widget} />
|
2026-01-30 22:14:12 +00:00
|
|
|
{/if}
|
|
|
|
|
<input bind:value={values.name} class="grow" type="text" />
|
|
|
|
|
</label>
|
|
|
|
|
{/snippet}
|
|
|
|
|
</FieldInline>
|
|
|
|
|
<FieldInline>
|
|
|
|
|
{#snippet label()}
|
2026-02-13 21:05:17 +00:00
|
|
|
<p class="flex flex-col items-start h-full">Description</p>
|
2026-01-30 22:14:12 +00:00
|
|
|
{/snippet}
|
|
|
|
|
{#snippet input()}
|
2026-06-24 20:56:53 +00:00
|
|
|
<textarea bind:value={values.description} class="min-h-24 textarea input flex w-full"
|
|
|
|
|
></textarea>
|
2026-01-30 22:14:12 +00:00
|
|
|
{/snippet}
|
|
|
|
|
</FieldInline>
|
|
|
|
|
</ModalBody>
|
2025-11-11 21:39:32 +00:00
|
|
|
<ModalFooter>
|
2026-06-24 20:56:53 +00:00
|
|
|
<Button class="button button-link" onclick={back}>
|
2025-11-11 21:39:32 +00:00
|
|
|
<Icon icon={AltArrowLeft} />
|
|
|
|
|
Go back
|
|
|
|
|
</Button>
|
2026-06-24 20:56:53 +00:00
|
|
|
<Button type="submit" class="button button-primary" disabled={loading}>
|
2025-11-11 21:39:32 +00:00
|
|
|
<Spinner {loading}>Save Changes</Spinner>
|
|
|
|
|
</Button>
|
|
|
|
|
</ModalFooter>
|
2026-01-30 22:14:12 +00:00
|
|
|
</Modal>
|