From a97065a86a53ba27b29d6a5500169bfd281ad134 Mon Sep 17 00:00:00 2001
From: Vara Rahul Rajana
Date: Tue, 7 Apr 2026 14:07:19 +0530
Subject: [PATCH] refactor: enhance SpaceSearch component with unique filtering
and improved search UI
---
src/app/components/SpaceSearch.svelte | 37 ++--
src/routes/spaces/[relay]/recent/+page.svelte | 184 +-----------------
2 files changed, 24 insertions(+), 197 deletions(-)
diff --git a/src/app/components/SpaceSearch.svelte b/src/app/components/SpaceSearch.svelte
index 6372f6cf..f0ab0ef7 100644
--- a/src/app/components/SpaceSearch.svelte
+++ b/src/app/components/SpaceSearch.svelte
@@ -2,7 +2,7 @@
import {tick} from "svelte"
import {debounce} from "throttle-debounce"
import {request} from "@welshman/net"
- import {formatTimestampAsDate, groupBy, now, MINUTE, HOUR, DAY, WEEK} from "@welshman/lib"
+ import {formatTimestampAsDate, groupBy, now, uniqBy, MINUTE, HOUR, DAY, WEEK} from "@welshman/lib"
import type {TrustedEvent, Filter} from "@welshman/util"
import {sortEventsDesc} from "@welshman/util"
import CloseCircle from "@assets/icons/close-circle.svg?dataurl"
@@ -10,15 +10,17 @@
import {fly} from "@lib/transition"
import Button from "@lib/components/Button.svelte"
import Icon from "@lib/components/Icon.svelte"
+ import NoteContentMinimal from "@app/components/NoteContentMinimal.svelte"
import {CONTENT_KINDS} from "@app/core/state"
import {goToEvent} from "@app/util/routes"
type Props = {
url: string
h?: string
+ kinds?: number[]
}
- const {url, h}: Props = $props()
+ const {url, h, kinds = CONTENT_KINDS}: Props = $props()
let term = $state("")
let show = $state(false)
@@ -52,9 +54,7 @@
const getRelayUrls = () => [url]
const getFilter = (searchTerm: string): Filter =>
- h
- ? {kinds: CONTENT_KINDS, "#h": [h], search: searchTerm}
- : {kinds: CONTENT_KINDS, search: searchTerm}
+ h ? {kinds, "#h": [h], search: searchTerm} : {kinds, search: searchTerm}
const search = debounce(300, async (searchTerm: string) => {
controller?.abort()
@@ -76,7 +76,7 @@
filters: [getFilter(searchTerm.trim())],
})
- results = sortEventsDesc(events)
+ results = sortEventsDesc(uniqBy(e => e.id, events))
} catch (error) {
if (!(error instanceof DOMException && error.name === "AbortError")) {
results = []
@@ -86,12 +86,6 @@
}
})
- const onInput = () => {
- void search(term)
- }
-
- const eventsByAge = $derived(groupBy(e => getAgeSection(e.created_at), results))
-
const getAgeSection = (createdAt: number) => {
const age = now() - createdAt
@@ -124,6 +118,12 @@
return `${Math.floor(age / DAY)}d ago`
}
+ const onInput = () => {
+ void search(term)
+ }
+
+ const eventsByAge = $derived(groupBy(e => getAgeSection(e.created_at), results))
+
const onRoomSearchResultClick = (event: TrustedEvent) => {
close()
goToEvent(event, {keepFocus: true})
@@ -162,9 +162,12 @@
{h ? "Search for content in this room." : "Search for content in this space."}
{:else if loading}
- Searching...
+
{:else if eventsByAge.size === 0}
- No results found.
+ No results found.
{:else}
{#each eventsByAge as [key, events] (key)}
@@ -181,11 +184,9 @@
{#each events as event (event.id)}