From 2c05bc69616a8ea6d3805ba1397f48352e62bb1c Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Mon, 16 Feb 2026 09:03:00 -0800 Subject: [PATCH] Refactor SpaceSearch into its own component --- AGENTS.md | 3 +- src/app.css | 4 + src/app/components/SpaceMenuButton.svelte | 2 +- src/app/components/SpaceSearch.svelte | 168 ++++++++ src/app/core/requests.ts | 47 -- src/lib/components/PageContent.svelte | 2 +- src/routes/spaces/[relay]/[h]/+page.svelte | 450 +------------------- src/routes/spaces/[relay]/chat/+page.svelte | 131 +----- 8 files changed, 195 insertions(+), 612 deletions(-) create mode 100644 src/app/components/SpaceSearch.svelte diff --git a/AGENTS.md b/AGENTS.md index 74bbf0ec..f1aa7e3b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -157,7 +157,7 @@ src/ - Derive all other data inside the component from identifiers - Example: Don't pass `members` prop, derive it from `h` inside component -**Code Style:** +**CRITICAL Code Style Guidelines:** - **No `null`** - only use `undefined` - Svelte 5 runes (`$state`, `$derived`, `$effect`) only in UI components @@ -168,6 +168,7 @@ src/ - When dynamically building classes, use `cx` from `classnames` rather than embedded ternaries or svelte 4's old `class:` syntax. - When creating forms, use `FieldInline` or `Field` instead of custom elements/tailwindcss - Do not define svelte event handlers inline, instead name them and put them in the script section of templates +- Avoid using `as`, except where necessary. Instead, annotate function parameters, and ensure upstream values are typed correctly. ## Common Tasks diff --git a/src/app.css b/src/app.css index aaddd0cd..09fbae83 100644 --- a/src/app.css +++ b/src/app.css @@ -402,6 +402,10 @@ progress[value]::-webkit-progress-value { @apply md:bottom-sai bottom-[calc(var(--saib)+3.5rem)]; } +.ct { + @apply top-[calc(var(--sait)+5rem)] md:top-[calc(var(--sait)+3rem)]; +} + /* Keyboard open state adjustments */ body.keyboard-open .cb { diff --git a/src/app/components/SpaceMenuButton.svelte b/src/app/components/SpaceMenuButton.svelte index 87e40d20..b5c0e7c5 100644 --- a/src/app/components/SpaceMenuButton.svelte +++ b/src/app/components/SpaceMenuButton.svelte @@ -13,7 +13,7 @@ const openMenu = () => pushDrawer(SpaceMenu, {url}) - + {#if show} + +
+
+
+ Search + +
+ +
+ {#if !term} +

+ {h ? "Search for messages in this room." : "Search for messages across this space."} +

+ {:else if eventsByAge.size === 0} +

No results found.

+ {:else} +
+ {#each eventsByAge as [key, events] (key)} +
+

+ {#if key === "day"} + Last 24 Hours + {:else if key === "week"} + Last 7 Days + {:else} + Older + {/if} +

+
+ {#each events as event (event.id)} + + {/each} +
+
+ {/each} +
+ {/if} +
+
+
+ {/if} + diff --git a/src/app/core/requests.ts b/src/app/core/requests.ts index 6c45ec70..abfecfc6 100644 --- a/src/app/core/requests.ts +++ b/src/app/core/requests.ts @@ -131,55 +131,8 @@ export const makeFeed = ({ insertEvent(event) } - const reveal = (id: string, targetEvent?: TrustedEvent) => { - const current = get(events) - - if (current.find(e => e.id === id)) { - return true - } - - const queued = get(buffer) - const index = queued.findIndex(e => e.id === id) - - if (index === -1) { - const event = targetEvent || repository.getEvent(id) - - if (event && matchFilters(filters, event)) { - insertEvent(event) - - const next = get(events) - - if (next.find(e => e.id === id)) { - return true - } - - const queuedNext = get(buffer) - const queuedIndex = queuedNext.findIndex(e => e.id === id) - - if (queuedIndex > -1) { - const count = Math.max(30, queuedIndex + 1) - const chunk = queuedNext.splice(0, count) - - events.update($events => [...$events, ...chunk]) - - return true - } - } - - return false - } - - const count = Math.max(30, index + 1) - const chunk = queued.splice(0, count) - - events.update($events => [...$events, ...chunk]) - - return true - } - return { events, - reveal, cleanup: () => { scroller.stop() controller.abort() diff --git a/src/lib/components/PageContent.svelte b/src/lib/components/PageContent.svelte index e29379ee..84483d6d 100644 --- a/src/lib/components/PageContent.svelte +++ b/src/lib/components/PageContent.svelte @@ -12,7 +12,7 @@ const className = cx( props.class, - "scroll-container cw cb fixed top-[calc(var(--sait)+5rem)] md:top-[calc(var(--sait)+3rem)] z-feature overflow-y-auto overflow-x-hidden", + "scroll-container cw cb ct fixed z-feature overflow-y-auto overflow-x-hidden", ) diff --git a/src/routes/spaces/[relay]/[h]/+page.svelte b/src/routes/spaces/[relay]/[h]/+page.svelte index 957159b3..201add1c 100644 --- a/src/routes/spaces/[relay]/[h]/+page.svelte +++ b/src/routes/spaces/[relay]/[h]/+page.svelte @@ -1,37 +1,23 @@ @@ -395,7 +275,10 @@ Chat {/snippet} {#snippet action()} - +
+ + +
{/snippet}