flotilla/src/app/components/Search.svelte

57 lines
2.2 KiB
Svelte
Raw Normal View History

2026-09-07 20:53:25 +00:00
<script lang="ts">
import {MESSAGE} from "@welshman/util"
import type {TrustedEvent} from "@welshman/util"
2026-09-07 21:39:01 +00:00
import {publish} from "@welshman/app"
import Server from "@assets/icons/server.svg?dataurl"
import Icon from "@lib/components/Icon.svelte"
2026-09-07 20:53:25 +00:00
import Badge from "@lib/components/Badge.svelte"
2026-09-07 21:39:01 +00:00
import Button from "@lib/components/Button.svelte"
2026-09-07 20:53:25 +00:00
import Modal from "@lib/components/Modal.svelte"
import ModalHeader from "@lib/components/ModalHeader.svelte"
import ModalTitle from "@lib/components/ModalTitle.svelte"
import ModalSubtitle from "@lib/components/ModalSubtitle.svelte"
2026-09-07 21:39:01 +00:00
import RelayList from "@app/components/RelayList.svelte"
2026-09-07 20:53:25 +00:00
import RelayName from "@app/components/RelayName.svelte"
import SearchBody from "@app/components/SearchBody.svelte"
import {CONTENT_KINDS} from "@app/content"
2026-09-07 21:39:01 +00:00
import {app, relays, searchRelayLists, user} from "@app/core"
import {pushModal} from "@app/modal"
2026-09-07 20:53:25 +00:00
import {userSpaceUrls} from "@app/rooms"
const filter = {kinds: [MESSAGE, ...CONTENT_KINDS]}
const getSpaceUrl = (event: TrustedEvent) =>
$userSpaceUrls.find(url => $app.tracker.getRelays(event.id).has(url))
2026-09-07 21:39:01 +00:00
const showRelays = () =>
pushModal(RelayList, {
title: "Search Relays",
subtitle: "Relays that support searching for profiles and public notes.",
relays: $searchRelayLists.urls($user.pubkey).$,
addRelay: (url: string) => $searchRelayLists.addUrl(url).then(publish),
removeRelay: (url: string) => $searchRelayLists.removeUrl(url).then(publish),
matchRelay: (url: string) => Boolean($relays.get(url)?.hasNip(50)),
})
2026-09-07 20:53:25 +00:00
</script>
<Modal class="flex flex-col gap-2">
<ModalHeader>
<ModalTitle>Search</ModalTitle>
<ModalSubtitle>across all your spaces</ModalSubtitle>
2026-09-07 21:39:01 +00:00
<Button class="button button-link button-sm self-center" onclick={showRelays}>
<Icon size={4} icon={Server} />
Search relays
</Button>
2026-09-07 20:53:25 +00:00
</ModalHeader>
<SearchBody placeholder="Search your spaces..." relays={$userSpaceUrls} {filter}>
{#snippet badges(event)}
{@const url = getSpaceUrl(event)}
{#if url}
<Badge variant="neutral">
<RelayName {url} />
</Badge>
{/if}
{/snippet}
</SearchBody>
</Modal>