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

174 lines
6.1 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"
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"
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 {
decodeRelay,
channelIsLocked,
makeChannelId,
channelsById,
deriveUserRooms,
deriveOtherRooms,
2024-12-11 19:25:39 +00:00
userMembership,
getMembershipUrls,
2024-12-10 21:38:34 +00:00
} from "@app/state"
2024-11-19 00:33:20 +00:00
import {makeChatPath, makeRoomPath, makeSpacePath} 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)
2024-12-16 19:49:57 +00:00
const threadsPath = makeSpacePath(url, "threads")
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})
2024-12-11 21:35:06 +00:00
let relayAdminEvents: TrustedEvent[] = []
2024-10-31 19:24:40 +00:00
$: pubkey = $relay?.profile?.pubkey
2024-09-23 20:10:15 +00:00
</script>
2024-10-31 19:24:40 +00:00
<div class="relative flex flex-col">
2024-10-09 23:11:23 +00:00
<PageBar>
<div slot="icon" class="center">
2024-10-31 19:24:40 +00:00
<Icon icon="home-smile" />
2024-09-23 20:10:15 +00:00
</div>
2024-10-31 19:24:40 +00:00
<strong slot="title">Home</strong>
2024-10-23 21:20:24 +00:00
<div slot="action" class="row-2">
2024-12-11 19:25:39 +00:00
{#if !getMembershipUrls($userMembership).includes(url)}
<Button class="btn btn-primary btn-sm" on:click={joinSpace}>
<Icon icon="login-2" />
Join Space
</Button>
{:else if pubkey}
2024-10-31 19:24:40 +00:00
<Link class="btn btn-primary btn-sm" href={makeChatPath([pubkey])}>
<Icon icon="letter" />
Contact Owner
</Link>
{/if}
2024-11-15 22:03:54 +00:00
<MenuSpaceButton {url} />
2024-10-23 16:45:06 +00:00
</div>
2024-10-09 23:11:23 +00:00
</PageBar>
2024-11-01 22:08:27 +00:00
<div class="col-2 p-2">
<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}
2024-10-31 19:24:40 +00:00
</div>
</div>
</div>
2024-11-01 22:08:27 +00:00
<div>
<h2 class="ellipsize whitespace-nowrap text-xl">
<RelayName {url} />
</h2>
<p class="text-sm opacity-75">{url}</p>
</div>
2024-10-31 19:24:40 +00:00
</div>
2024-11-01 22:08:27 +00:00
<RelayDescription {url} />
{#if $relay?.profile}
{@const {software, version, supported_nips, limitation} = $relay.profile}
<div class="flex flex-wrap gap-1">
{#if limitation?.auth_required}
2024-11-16 16:04:09 +00:00
<p class="badge badge-neutral">
<span class="ellipsize">Authentication Required</span>
</p>
2024-11-01 22:08:27 +00:00
{/if}
{#if limitation?.payment_required}
2024-11-16 16:04:09 +00:00
<p class="badge badge-neutral"><span class="ellipsize">Payment Required</span></p>
2024-11-01 22:08:27 +00:00
{/if}
{#if limitation?.min_pow_difficulty}
2024-11-16 16:04:09 +00:00
<p class="badge badge-neutral">
<span class="ellipsize">Requires PoW {limitation?.min_pow_difficulty}</span>
</p>
2024-11-01 22:08:27 +00:00
{/if}
{#if supported_nips}
2024-11-16 16:04:09 +00:00
<p class="badge badge-neutral">
<span class="ellipsize">NIPs: {supported_nips.join(", ")}</span>
</p>
2024-11-01 22:08:27 +00:00
{/if}
{#if software}
2024-11-16 16:04:09 +00:00
<p class="badge badge-neutral"><span class="ellipsize">Software: {software}</span></p>
2024-11-01 22:08:27 +00:00
{/if}
{#if version}
2024-11-16 16:04:09 +00:00
<p class="badge badge-neutral"><span class="ellipsize">Version: {version}</span></p>
2024-11-01 22:08:27 +00:00
{/if}
</div>
{/if}
</div>
2024-12-10 01:04:39 +00:00
<div class="grid grid-cols-3 gap-2">
2024-12-16 19:49:57 +00:00
<Link href={threadsPath} class="btn btn-primary">
<Icon icon="notes-minimalistic" />
<div class="relative">
Threads
{#if $notifications.has(threadsPath)}
<div
class="absolute -right-3 -top-1 h-2 w-2 rounded-full bg-primary-content"
transition:fade />
{/if}
</div>
2024-11-19 00:33:20 +00:00
</Link>
2024-12-10 21:02:41 +00:00
{#each $userRooms as room (room)}
2024-12-16 19:49:57 +00:00
{@const roomPath = makeRoomPath(url, room)}
<Link href={roomPath} class="btn btn-neutral">
2024-12-10 21:38:34 +00:00
{#if channelIsLocked($channelsById.get(makeChannelId(url, room)))}
<Icon icon="lock" size={4} />
{:else}
<Icon icon="hashtag" />
{/if}
2024-12-16 19:49:57 +00:00
<div class="relative">
<ChannelName {url} {room} />
{#if $notifications.has(roomPath)}
<div
class="absolute -right-3 -top-1 h-2 w-2 rounded-full bg-primary"
transition:fade />
{/if}
</div>
2024-12-10 21:02:41 +00:00
</Link>
{/each}
{#each $otherRooms as room (room)}
2024-12-11 22:10:20 +00:00
<Link href={makeRoomPath(url, room)} class="btn btn-neutral">
2024-12-10 21:38:34 +00:00
{#if channelIsLocked($channelsById.get(makeChannelId(url, room)))}
<Icon icon="lock" size={4} />
{:else}
<Icon icon="hashtag" />
{/if}
2024-12-11 21:57:46 +00:00
<ChannelName {url} {room} />
2024-11-19 00:33:20 +00:00
</Link>
{/each}
2024-12-11 21:57:46 +00:00
<Button on:click={addRoom} class="btn btn-neutral">
<Icon icon="add-circle" />
Create Room
</Button>
2024-11-19 00:33:20 +00:00
</div>
2024-11-01 22:08:27 +00:00
{#if pubkey}
2024-12-11 21:35:06 +00:00
<div class="hidden flex-col gap-2" class:!flex={relayAdminEvents.length > 0}>
<Divider>Recent posts from the relay admin</Divider>
2024-12-11 22:10:20 +00:00
<ProfileFeed hideLoading {url} {pubkey} bind:events={relayAdminEvents} />
2024-12-11 21:35:06 +00:00
</div>
2024-11-01 22:08:27 +00:00
{/if}
</div>
2024-09-23 20:10:15 +00:00
</div>