2025-10-28 23:46:49 +00:00
|
|
|
<script lang="ts">
|
2026-06-24 20:10:06 +00:00
|
|
|
import {onMount} from "svelte"
|
2026-09-26 06:27:46 +00:00
|
|
|
import {sleep} from "@welshman/lib"
|
2026-05-07 19:52:26 +00:00
|
|
|
import {ROOMS} from "@welshman/util"
|
2026-09-26 06:27:46 +00:00
|
|
|
import {Sync} from "@welshman/app"
|
2026-06-24 20:10:06 +00:00
|
|
|
import {createScroller, isMobile} from "@lib/html"
|
2026-03-31 20:34:47 +00:00
|
|
|
import {fly} from "@lib/transition"
|
2026-09-23 03:13:48 +00:00
|
|
|
import Compass from "@assets/icons/compass.svg?dataurl"
|
2025-10-28 23:46:49 +00:00
|
|
|
import AddCircle from "@assets/icons/add-circle.svg?dataurl"
|
2026-03-31 20:34:47 +00:00
|
|
|
import Magnifier from "@assets/icons/magnifier.svg?dataurl"
|
2025-10-28 23:46:49 +00:00
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
|
|
|
|
import Button from "@lib/components/Button.svelte"
|
|
|
|
|
import Page from "@lib/components/Page.svelte"
|
|
|
|
|
import PageBar from "@lib/components/PageBar.svelte"
|
|
|
|
|
import PageContent from "@lib/components/PageContent.svelte"
|
2026-03-31 20:34:47 +00:00
|
|
|
import Divider from "@lib/components/Divider.svelte"
|
|
|
|
|
import Spinner from "@lib/components/Spinner.svelte"
|
2026-06-24 20:10:06 +00:00
|
|
|
import ContentSearch from "@lib/components/ContentSearch.svelte"
|
2025-10-28 23:46:49 +00:00
|
|
|
import SpaceAdd from "@app/components/SpaceAdd.svelte"
|
2026-09-26 06:27:46 +00:00
|
|
|
import SpaceResult from "@app/components/SpaceResult.svelte"
|
|
|
|
|
import {app, roomLists, user} from "@app/core"
|
|
|
|
|
import {deriveSpaceSearch, userSpaceUrls} from "@app/rooms"
|
2026-06-08 22:33:38 +00:00
|
|
|
import {PLATFORM_RELAYS, DEFAULT_RELAYS} from "@app/env"
|
|
|
|
|
import {bootstrapPubkeys} from "@app/social"
|
2026-07-20 23:35:24 +00:00
|
|
|
import {parseInviteLink} from "@app/access"
|
2026-06-08 21:14:40 +00:00
|
|
|
import {pushModal} from "@app/modal"
|
2025-10-28 23:46:49 +00:00
|
|
|
|
|
|
|
|
const addSpace = () => pushModal(SpaceAdd)
|
2026-02-18 23:03:08 +00:00
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
const userSpacesLoaded = $roomLists.load($user.pubkey)
|
2026-09-26 06:27:46 +00:00
|
|
|
const spaceSearch = deriveSpaceSearch()
|
2026-03-31 20:34:47 +00:00
|
|
|
|
|
|
|
|
let term = $state("")
|
|
|
|
|
let limit = $state(20)
|
|
|
|
|
let element: Element
|
|
|
|
|
|
|
|
|
|
const inviteData = $derived(parseInviteLink(term))
|
2026-09-26 06:27:46 +00:00
|
|
|
const searchResults = $derived($spaceSearch.searchOptions(term))
|
2026-03-31 20:34:47 +00:00
|
|
|
const userSpaceSet = $derived(new Set($userSpaceUrls))
|
|
|
|
|
const otherSpaces = $derived(
|
|
|
|
|
searchResults.filter(r => !userSpaceSet.has(r.url) && r.url !== inviteData?.url),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
|
const scroller = createScroller({
|
|
|
|
|
element,
|
|
|
|
|
onScroll: () => {
|
|
|
|
|
limit += 20
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
$app.use(Sync).pull({
|
2026-05-07 19:52:26 +00:00
|
|
|
filters: [{kinds: [ROOMS], authors: $bootstrapPubkeys}],
|
|
|
|
|
relays: DEFAULT_RELAYS,
|
|
|
|
|
})
|
|
|
|
|
|
2026-03-31 20:34:47 +00:00
|
|
|
return () => {
|
|
|
|
|
scroller.stop()
|
|
|
|
|
}
|
|
|
|
|
})
|
2025-10-28 23:46:49 +00:00
|
|
|
</script>
|
|
|
|
|
|
2026-04-04 00:14:55 +00:00
|
|
|
<Page>
|
|
|
|
|
<PageBar>
|
2026-05-07 19:52:26 +00:00
|
|
|
<div class="flex items-center justify-between gap-4" in:fly>
|
2026-07-02 21:22:55 +00:00
|
|
|
<div class="truncate min-w-0 flex items-center gap-2 whitespace-nowrap">
|
2026-09-23 03:13:48 +00:00
|
|
|
<Icon icon={Compass} size={6} />
|
2026-05-07 19:52:26 +00:00
|
|
|
<strong>Spaces</strong>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="flex items-center gap-2">
|
|
|
|
|
{#if PLATFORM_RELAYS.length === 0}
|
2026-06-24 20:56:53 +00:00
|
|
|
<Button class="button button-primary button-sm" onclick={addSpace}>
|
2026-05-07 19:52:26 +00:00
|
|
|
<Icon icon={AddCircle} />
|
|
|
|
|
Add Space
|
|
|
|
|
</Button>
|
|
|
|
|
{/if}
|
2026-03-31 20:34:47 +00:00
|
|
|
</div>
|
2026-05-07 19:52:26 +00:00
|
|
|
</div>
|
2026-03-31 20:34:47 +00:00
|
|
|
</PageBar>
|
2026-06-24 20:56:53 +00:00
|
|
|
<PageContent class="flex flex-col gap-2 p-2 sm:flex flex-col gap-4 sm:p-4">
|
2026-06-24 20:10:06 +00:00
|
|
|
<ContentSearch>
|
|
|
|
|
{#snippet input()}
|
2026-06-24 20:56:53 +00:00
|
|
|
<label class="flex gap-2 input w-full">
|
2026-06-24 20:10:06 +00:00
|
|
|
<Icon icon={Magnifier} />
|
|
|
|
|
<!-- svelte-ignore a11y_autofocus -->
|
|
|
|
|
<input
|
|
|
|
|
autofocus={!isMobile}
|
|
|
|
|
bind:value={term}
|
|
|
|
|
class="min-w-0 grow"
|
|
|
|
|
type="text"
|
|
|
|
|
placeholder="Search for spaces..." />
|
|
|
|
|
</label>
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet content()}
|
2026-06-24 20:56:53 +00:00
|
|
|
<div class="flex flex-col gap-2" bind:this={element}>
|
2026-06-24 20:10:06 +00:00
|
|
|
{#each PLATFORM_RELAYS as url (url)}
|
2026-09-26 06:27:46 +00:00
|
|
|
<SpaceResult {url} />
|
2026-06-24 20:10:06 +00:00
|
|
|
{:else}
|
2026-07-28 16:16:26 +00:00
|
|
|
{#await userSpacesLoaded}
|
2026-06-24 20:10:06 +00:00
|
|
|
<div class="flex items-center justify-center py-20">
|
2026-06-24 20:56:53 +00:00
|
|
|
<Spinner size="sm" class="mr-3" />
|
2026-09-17 18:26:01 +00:00
|
|
|
Loading spaces...
|
2026-06-24 20:10:06 +00:00
|
|
|
</div>
|
2026-03-31 20:34:47 +00:00
|
|
|
{:then}
|
2026-06-24 20:10:06 +00:00
|
|
|
{#if inviteData}
|
|
|
|
|
<Divider>Search results</Divider>
|
|
|
|
|
{#key inviteData.url}
|
2026-09-26 06:27:46 +00:00
|
|
|
<SpaceResult url={inviteData.url} invite={inviteData.claim ? term : undefined} />
|
2026-06-24 20:10:06 +00:00
|
|
|
{/key}
|
|
|
|
|
{/if}
|
|
|
|
|
{#if otherSpaces.length > 0}
|
2026-08-21 15:31:53 +00:00
|
|
|
<Divider>Browse Spaces</Divider>
|
2026-03-31 20:34:47 +00:00
|
|
|
{/if}
|
2026-06-24 20:10:06 +00:00
|
|
|
{#each otherSpaces.slice(0, limit) as relay (relay.url)}
|
2026-09-26 06:27:46 +00:00
|
|
|
<SpaceResult url={relay.url} />
|
2026-06-24 20:10:06 +00:00
|
|
|
{/each}
|
|
|
|
|
<div class="flex justify-center py-20">
|
|
|
|
|
{#await sleep(5000)}
|
|
|
|
|
<Spinner loading>Looking for spaces...</Spinner>
|
|
|
|
|
{:then}
|
|
|
|
|
{#if otherSpaces.length === 0}
|
2026-09-17 18:26:01 +00:00
|
|
|
<Spinner>No spaces found.</Spinner>
|
2026-06-24 20:10:06 +00:00
|
|
|
{/if}
|
|
|
|
|
{/await}
|
|
|
|
|
</div>
|
2026-03-31 20:34:47 +00:00
|
|
|
{/await}
|
2026-06-24 20:10:06 +00:00
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
{/snippet}
|
|
|
|
|
</ContentSearch>
|
2025-10-28 23:46:49 +00:00
|
|
|
</PageContent>
|
|
|
|
|
</Page>
|