2024-08-14 21:52:00 +00:00
|
|
|
<script lang="ts">
|
|
|
|
|
import {onMount} from 'svelte'
|
|
|
|
|
import Masonry from 'svelte-bricks'
|
2024-08-15 19:08:07 +00:00
|
|
|
import {append, remove} from '@welshman/lib'
|
|
|
|
|
import {GROUP_META, displayRelayUrl} from '@welshman/util'
|
2024-08-14 21:52:00 +00:00
|
|
|
import Icon from '@lib/components/Icon.svelte'
|
2024-08-15 19:08:07 +00:00
|
|
|
import Button from '@lib/components/Button.svelte'
|
|
|
|
|
import Spinner from '@lib/components/Spinner.svelte'
|
|
|
|
|
import {makeSpacePath} from '@app/routes'
|
|
|
|
|
import {load, relays, groups, searchGroups, relayUrlsByNom, userMembership} from '@app/state'
|
|
|
|
|
import {updateGroupMemberships} from '@app/commands'
|
|
|
|
|
|
|
|
|
|
const getRelayUrls = (nom: string): string[] => $relayUrlsByNom.get(nom) || []
|
|
|
|
|
|
|
|
|
|
const join = async (nom: string) => {
|
|
|
|
|
loading = append(nom, loading)
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await updateGroupMemberships(getRelayUrls(nom).map(url => ["group", nom, url]))
|
|
|
|
|
} finally {
|
|
|
|
|
loading = remove(nom, loading)
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-14 21:52:00 +00:00
|
|
|
|
|
|
|
|
let term = ""
|
2024-08-15 19:08:07 +00:00
|
|
|
let loading: string[] = []
|
2024-08-14 21:52:00 +00:00
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
|
load({
|
|
|
|
|
relays: $relays.map(r => r.url),
|
|
|
|
|
filters: [{kinds: [GROUP_META]}],
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
</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>
|
|
|
|
|
<label class="input input-bordered w-full flex items-center gap-2">
|
|
|
|
|
<Icon icon="magnifer" />
|
|
|
|
|
<input bind:value={term} class="grow" type="text" placeholder="Search for spaces..." />
|
|
|
|
|
</label>
|
2024-08-15 19:08:07 +00:00
|
|
|
<Masonry animate={false} items={$searchGroups.searchOptions(term)} minColWidth={250} maxColWidth={800} gap={16} idKey="nom" let:item={group}>
|
2024-08-14 21:52:00 +00:00
|
|
|
<div class="card bg-base-100 shadow-xl">
|
2024-08-14 23:25:36 +00:00
|
|
|
<div class="avatar center mt-8">
|
2024-08-14 21:52:00 +00:00
|
|
|
<div class="w-20 rounded-full bg-base-300 border-2 border-solid border-base-300 !flex center">
|
2024-08-15 19:08:07 +00:00
|
|
|
{#if group?.picture}
|
|
|
|
|
<img alt="" src={group.picture} />
|
2024-08-14 21:52:00 +00:00
|
|
|
{:else}
|
|
|
|
|
<Icon icon="ghost" size={7} />
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="card-body">
|
2024-08-15 19:08:07 +00:00
|
|
|
<a href={makeSpacePath(group.nom)}>
|
|
|
|
|
<h2 class="card-title justify-center">{group.name}</h2>
|
|
|
|
|
</a>
|
|
|
|
|
<div class="text-sm text-center">
|
|
|
|
|
{#each getRelayUrls(group.nom) as url}
|
|
|
|
|
<div class="badge badge-neutral">{displayRelayUrl(url)}</div>
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
<p class="text-sm py-4">{group.about}</p>
|
2024-08-14 21:52:00 +00:00
|
|
|
<div class="card-actions">
|
2024-08-15 19:08:07 +00:00
|
|
|
<Button
|
|
|
|
|
class="btn btn-primary w-full"
|
|
|
|
|
disabled={loading.includes(group.nom) || $userMembership?.noms.has(group.nom)}
|
|
|
|
|
on:click={() => join(group.nom)}>
|
|
|
|
|
{#if $userMembership?.noms.has(group.nom)}
|
|
|
|
|
<Icon icon="check-circle" />
|
|
|
|
|
Joined
|
|
|
|
|
{:else}
|
|
|
|
|
<Spinner loading={loading.includes(group.nom)} />
|
|
|
|
|
Join Space
|
|
|
|
|
{/if}
|
|
|
|
|
</Button>
|
2024-08-14 21:52:00 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Masonry>
|
|
|
|
|
</div>
|