2024-08-14 21:52:00 +00:00
|
|
|
<script lang="ts">
|
2024-08-16 17:50:38 +00:00
|
|
|
import {onMount} from "svelte"
|
2026-01-29 18:47:29 +00:00
|
|
|
import {derived as _derived} from "svelte/store"
|
|
|
|
|
import {dec, sleep} from "@welshman/lib"
|
2025-10-24 16:38:57 +00:00
|
|
|
import type {RelayProfile} from "@welshman/util"
|
2026-01-29 18:47:29 +00:00
|
|
|
import {throttled} from "@welshman/store"
|
|
|
|
|
import {relays, createSearch} from "@welshman/app"
|
2024-09-11 22:21:25 +00:00
|
|
|
import {createScroller} from "@lib/html"
|
2025-09-22 22:48:13 +00:00
|
|
|
import AddCircle from "@assets/icons/add-circle.svg?dataurl"
|
2026-02-19 19:08:06 +00:00
|
|
|
import Login from "@assets/icons/login-3.svg?dataurl"
|
2025-09-10 22:26:39 +00:00
|
|
|
import Magnifier from "@assets/icons/magnifier.svg?dataurl"
|
2024-08-16 17:50:38 +00:00
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
2024-10-22 16:22:55 +00:00
|
|
|
import Page from "@lib/components/Page.svelte"
|
2024-11-14 23:43:55 +00:00
|
|
|
import Spinner from "@lib/components/Spinner.svelte"
|
2026-02-19 19:08:06 +00:00
|
|
|
import Divider from "@lib/components/Divider.svelte"
|
2024-10-10 21:33:50 +00:00
|
|
|
import Button from "@lib/components/Button.svelte"
|
2026-02-19 19:08:06 +00:00
|
|
|
import CardButton from "@lib/components/CardButton.svelte"
|
|
|
|
|
import Link from "@lib/components/Link.svelte"
|
2024-10-09 23:11:23 +00:00
|
|
|
import PageHeader from "@lib/components/PageHeader.svelte"
|
2025-09-22 22:48:13 +00:00
|
|
|
import ContentSearch from "@lib/components/ContentSearch.svelte"
|
2025-09-22 22:56:48 +00:00
|
|
|
import SpaceInviteAccept from "@app/components/SpaceInviteAccept.svelte"
|
2025-09-06 00:20:12 +00:00
|
|
|
import RelaySummary from "@app/components/RelaySummary.svelte"
|
2026-01-30 16:41:58 +00:00
|
|
|
import SpaceJoin from "@app/components/SpaceJoin.svelte"
|
2026-01-29 18:47:29 +00:00
|
|
|
import {groupListPubkeysByUrl, parseInviteLink} from "@app/core/state"
|
2025-08-21 22:01:31 +00:00
|
|
|
import {pushModal} from "@app/util/modal"
|
2024-10-10 21:33:50 +00:00
|
|
|
|
2026-02-19 19:08:06 +00:00
|
|
|
const startJoin = () => pushModal(SpaceInviteAccept)
|
2025-09-22 22:56:48 +00:00
|
|
|
|
2026-01-29 18:47:29 +00:00
|
|
|
const relaySearch = _derived(throttled(1000, relays), $relays => {
|
2026-01-30 16:41:58 +00:00
|
|
|
const options = $relays.filter(r => $groupListPubkeysByUrl.has(r.url))
|
2025-02-14 20:14:00 +00:00
|
|
|
|
2026-01-29 18:47:29 +00:00
|
|
|
return createSearch(options, {
|
|
|
|
|
getValue: (relay: RelayProfile) => relay.url,
|
|
|
|
|
sortFn: ({score, item}) => {
|
|
|
|
|
if (score && score > 0.1) return -score!
|
2025-02-14 20:14:00 +00:00
|
|
|
|
2026-01-29 18:47:29 +00:00
|
|
|
const wotScore = $groupListPubkeysByUrl.get(item.url)!.size
|
2024-08-15 19:08:07 +00:00
|
|
|
|
2026-01-29 18:47:29 +00:00
|
|
|
return score ? dec(score) * wotScore : -wotScore
|
|
|
|
|
},
|
|
|
|
|
fuseOptions: {
|
|
|
|
|
keys: ["url", "name", {name: "description", weight: 0.3}],
|
|
|
|
|
shouldSort: false,
|
2025-02-04 00:37:14 +00:00
|
|
|
},
|
2026-01-29 18:47:29 +00:00
|
|
|
})
|
|
|
|
|
})
|
2024-10-17 20:56:53 +00:00
|
|
|
|
2025-11-05 00:39:34 +00:00
|
|
|
const openSpace = (url: string, claim = "") => {
|
|
|
|
|
if (claim) {
|
|
|
|
|
pushModal(SpaceInviteAccept, {invite: term})
|
|
|
|
|
} else {
|
2026-01-30 16:41:58 +00:00
|
|
|
pushModal(SpaceJoin, {url})
|
2025-11-05 00:39:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
2024-10-17 20:56:53 +00:00
|
|
|
|
2025-02-04 00:37:14 +00:00
|
|
|
let term = $state("")
|
|
|
|
|
let limit = $state(20)
|
|
|
|
|
let element: Element
|
2024-10-17 20:56:53 +00:00
|
|
|
|
2026-01-30 16:41:58 +00:00
|
|
|
const options = $derived($relaySearch.searchOptions(term).filter(r => r.url !== inviteData?.url))
|
2025-11-05 00:39:34 +00:00
|
|
|
const inviteData = $derived(parseInviteLink(term))
|
|
|
|
|
|
2024-08-14 21:52:00 +00:00
|
|
|
onMount(() => {
|
2024-10-01 21:55:33 +00:00
|
|
|
const scroller = createScroller({
|
2024-10-17 21:26:53 +00:00
|
|
|
element,
|
2024-10-01 21:55:33 +00:00
|
|
|
onScroll: () => {
|
|
|
|
|
limit += 20
|
|
|
|
|
},
|
|
|
|
|
})
|
2024-09-11 17:48:34 +00:00
|
|
|
|
2024-09-11 18:33:50 +00:00
|
|
|
return () => {
|
|
|
|
|
scroller.stop()
|
|
|
|
|
}
|
2024-08-14 21:52:00 +00:00
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
2025-05-27 23:22:20 +00:00
|
|
|
<Page class="cw-full">
|
2025-09-22 22:48:13 +00:00
|
|
|
<ContentSearch>
|
|
|
|
|
{#snippet input()}
|
2025-09-22 22:56:48 +00:00
|
|
|
<div class="flex flex-col gap-2">
|
|
|
|
|
<PageHeader>
|
|
|
|
|
{#snippet title()}
|
2026-02-19 19:08:06 +00:00
|
|
|
Join a Space
|
2025-09-22 22:56:48 +00:00
|
|
|
{/snippet}
|
|
|
|
|
{#snippet info()}
|
|
|
|
|
Find communities all across the nostr network
|
|
|
|
|
{/snippet}
|
|
|
|
|
</PageHeader>
|
2026-02-20 22:21:38 +00:00
|
|
|
<div class="grid gap-3 sm:grid-cols-2 card2 bg-alt">
|
2026-02-19 19:08:06 +00:00
|
|
|
<Button onclick={startJoin} class="w-full">
|
|
|
|
|
<CardButton class="btn-primary w-full">
|
|
|
|
|
{#snippet icon()}
|
|
|
|
|
<div><Icon icon={Login} size={7} /></div>
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet title()}
|
|
|
|
|
<div>Join with an invite</div>
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet info()}
|
|
|
|
|
<div>Paste a link and jump right in.</div>
|
|
|
|
|
{/snippet}
|
|
|
|
|
</CardButton>
|
|
|
|
|
</Button>
|
|
|
|
|
<Link href="/spaces/create" class="w-full">
|
|
|
|
|
<CardButton class="btn-neutral w-full">
|
|
|
|
|
{#snippet icon()}
|
|
|
|
|
<div><Icon icon={AddCircle} size={7} /></div>
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet title()}
|
|
|
|
|
<div>Create a new space</div>
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet info()}
|
|
|
|
|
<div>Launch a place for your people.</div>
|
|
|
|
|
{/snippet}
|
|
|
|
|
</CardButton>
|
|
|
|
|
</Link>
|
|
|
|
|
</div>
|
|
|
|
|
<Divider>Or</Divider>
|
|
|
|
|
<div class="min-w-0">
|
|
|
|
|
<label class="input input-bordered flex items-center gap-2">
|
2025-09-22 22:56:48 +00:00
|
|
|
<Icon icon={Magnifier} />
|
2026-02-19 19:08:06 +00:00
|
|
|
<input bind:value={term} class="grow" type="text" placeholder="Search for spaces..." />
|
2025-09-22 22:56:48 +00:00
|
|
|
</label>
|
|
|
|
|
</div>
|
2025-09-22 22:48:13 +00:00
|
|
|
</div>
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet content()}
|
2026-02-19 19:08:06 +00:00
|
|
|
<div class="col-2" bind:this={element}>
|
2025-11-05 00:39:34 +00:00
|
|
|
{#if inviteData}
|
|
|
|
|
{#key inviteData.url}
|
2025-09-22 22:48:13 +00:00
|
|
|
<Button
|
2025-11-05 23:32:55 +00:00
|
|
|
class="card2 bg-alt shadow-md transition-all hover:shadow-lg hover:dark:brightness-[1.1]"
|
2025-11-05 00:39:34 +00:00
|
|
|
onclick={() => openSpace(inviteData.url, inviteData.claim)}>
|
|
|
|
|
<RelaySummary url={inviteData.url} />
|
2025-09-22 22:48:13 +00:00
|
|
|
</Button>
|
2025-11-05 00:39:34 +00:00
|
|
|
{/key}
|
|
|
|
|
{/if}
|
2026-01-29 18:47:29 +00:00
|
|
|
{#each options.slice(0, limit) as relay (relay.url)}
|
2025-09-22 22:48:13 +00:00
|
|
|
<Button
|
2025-11-05 23:32:55 +00:00
|
|
|
class="card2 bg-alt shadow-md transition-all hover:shadow-lg hover:dark:brightness-[1.1]"
|
2025-09-22 22:48:13 +00:00
|
|
|
onclick={() => openSpace(relay.url)}>
|
|
|
|
|
<RelaySummary url={relay.url} />
|
|
|
|
|
</Button>
|
|
|
|
|
{/each}
|
2026-01-29 18:47:29 +00:00
|
|
|
<div class="flex justify-center py-20">
|
|
|
|
|
{#await sleep(5000)}
|
2025-09-22 22:48:13 +00:00
|
|
|
<Spinner loading>Looking for spaces...</Spinner>
|
2026-01-29 18:47:29 +00:00
|
|
|
{:then}
|
|
|
|
|
{#if options.length === 0}
|
|
|
|
|
<Spinner>No spaces found.</Spinner>
|
|
|
|
|
{/if}
|
|
|
|
|
{/await}
|
|
|
|
|
</div>
|
2024-11-15 22:03:54 +00:00
|
|
|
</div>
|
2025-09-22 22:48:13 +00:00
|
|
|
{/snippet}
|
|
|
|
|
</ContentSearch>
|
2024-10-22 16:22:55 +00:00
|
|
|
</Page>
|