2025-10-30 21:59:39 +00:00
|
|
|
<script lang="ts">
|
|
|
|
|
import type {Snippet} from "svelte"
|
|
|
|
|
import type {RoomMeta} from "@welshman/util"
|
|
|
|
|
import {makeRoomMeta} from "@welshman/util"
|
|
|
|
|
import {waitForThunkError, createRoom, editRoom, joinRoom} from "@welshman/app"
|
|
|
|
|
import Hashtag from "@assets/icons/hashtag.svg?dataurl"
|
2026-03-16 20:38:05 +00:00
|
|
|
import Volume from "@assets/icons/volume.svg?dataurl"
|
2025-11-12 01:34:15 +00:00
|
|
|
import {preventDefault} from "@lib/html"
|
2025-10-30 21:59:39 +00:00
|
|
|
import FieldInline from "@lib/components/FieldInline.svelte"
|
|
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
2025-10-31 23:18:58 +00:00
|
|
|
import ImageIcon from "@lib/components/ImageIcon.svelte"
|
2026-07-15 16:30:17 +00:00
|
|
|
import IconInput from "@lib/components/IconInput.svelte"
|
2026-01-30 22:14:12 +00:00
|
|
|
import Modal from "@lib/components/Modal.svelte"
|
|
|
|
|
import ModalBody from "@lib/components/ModalBody.svelte"
|
2026-06-08 21:14:40 +00:00
|
|
|
import {pushToast} from "@app/toast"
|
2026-07-03 20:03:04 +00:00
|
|
|
import {compressFileForUpload, uploadFileOrFallback} from "@app/uploads"
|
2026-06-08 22:33:38 +00:00
|
|
|
import {deriveHasLivekit} from "@app/relays"
|
|
|
|
|
import {getRoomType, RoomType} from "@app/groups"
|
2025-10-30 21:59:39 +00:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
url: string
|
|
|
|
|
header: Snippet
|
|
|
|
|
footer: Snippet<[{loading: boolean}]>
|
|
|
|
|
onsubmit: (room: RoomMeta) => void
|
|
|
|
|
initialValues?: RoomMeta
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const {url, header, footer, onsubmit, initialValues = makeRoomMeta()}: Props = $props()
|
|
|
|
|
|
|
|
|
|
const values = $state(initialValues)
|
2026-03-16 20:38:05 +00:00
|
|
|
const relayHasLivekit = deriveHasLivekit(url)
|
2025-10-30 21:59:39 +00:00
|
|
|
|
|
|
|
|
const submit = async () => {
|
|
|
|
|
const room = $state.snapshot(values)
|
|
|
|
|
|
2026-03-16 20:38:05 +00:00
|
|
|
if (roomType === RoomType.Voice && !$relayHasLivekit) {
|
|
|
|
|
return pushToast({
|
|
|
|
|
theme: "error",
|
|
|
|
|
message: "This relay does not support voice rooms.",
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
room.livekit = roomType === RoomType.Voice
|
|
|
|
|
|
2025-10-30 21:59:39 +00:00
|
|
|
if (imageFile) {
|
2026-07-03 20:03:04 +00:00
|
|
|
const compressedFile = await compressFileForUpload(imageFile, {
|
|
|
|
|
maxWidth: 128,
|
|
|
|
|
maxHeight: 128,
|
2026-03-16 20:38:05 +00:00
|
|
|
})
|
2025-10-30 21:59:39 +00:00
|
|
|
|
2026-07-03 20:03:04 +00:00
|
|
|
const result = await uploadFileOrFallback(compressedFile)
|
2025-10-30 21:59:39 +00:00
|
|
|
|
|
|
|
|
room.picture = result.url
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const createMessage = await waitForThunkError(createRoom(url, room))
|
|
|
|
|
|
|
|
|
|
if (createMessage && !createMessage.includes("already")) {
|
|
|
|
|
return pushToast({theme: "error", message: createMessage})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const editMessage = await waitForThunkError(editRoom(url, room))
|
|
|
|
|
|
|
|
|
|
if (editMessage) {
|
|
|
|
|
return pushToast({theme: "error", message: editMessage})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const joinMessage = await waitForThunkError(joinRoom(url, room))
|
|
|
|
|
|
|
|
|
|
if (joinMessage && !joinMessage.includes("already")) {
|
|
|
|
|
return pushToast({theme: "error", message: joinMessage})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onsubmit(room)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const trySubmit = async () => {
|
|
|
|
|
loading = true
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await submit()
|
|
|
|
|
} finally {
|
|
|
|
|
loading = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let loading = $state(false)
|
|
|
|
|
let imageFile = $state<File | undefined>()
|
|
|
|
|
let imagePreview = $state(initialValues.picture)
|
2026-03-16 20:38:05 +00:00
|
|
|
let roomType = $state(getRoomType(initialValues))
|
2025-10-30 21:59:39 +00:00
|
|
|
</script>
|
|
|
|
|
|
2026-01-30 22:14:12 +00:00
|
|
|
<Modal tag="form" onsubmit={preventDefault(trySubmit)}>
|
|
|
|
|
<ModalBody>
|
|
|
|
|
{@render header()}
|
|
|
|
|
<FieldInline>
|
|
|
|
|
{#snippet label()}
|
|
|
|
|
<p>Icon</p>
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet input()}
|
2026-07-15 16:30:17 +00:00
|
|
|
<IconInput bind:file={imageFile} bind:preview={imagePreview} previewClass="rounded-xl" />
|
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 input-group flex w-full items-center gap-2">
|
2026-01-30 22:14:12 +00:00
|
|
|
{#if imagePreview}
|
2026-07-15 16:30:17 +00:00
|
|
|
<ImageIcon src={imagePreview} alt="" class="rounded-xl" />
|
2026-01-30 22:14:12 +00:00
|
|
|
{:else}
|
2026-03-16 20:38:05 +00:00
|
|
|
<Icon icon={roomType === RoomType.Voice ? Volume : Hashtag} />
|
2026-01-30 22:14:12 +00:00
|
|
|
{/if}
|
|
|
|
|
<input bind:value={values.name} class="grow" type="text" />
|
|
|
|
|
</label>
|
|
|
|
|
{/snippet}
|
|
|
|
|
</FieldInline>
|
|
|
|
|
<FieldInline>
|
|
|
|
|
{#snippet label()}
|
|
|
|
|
<p>Description</p>
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet input()}
|
2026-06-24 20:56:53 +00:00
|
|
|
<label class="input input-group flex w-full items-center gap-2">
|
2026-01-30 22:14:12 +00:00
|
|
|
<input bind:value={values.about} class="grow" type="text" />
|
|
|
|
|
</label>
|
|
|
|
|
{/snippet}
|
|
|
|
|
</FieldInline>
|
2026-03-16 20:38:05 +00:00
|
|
|
{#if $relayHasLivekit}
|
|
|
|
|
<FieldInline>
|
|
|
|
|
{#snippet label()}
|
|
|
|
|
<p>Room type</p>
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet input()}
|
2026-06-24 20:56:53 +00:00
|
|
|
<select class="select input w-full" bind:value={roomType} aria-label="Room type">
|
2026-03-16 20:38:05 +00:00
|
|
|
<option value={RoomType.Text}>Text</option>
|
|
|
|
|
<option value={RoomType.Voice}>Voice</option>
|
|
|
|
|
</select>
|
|
|
|
|
{/snippet}
|
|
|
|
|
</FieldInline>
|
|
|
|
|
{/if}
|
2026-01-30 22:14:12 +00:00
|
|
|
<strong class="md:hidden">Permissions</strong>
|
|
|
|
|
<div class="flex items-center gap-2">
|
|
|
|
|
<input type="checkbox" class="checkbox" bind:checked={values.isRestricted} />
|
|
|
|
|
<span class="text-sm opacity-75">Only allow members to send messages</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="flex items-center gap-2">
|
|
|
|
|
<input type="checkbox" class="checkbox" bind:checked={values.isPrivate} />
|
|
|
|
|
<span class="text-sm opacity-75">Only allow members to read messages</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="flex items-center gap-2">
|
|
|
|
|
<input type="checkbox" class="checkbox" bind:checked={values.isHidden} />
|
|
|
|
|
<span class="text-sm opacity-75">Hide this group from non-members</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="flex items-center gap-2">
|
|
|
|
|
<input type="checkbox" class="checkbox" bind:checked={values.isClosed} />
|
2026-03-19 15:40:34 +00:00
|
|
|
<span class="text-sm opacity-75">Membership requires approval</span>
|
2026-01-30 22:14:12 +00:00
|
|
|
</div>
|
|
|
|
|
</ModalBody>
|
2025-10-30 21:59:39 +00:00
|
|
|
{@render footer({loading})}
|
2026-01-30 22:14:12 +00:00
|
|
|
</Modal>
|