flotilla/src/app/components/RoomDetail.svelte

158 lines
5.8 KiB
Svelte
Raw Normal View History

<script lang="ts">
2026-07-03 16:20:45 +00:00
import {displayRelayUrl} from "@welshman/util"
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
import EyeClosed from "@assets/icons/eye-closed.svg?dataurl"
2026-02-12 00:44:51 +00:00
import Eye from "@assets/icons/eye.svg?dataurl"
import MinusCircle from "@assets/icons/minus-circle.svg?dataurl"
import Lock from "@assets/icons/lock.svg?dataurl"
import Microphone from "@assets/icons/microphone.svg?dataurl"
2026-01-30 16:41:58 +00:00
import Bookmark from "@assets/icons/bookmark.svg?dataurl"
import Bell from "@assets/icons/bell.svg?dataurl"
import Icon from "@lib/components/Icon.svelte"
import Button from "@lib/components/Button.svelte"
2026-07-03 16:20:45 +00:00
import MenuButton from "@lib/components/MenuButton.svelte"
import Tooltip from "@lib/components/Tooltip.svelte"
2026-01-30 22:14:12 +00:00
import Modal from "@lib/components/Modal.svelte"
import ModalBody from "@lib/components/ModalBody.svelte"
import ModalFooter from "@lib/components/ModalFooter.svelte"
import ProfileCircles from "@app/components/ProfileCircles.svelte"
2025-11-13 21:25:34 +00:00
import RoomMembers from "@app/components/RoomMembers.svelte"
2026-07-03 16:20:45 +00:00
import RoomDetailMenu from "@app/components/RoomDetailMenu.svelte"
import RoomName from "@app/components/RoomName.svelte"
import RoomImage from "@app/components/RoomImage.svelte"
import {deriveRoom, deriveUserRooms, addRoom, removeRoom} from "@app/groups"
2026-07-03 16:20:45 +00:00
import {deriveRoomMembers} from "@app/members"
import {deriveShouldNotify, toggleRoomNotifications} from "@app/settings"
2026-06-08 21:14:40 +00:00
import {pushModal} from "@app/modal"
type Props = {
url: string
h: string
}
const {url, h}: Props = $props()
const room = deriveRoom(url, h)
const members = deriveRoomMembers(url, h)
2026-01-30 16:41:58 +00:00
const userRooms = deriveUserRooms(url)
const isFavorite = $derived($userRooms.includes(h))
2026-02-02 22:29:12 +00:00
const shouldNotify = deriveShouldNotify(url, h)
const back = () => history.back()
2025-11-13 21:25:34 +00:00
const showMembers = () => pushModal(RoomMembers, {url, h})
2026-01-30 16:41:58 +00:00
const toggleFavorite = () => {
if (isFavorite) {
removeRoom(url, h)
2026-01-30 16:41:58 +00:00
} else {
addRoom(url, h)
2026-01-30 16:41:58 +00:00
}
}
2026-02-02 22:29:12 +00:00
const toggleShouldNotify = () => {
2026-01-30 16:41:58 +00:00
toggleRoomNotifications(url, h)
}
</script>
2026-01-30 22:14:12 +00:00
<Modal>
<ModalBody>
<div class="flex justify-between">
<div class="flex gap-3">
<div class="pt-0.5">
<RoomImage {url} {h} size={8} />
</div>
<div class="flex min-w-0 flex-col">
<RoomName {url} {h} class="text-2xl" />
<span class="text-primary">{displayRelayUrl(url)}</span>
</div>
2026-01-30 16:41:58 +00:00
</div>
2026-07-03 16:20:45 +00:00
<MenuButton component={RoomDetailMenu} componentProps={{url, h}} />
2026-02-10 19:39:29 +00:00
</div>
2026-02-12 00:44:51 +00:00
{#if $room?.about}
<p>{$room.about}</p>
{/if}
<div class="flex flex-col gap-2 card card-sm">
2026-02-10 19:39:29 +00:00
<strong class="text-lg">Room Permissions</strong>
<div class="flex gap-2 flex-wrap">
2026-01-30 22:14:12 +00:00
{#if $room?.isRestricted}
<Tooltip content="Only members can send messages.">
<Button class="button button-neutral button-xs button-pill flex gap-2 items-center">
<Icon size={4} icon={Microphone} /> Restricted
</Button>
</Tooltip>
2026-01-30 22:14:12 +00:00
{/if}
{#if $room?.isPrivate}
<Tooltip content="Only members can view messages.">
<Button class="button button-neutral button-xs button-pill flex gap-2 items-center">
<Icon size={4} icon={Lock} /> Private
</Button>
</Tooltip>
2026-01-30 22:14:12 +00:00
{/if}
{#if $room?.isHidden}
<Tooltip content="This room is not visible to non-members.">
<Button class="button button-neutral button-xs button-pill flex gap-2 items-center">
<Icon size={4} icon={EyeClosed} /> Hidden
</Button>
</Tooltip>
2026-01-30 22:14:12 +00:00
{/if}
{#if $room?.isClosed}
<Tooltip content="Requests to join this room will be ignored.">
<Button class="button button-neutral button-xs button-pill flex gap-2 items-center">
<Icon size={4} icon={MinusCircle} /> Closed
</Button>
</Tooltip>
2026-02-10 19:39:29 +00:00
{/if}
{#if !$room?.isRestricted && !$room?.isPrivate && !$room?.isHidden && !$room?.isClosed}
<Tooltip content="This room has no additional access controls.">
<Button class="button button-neutral button-xs button-pill flex gap-2 items-center">
<Icon size={4} icon={Eye} /> Public
</Button>
</Tooltip>
2026-01-30 22:14:12 +00:00
{/if}
</div>
</div>
{#if $members !== undefined && $members.length > 0}
<div class="card card-sm flex items-center justify-between gap-4">
2026-01-30 22:14:12 +00:00
<div class="flex items-center gap-4">
<span>Members:</span>
<ProfileCircles pubkeys={$members} />
</div>
<Button class="button button-neutral button-sm" onclick={showMembers}>View All</Button>
2025-11-13 21:25:34 +00:00
</div>
{:else if $members === undefined}
<div class="card card-sm bg-surface flex items-center gap-4">
<span class="text-error">Member list not available from this relay</span>
</div>
2026-01-30 22:14:12 +00:00
{/if}
<div class="card card-sm flex flex-col gap-4">
2026-01-30 22:14:12 +00:00
<strong class="text-lg">Room Settings</strong>
<div class="flex items-center justify-between">
<div class="flex items-center gap-2">
<Icon icon={Bell} />
2026-01-30 22:14:12 +00:00
<span>Notifications</span>
</div>
<input
type="checkbox"
class="toggle"
2026-02-02 22:29:12 +00:00
checked={$shouldNotify}
onchange={toggleShouldNotify} />
2026-01-30 16:41:58 +00:00
</div>
2026-01-30 22:14:12 +00:00
<div class="flex items-center justify-between">
<div class="flex items-center gap-2">
<Icon icon={Bookmark} />
<span>Favorite</span>
</div>
<input type="checkbox" class="toggle" checked={isFavorite} onchange={toggleFavorite} />
2026-01-30 16:41:58 +00:00
</div>
</div>
2026-01-30 22:14:12 +00:00
</ModalBody>
<ModalFooter>
<Button class="button button-link" onclick={back}>
<Icon icon={AltArrowLeft} />
Go back
</Button>
</ModalFooter>
2026-01-30 22:14:12 +00:00
</Modal>