make contextual search h-based again

This commit is contained in:
Bhavishy
2026-04-02 23:56:02 +05:30
parent 600fc30eee
commit 63b1cd125e
+7 -33
View File
@@ -20,22 +20,15 @@
const {url, h}: Props = $props() const {url, h}: Props = $props()
type SearchScope = "room" | "space"
const scopes: SearchScope[] = h ? ["room", "space"] : ["space"]
let term = $state("") let term = $state("")
let show = $state(false) let show = $state(false)
let scope = $state<SearchScope>(h ? "room" : "space")
let results = $state<TrustedEvent[]>([]) let results = $state<TrustedEvent[]>([])
let loading = $state(false) let loading = $state(false)
let input: HTMLInputElement | undefined = $state() let input: HTMLInputElement | undefined = $state()
let controller: AbortController | undefined let controller: AbortController | undefined
const relayStatus = $derived( const relayStatus = $derived(
scope === "room" h ? `Searching this room on relay: ${url}.` : `Searching this space on relay: ${url}.`,
? `Using space relay: ${url} (room filter applied).`
: `Using space relay: ${url}.`,
) )
const open = () => { const open = () => {
@@ -58,13 +51,10 @@
const getRelayUrls = () => [url] const getRelayUrls = () => [url]
const getFilter = (searchTerm: string): Filter => { const getFilter = (searchTerm: string): Filter =>
if (scope === "room" && h) { h
return {kinds: CONTENT_KINDS, "#h": [h], search: searchTerm} ? {kinds: CONTENT_KINDS, "#h": [h], search: searchTerm}
} : {kinds: CONTENT_KINDS, search: searchTerm}
return {kinds: CONTENT_KINDS, search: searchTerm}
}
const search = debounce(300, async (searchTerm: string) => { const search = debounce(300, async (searchTerm: string) => {
controller?.abort() controller?.abort()
@@ -100,11 +90,6 @@
void search(term) void search(term)
} }
const setScope = (value: SearchScope) => {
scope = value
void search(term)
}
const eventsByAge = $derived(groupBy(e => getAgeSection(e.created_at), results)) const eventsByAge = $derived(groupBy(e => getAgeSection(e.created_at), results))
const getAgeSection = (createdAt: number) => { const getAgeSection = (createdAt: number) => {
@@ -168,25 +153,14 @@
bind:value={term} bind:value={term}
class="min-w-0 grow" class="min-w-0 grow"
type="text" type="text"
placeholder={scope === "room" ? "Search this room..." : "Search this space..."} placeholder={h ? "Search this room..." : "Search this space..."}
oninput={onInput} /> oninput={onInput} />
</label> </label>
<div class="flex flex-wrap gap-1">
{#each scopes as value (value)}
<Button
class={value === scope ? "btn btn-neutral btn-xs" : "btn btn-ghost btn-xs"}
onclick={() => setScope(value)}>
{value === "room" ? "Room" : "Space"}
</Button>
{/each}
</div>
<div class="max-h-[65vh] overflow-y-auto"> <div class="max-h-[65vh] overflow-y-auto">
<p class="mb-2 text-xs opacity-70">{relayStatus}</p> <p class="mb-2 text-xs opacity-70">{relayStatus}</p>
{#if !term} {#if !term}
<p class="text-sm opacity-70"> <p class="text-sm opacity-70">
{scope === "room" {h ? "Search for content in this room." : "Search for content in this space."}
? "Search for content in this room."
: "Search for content in this space."}
</p> </p>
{:else if loading} {:else if loading}
<p class="text-sm opacity-70">Searching...</p> <p class="text-sm opacity-70">Searching...</p>