diff --git a/CHANGELOG.md b/CHANGELOG.md index edf7da573..6bfbda73c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## [0.12.2] - 2026-02-13 + +### Fixed +- **Hub search returns all results** — hub/index search no longer capped at 20; `limit=0` means no limit (GitHub search default unchanged) +- **Search filter ghost cards** — replaced IIFE rendering with `useMemo` to fix stale DOM when filtering results + +### Added +- **Scroll-to-load in Web UI** — search results render 20 at a time with IntersectionObserver-based incremental loading + ## [0.12.1] - 2026-02-13 ### Added diff --git a/cmd/skillshare/search.go b/cmd/skillshare/search.go index e52a79248..4e98847f7 100644 --- a/cmd/skillshare/search.go +++ b/cmd/skillshare/search.go @@ -48,6 +48,7 @@ func cmdSearch(args []string) error { var hubInput string // raw --hub value var hubBare bool // --hub with no value var limit int = 20 + var limitSet bool // Parse remaining arguments i := 0 @@ -69,6 +70,7 @@ func cmdSearch(args []string) error { hubBare = true } case key == "--limit" || key == "-n": + limitSet = true if hasEq { n, err := strconv.Atoi(strings.TrimSpace(val)) if err != nil || n < 1 { @@ -111,6 +113,11 @@ func cmdSearch(args []string) error { indexURL = resolved } + // Hub search returns all results by default (limit=0 means no limit) + if indexURL != "" && !limitSet { + limit = 0 + } + // JSON mode: silent search, output JSON if jsonOutput { return searchJSON(query, limit, indexURL) diff --git a/internal/search/index.go b/internal/search/index.go index 2cf77c275..95b2112e8 100644 --- a/internal/search/index.go +++ b/internal/search/index.go @@ -25,8 +25,8 @@ type indexSkill struct { } // SearchFromIndexURL searches skills from a private index.json URL or local path. +// A limit of 0 means no limit (return all results). func SearchFromIndexURL(query string, limit int, indexURL string) ([]SearchResult, error) { - limit = normalizeLimit(limit) doc, err := loadIndex(indexURL) if err != nil { return nil, err @@ -36,8 +36,8 @@ func SearchFromIndexURL(query string, limit int, indexURL string) ([]SearchResul // SearchFromIndexJSON searches skills from raw index JSON data. // Used by the server to search an in-memory index without file I/O. +// A limit of 0 means no limit (return all results). func SearchFromIndexJSON(query string, limit int, data []byte) ([]SearchResult, error) { - limit = normalizeLimit(limit) var doc indexDocument if err := json.Unmarshal(data, &doc); err != nil { return nil, fmt.Errorf("parse hub: %w", err) @@ -89,7 +89,7 @@ func searchIndex(query string, limit int, doc *indexDocument) ([]SearchResult, e sort.Slice(results, func(i, j int) bool { return results[i].Name < results[j].Name }) - if len(results) > limit { + if limit > 0 && len(results) > limit { results = results[:limit] } return results, nil diff --git a/internal/server/handler_search.go b/internal/server/handler_search.go index 77cf2bf6d..c3fc8b3af 100644 --- a/internal/server/handler_search.go +++ b/internal/server/handler_search.go @@ -14,7 +14,7 @@ func (s *Server) handleSearch(w http.ResponseWriter, r *http.Request) { query := r.URL.Query().Get("q") hubParam := r.URL.Query().Get("hub") - limit := 20 + limit := 0 // default: no limit for hub search if l := r.URL.Query().Get("limit"); l != "" { if parsed, err := strconv.Atoi(l); err == nil { limit = parsed @@ -29,6 +29,10 @@ func (s *Server) handleSearch(w http.ResponseWriter, r *http.Request) { case hubParam != "": results, err = search.SearchFromIndexURL(query, limit, hubParam) default: + // GitHub search always needs a limit + if limit <= 0 { + limit = 20 + } results, err = search.Search(query, limit) } if err != nil { diff --git a/ui/src/api/client.ts b/ui/src/api/client.ts index 8b901f825..e2cf56ff0 100644 --- a/ui/src/api/client.ts +++ b/ui/src/api/client.ts @@ -72,8 +72,8 @@ export const api = { // Search & Install search: (q: string, limit = 20) => apiFetch<{ results: SearchResult[] }>(`/search?q=${encodeURIComponent(q)}&limit=${limit}`), - searchHub: (q: string, hubURL: string, limit = 20) => - apiFetch<{ results: SearchResult[] }>(`/search?q=${encodeURIComponent(q)}&limit=${limit}&hub=${encodeURIComponent(hubURL)}`), + searchHub: (q: string, hubURL: string) => + apiFetch<{ results: SearchResult[] }>(`/search?q=${encodeURIComponent(q)}&hub=${encodeURIComponent(hubURL)}`), check: () => apiFetch('/check'), discover: (source: string) => apiFetch('/discover', { diff --git a/ui/src/pages/SearchPage.tsx b/ui/src/pages/SearchPage.tsx index fa7910aee..5b8c96a22 100644 --- a/ui/src/pages/SearchPage.tsx +++ b/ui/src/pages/SearchPage.tsx @@ -1,4 +1,4 @@ -import { useState, useCallback, useEffect } from 'react'; +import { useState, useCallback, useEffect, useRef, useMemo } from 'react'; import { Search, Star, Download, Globe, Database, Settings } from 'lucide-react'; import Card from '../components/Card'; import Badge from '../components/Badge'; @@ -43,6 +43,25 @@ export default function SearchPage() { // Install state const [installing, setInstalling] = useState(null); + // Incremental rendering + const PAGE_SIZE = 20; + const [visibleCount, setVisibleCount] = useState(PAGE_SIZE); + const sentinelRef = useRef(null); + + const filteredResults = useMemo(() => { + if (!results || results.length === 0) return []; + if (!filter) return results; + const f = filter.toLowerCase(); + return results.filter((r) => + r.name.toLowerCase().includes(f) || + r.description.toLowerCase().includes(f) || + (r.tags ?? []).some((t) => t.toLowerCase().includes(f)), + ); + }, [results, filter]); + + const visible = filteredResults.slice(0, visibleCount); + const hasMore = visible.length < filteredResults.length; + // Discovery flow state const [discoveredSkills, setDiscoveredSkills] = useState([]); const [showPicker, setShowPicker] = useState(false); @@ -54,6 +73,27 @@ export default function SearchPage() { fetchHubConfig(); }, []); + // Reset visible count when results or filter change + useEffect(() => { + setVisibleCount(PAGE_SIZE); + }, [filteredResults]); + + // IntersectionObserver: load more when sentinel scrolls into view + useEffect(() => { + const el = sentinelRef.current; + if (!el) return; + const observer = new IntersectionObserver( + ([entry]) => { + if (entry.isIntersecting) { + setVisibleCount((prev) => prev + PAGE_SIZE); + } + }, + { rootMargin: '200px' }, + ); + observer.observe(el); + return () => observer.disconnect(); + }, [hasMore]); + const fetchHubConfig = async () => { try { const res = await api.getHubConfig(); @@ -375,17 +415,7 @@ export default function SearchPage() { {/* Results */} - {results && results.length > 0 && (() => { - const filteredResults = results.filter((r) => { - if (!filter) return true; - const f = filter.toLowerCase(); - return ( - r.name.toLowerCase().includes(f) || - r.description.toLowerCase().includes(f) || - (r.tags ?? []).some((t) => t.toLowerCase().includes(f)) - ); - }); - return ( + {results && results.length > 0 && (

@@ -406,10 +436,10 @@ export default function SearchPage() { />

- {filteredResults.map((r, i) => ( + {visible.map((r) => (
@@ -458,9 +488,9 @@ export default function SearchPage() {
))} + {hasMore &&
}
- ); - })()} + )} {results && results.length === 0 && (