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

77 lines
2.3 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 18:33:50 +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"
import {userMembership, discoverRelays} 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-08-14 21:52:00 +00:00
2024-09-11 18:33:50 +00:00
const loadMore = async () => {
limit += 20
}
$: 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-09-11 18:33:50 +00:00
const scroller = createScroller(loadMore)
2024-09-11 18:33:50 +00:00
return () => {
sub.close()
scroller.stop()
}
2024-08-14 21:52:00 +00:00
})
</script>
2024-08-14 23:25:36 +00:00
<div class="content column gap-4">
<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-08-16 17:50:38 +00:00
class="card bg-base-100 shadow-xl transition-all hover:shadow-2xl hover:brightness-[1.1]">
<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>
{#if $userMembership?.topicsByUrl.has(relay.url)}
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-08-14 21:52:00 +00:00
<div class="card-body">
<h2 class="card-title justify-center">{displayRelayUrl(relay.url)}</h2>
{#if relay.profile?.description}
2024-09-11 18:09:25 +00:00
<p class="py-4 text-center text-sm">{relay.profile.description}</p>
2024-08-23 21:42:50 +00:00
{/if}
2024-08-14 21:52:00 +00:00
</div>
</a>
2024-08-14 21:52:00 +00:00
</Masonry>
</div>