flotilla/src/routes/discover/+page.svelte

77 lines
2.4 KiB
Svelte
Raw Normal View History

2024-08-14 21:52:00 +00:00
<script lang="ts">
2024-08-16 17:50:38 +00:00
import {onMount} from "svelte"
import Masonry from "svelte-bricks"
import {displayRelayUrl} from "@welshman/util"
2024-09-11 18:09:25 +00:00
import {relaySearch} from "@welshman/app"
2024-09-11 22:21:25 +00:00
import {createScroller} from "@lib/html"
2024-08-16 17:50:38 +00:00
import Icon from "@lib/components/Icon.svelte"
import {makeSpacePath} from "@app/routes"
2024-10-08 22:30:18 +00:00
import {userMembership, discoverRelays, getMembershipRoomsByUrl} from "@app/state"
2024-08-15 19:08:07 +00:00
2024-08-14 21:52:00 +00:00
let term = ""
2024-09-11 18:33:50 +00:00
let limit = 20
2024-10-01 21:55:33 +00:00
let element: Element
2024-09-11 18:33:50 +00:00
$: relays = $relaySearch.searchOptions(term).slice(0, limit)
2024-08-23 20:33:36 +00:00
2024-08-14 21:52:00 +00:00
onMount(() => {
const sub = discoverRelays()
2024-10-01 21:55:33 +00:00
const scroller = createScroller({
2024-10-08 18:39:16 +00:00
element: element.closest(".max-h-screen")!,
2024-10-01 21:55:33 +00:00
onScroll: () => {
limit += 20
},
})
2024-09-11 18:33:50 +00:00
return () => {
sub.close()
scroller.stop()
}
2024-08-14 21:52:00 +00:00
})
</script>
2024-10-01 21:55:33 +00:00
<div class="content column gap-4" bind:this={element}>
2024-08-14 23:25:36 +00:00
<h1 class="superheading mt-20">Discover Spaces</h1>
<p class="text-center">Find communities all across the nostr network</p>
2024-08-16 17:50:38 +00:00
<label class="input input-bordered flex w-full items-center gap-2">
2024-08-14 23:25:36 +00:00
<Icon icon="magnifer" />
<input bind:value={term} class="grow" type="text" placeholder="Search for spaces..." />
</label>
2024-08-16 17:50:38 +00:00
<Masonry
animate={false}
items={relays}
2024-08-16 17:50:38 +00:00
minColWidth={250}
maxColWidth={800}
gap={16}
idKey="url"
let:item={relay}>
2024-08-16 17:50:38 +00:00
<a
href={makeSpacePath(relay.url)}
2024-10-03 21:32:55 +00:00
class="card2 bg-alt shadow-xl transition-all hover:shadow-2xl hover:brightness-[1.1]">
2024-08-16 17:50:38 +00:00
<div class="center avatar mt-8">
<div
class="center relative !flex w-20 rounded-full border-2 border-solid border-base-300 bg-base-300">
{#if relay.profile?.icon}
<img alt="" src={relay.profile.icon} />
2024-08-14 21:52:00 +00:00
{:else}
<Icon icon="ghost" size={7} />
{/if}
</div>
</div>
2024-10-08 22:30:18 +00:00
{#if getMembershipRoomsByUrl(relay.url, $userMembership)}
2024-08-16 17:50:38 +00:00
<div class="center absolute flex w-full">
<div
2024-08-26 21:43:43 +00:00
class="tooltip relative left-8 top-[38px] h-5 w-5 rounded-full bg-primary"
2024-08-16 17:50:38 +00:00
data-tip="You are already a member of this space.">
<Icon icon="check-circle" class="scale-110" />
</div>
</div>
{/if}
2024-10-03 21:32:55 +00:00
<h2 class="text-center">{displayRelayUrl(relay.url)}</h2>
{#if relay.profile?.description}
<p class="py-4 text-center text-sm">{relay.profile.description}</p>
{/if}
</a>
2024-08-14 21:52:00 +00:00
</Masonry>
</div>