flotilla/src/routes/spaces/[relay]/+page.svelte

202 lines
6.9 KiB
Svelte
Raw Normal View History

2024-09-23 20:10:15 +00:00
<script lang="ts">
import {page} from "$app/stores"
2024-12-11 21:35:06 +00:00
import type {TrustedEvent} from "@welshman/util"
2025-01-14 23:58:38 +00:00
import {displayRelayUrl} from "@welshman/util"
2024-10-31 19:24:40 +00:00
import {deriveRelay} from "@welshman/app"
2024-12-16 19:49:57 +00:00
import {fade} from "@lib/transition"
2024-09-23 20:10:15 +00:00
import Icon from "@lib/components/Icon.svelte"
2024-10-31 19:24:40 +00:00
import Link from "@lib/components/Link.svelte"
2024-12-11 19:25:39 +00:00
import Button from "@lib/components/Button.svelte"
2024-10-31 19:24:40 +00:00
import Divider from "@lib/components/Divider.svelte"
2024-10-09 23:11:23 +00:00
import PageBar from "@lib/components/PageBar.svelte"
2025-03-19 17:30:36 +00:00
import PageContent from "@lib/components/PageContent.svelte"
2024-11-15 22:03:54 +00:00
import MenuSpaceButton from "@app/components/MenuSpaceButton.svelte"
2024-10-31 19:24:40 +00:00
import ProfileFeed from "@app/components/ProfileFeed.svelte"
2024-12-10 01:04:39 +00:00
import ChannelName from "@app/components/ChannelName.svelte"
2024-12-11 19:25:39 +00:00
import SpaceJoin from "@app/components/SpaceJoin.svelte"
2024-10-31 19:24:40 +00:00
import RelayName from "@app/components/RelayName.svelte"
2024-12-11 21:57:46 +00:00
import RoomCreate from "@app/components/RoomCreate.svelte"
2024-10-31 19:24:40 +00:00
import RelayDescription from "@app/components/RelayDescription.svelte"
2024-12-10 21:38:34 +00:00
import {
hasNip29,
2024-12-10 21:38:34 +00:00
decodeRelay,
makeChannelId,
channelsById,
deriveUserRooms,
deriveOtherRooms,
2024-12-17 01:07:52 +00:00
userRoomsByUrl,
2024-12-10 21:38:34 +00:00
} from "@app/state"
2025-02-06 17:29:30 +00:00
import {makeChatPath, makeThreadPath, makeCalendarPath, makeRoomPath} from "@app/routes"
2024-12-16 19:49:57 +00:00
import {notifications} from "@app/notifications"
2024-12-11 19:25:39 +00:00
import {pushModal} from "@app/modal"
2024-09-23 20:10:15 +00:00
2024-10-21 17:30:12 +00:00
const url = decodeRelay($page.params.relay)
2024-10-31 19:24:40 +00:00
const relay = deriveRelay(url)
2024-12-10 21:02:41 +00:00
const userRooms = deriveUserRooms(url)
const otherRooms = deriveOtherRooms(url)
2025-02-06 17:29:30 +00:00
const threadsPath = makeThreadPath(url)
const calendarPath = makeCalendarPath(url)
2024-09-23 20:10:15 +00:00
2024-12-11 19:25:39 +00:00
const joinSpace = () => pushModal(SpaceJoin, {url})
2024-12-11 21:57:46 +00:00
const addRoom = () => pushModal(RoomCreate, {url})
2025-02-04 00:37:14 +00:00
let relayAdminEvents: TrustedEvent[] = $state([])
2024-12-11 21:35:06 +00:00
const pubkey = $derived($relay?.profile?.pubkey)
2024-09-23 20:10:15 +00:00
</script>
2025-03-19 17:30:36 +00:00
<PageBar>
{#snippet icon()}
<div class="center">
<Icon icon="home-smile" />
</div>
{/snippet}
{#snippet title()}
<strong>Home</strong>
{/snippet}
{#snippet action()}
<div class="row-2">
{#if !$userRoomsByUrl.has(url)}
<Button class="btn btn-primary btn-sm" onclick={joinSpace}>
<Icon icon="login-2" />
Join Space
</Button>
{:else if pubkey}
<Link class="btn btn-primary btn-sm" href={makeChatPath([pubkey])}>
<Icon icon="letter" />
Contact Owner
</Link>
{/if}
<MenuSpaceButton {url} />
</div>
{/snippet}
</PageBar>
<PageContent class="flex flex-col p-2 pt-4">
<div class="card2 bg-alt col-4 text-left">
<div class="relative flex gap-4">
<div class="relative">
<div class="avatar relative">
<div
class="center !flex h-12 w-12 min-w-12 rounded-full border-2 border-solid border-base-300 bg-base-300">
{#if $relay?.profile?.icon}
<img alt="" src={$relay.profile.icon} />
{:else}
<Icon icon="ghost" size={5} />
{/if}
</div>
</div>
</div>
<div class="min-w-0">
<h2 class="ellipsize whitespace-nowrap text-xl">
<RelayName {url} />
</h2>
<p class="ellipsize text-sm opacity-75">{displayRelayUrl(url)}</p>
2025-02-04 00:37:14 +00:00
</div>
2025-03-19 17:30:36 +00:00
</div>
<RelayDescription {url} />
{#if $relay?.profile}
{@const {software, version, supported_nips, limitation} = $relay.profile}
<div class="flex flex-wrap gap-1">
{#if limitation?.auth_required}
<p class="badge badge-neutral">
<span class="ellipsize">Authentication Required</span>
</p>
{/if}
{#if limitation?.payment_required}
<p class="badge badge-neutral"><span class="ellipsize">Payment Required</span></p>
{/if}
{#if limitation?.min_pow_difficulty}
<p class="badge badge-neutral">
<span class="ellipsize">Requires PoW {limitation?.min_pow_difficulty}</span>
</p>
{/if}
2025-05-08 18:16:02 +00:00
{#if Array.isArray(supported_nips)}
2025-03-19 17:30:36 +00:00
<p class="badge badge-neutral">
<span class="ellipsize">NIPs: {supported_nips.join(", ")}</span>
</p>
{/if}
{#if software}
<p class="badge badge-neutral"><span class="ellipsize">Software: {software}</span></p>
{/if}
{#if version}
<p class="badge badge-neutral"><span class="ellipsize">Version: {version}</span></p>
2025-02-04 00:37:14 +00:00
{/if}
</div>
2025-03-19 17:30:36 +00:00
{/if}
</div>
<Divider>Your Rooms</Divider>
<div class="grid grid-cols-3 gap-2">
<Link href={threadsPath} class="btn btn-primary">
<div class="relative flex items-center gap-2">
<Icon icon="notes-minimalistic" />
Threads
{#if $notifications.has(threadsPath)}
<div
class="absolute -right-3 -top-1 h-2 w-2 rounded-full bg-primary-content"
transition:fade>
2024-10-31 19:24:40 +00:00
</div>
2025-03-19 17:30:36 +00:00
{/if}
2024-10-31 19:24:40 +00:00
</div>
2025-03-19 17:30:36 +00:00
</Link>
<Link href={calendarPath} class="btn btn-secondary">
<div class="relative flex items-center gap-2">
<Icon icon="notes-minimalistic" />
Calendar
{#if $notifications.has(calendarPath)}
<div
class="absolute -right-3 -top-1 h-2 w-2 rounded-full bg-primary-content"
transition:fade>
</div>
{/if}
</div>
</Link>
{#each $userRooms as room (room)}
{@const roomPath = makeRoomPath(url, room)}
2025-05-28 23:46:41 +00:00
{@const channel = $channelsById.get(makeChannelId(url, room))}
2025-03-19 17:30:36 +00:00
<Link href={roomPath} class="btn btn-neutral relative">
<div class="flex min-w-0 items-center gap-2 overflow-hidden text-nowrap">
2025-05-28 23:46:41 +00:00
{#if channel?.closed || channel?.private}
2025-03-19 17:30:36 +00:00
<Icon icon="lock" size={4} />
{:else}
<Icon icon="hashtag" />
2024-12-16 19:49:57 +00:00
{/if}
2025-03-19 17:30:36 +00:00
<ChannelName {url} {room} />
2024-12-16 19:49:57 +00:00
</div>
2025-03-19 17:30:36 +00:00
{#if $notifications.has(roomPath)}
<div class="absolute right-1 top-1 h-2 w-2 rounded-full bg-primary" transition:fade></div>
{/if}
2024-11-19 00:33:20 +00:00
</Link>
2025-03-19 17:30:36 +00:00
{/each}
</div>
<Divider>Other Rooms</Divider>
<div class="grid grid-cols-3 gap-2">
{#each $otherRooms as room (room)}
2025-05-28 23:46:41 +00:00
{@const channel = $channelsById.get(makeChannelId(url, room))}
2025-03-19 17:30:36 +00:00
<Link href={makeRoomPath(url, room)} class="btn btn-neutral">
<div class="relative flex min-w-0 items-center gap-2 overflow-hidden text-nowrap">
2025-05-28 23:46:41 +00:00
{#if channel?.closed || channel?.private}
2025-03-19 17:30:36 +00:00
<Icon icon="lock" size={4} />
{:else}
<Icon icon="hashtag" />
2025-02-06 17:29:30 +00:00
{/if}
2025-03-19 17:30:36 +00:00
<ChannelName {url} {room} />
2025-02-06 17:29:30 +00:00
</div>
</Link>
2025-03-19 17:30:36 +00:00
{/each}
{#if hasNip29($relay)}
<Button onclick={addRoom} class="btn btn-neutral whitespace-nowrap">
<Icon icon="add-circle" />
Create
</Button>
{/if}
2024-11-01 22:08:27 +00:00
</div>
2025-03-19 17:30:36 +00:00
{#if pubkey}
2025-05-08 18:05:27 +00:00
<Divider>Recent posts from the relay admin</Divider>
2025-03-19 17:30:36 +00:00
<div class="hidden flex-col gap-2" class:!flex={relayAdminEvents.length > 0}>
<ProfileFeed hideLoading {url} {pubkey} bind:events={relayAdminEvents} />
</div>
{/if}
</PageContent>