flotilla/src/app/components/ShareEvent.svelte

88 lines
2.9 KiB
Svelte
Raw Normal View History

2025-02-06 17:29:30 +00:00
<script lang="ts">
2025-02-06 18:14:29 +00:00
import type {TrustedEvent} from "@welshman/util"
2025-02-06 17:29:30 +00:00
import {preventDefault} from "@lib/html"
2025-09-10 22:26:39 +00:00
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
import AltArrowRight from "@assets/icons/alt-arrow-right.svg?dataurl"
import Copy from "@assets/icons/copy.svg?dataurl"
import LinkRound from "@assets/icons/link-round.svg?dataurl"
2025-02-06 17:29:30 +00:00
import Icon from "@lib/components/Icon.svelte"
import Button from "@lib/components/Button.svelte"
import Divider from "@lib/components/Divider.svelte"
2025-02-06 17:29:30 +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-02-06 17:29:30 +00:00
import ModalFooter from "@lib/components/ModalFooter.svelte"
2026-01-30 22:14:12 +00:00
import Modal from "@lib/components/Modal.svelte"
import ModalBody from "@lib/components/ModalBody.svelte"
import RoomNameWithImage from "@app/components/RoomNameWithImage.svelte"
import {makeEventPermalink, makeRoomPath} from "@app/routes"
2026-08-11 21:54:05 +00:00
import {shareTo} from "@app/share"
import {clip} from "@app/toast"
2026-07-28 16:16:26 +00:00
import {rooms} from "@app/core"
2025-02-06 17:29:30 +00:00
2026-07-28 16:16:26 +00:00
type Props = {
url: string
noun: string
event: TrustedEvent
}
const {url, noun, event}: Props = $props()
const spaceRooms = $rooms.forUrl(url).$
2025-02-06 17:29:30 +00:00
const back = () => history.back()
const onSubmit = () => {
shareTo(makeRoomPath(url, selection), {type: "event", value: event})
2025-02-06 17:29:30 +00:00
}
2025-10-30 22:33:34 +00:00
const toggleRoom = (h: string) => {
selection = h === selection ? "" : h
2025-02-06 17:29:30 +00:00
}
const permalink = makeEventPermalink(event, url)
const copyPermalink = () => clip(permalink)
2025-02-06 17:29:30 +00:00
let selection = $state("")
</script>
2026-01-30 22:14:12 +00:00
<Modal tag="form" onsubmit={preventDefault(onSubmit)}>
<ModalBody>
<ModalHeader>
2026-02-02 18:09:14 +00:00
<ModalTitle>Share {noun}</ModalTitle>
<ModalSubtitle>Which room would you like to share this event to?</ModalSubtitle>
2026-01-30 22:14:12 +00:00
</ModalHeader>
<div class="grid grid-cols-2 gap-2">
2026-07-28 16:16:26 +00:00
{#each $spaceRooms as room (room.h)}
<Button
2026-01-30 22:14:12 +00:00
type="button"
class="flex justify-center button {selection === room.h
? 'button-primary'
: 'button-neutral'}"
2026-01-30 22:14:12 +00:00
onclick={() => toggleRoom(room.h)}>
2026-07-28 16:16:26 +00:00
<RoomNameWithImage {url} h={room.h} />
</Button>
2026-01-30 22:14:12 +00:00
{/each}
</div>
<Divider>Or copy a link</Divider>
<label class="input flex min-w-0 items-center gap-2">
<Icon icon={LinkRound} class="shrink-0" />
<input value={permalink} class="min-w-0 flex-1 truncate" type="text" readonly />
<Button class="shrink-0" aria-label="Copy link" onclick={copyPermalink}>
<Icon icon={Copy} />
</Button>
</label>
2026-01-30 22:14:12 +00:00
</ModalBody>
2025-02-06 17:29:30 +00:00
<ModalFooter>
<Button class="button button-link" onclick={back}>
2025-09-10 22:26:39 +00:00
<Icon icon={AltArrowLeft} />
2025-02-06 17:29:30 +00:00
Go back
</Button>
<Button type="submit" class="button button-primary" disabled={!selection}>
2025-02-06 18:14:29 +00:00
Share {noun}
2025-09-10 22:26:39 +00:00
<Icon icon={AltArrowRight} />
2025-02-06 17:29:30 +00:00
</Button>
</ModalFooter>
2026-01-30 22:14:12 +00:00
</Modal>