mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
fix(search): remove 20-result cap for hub search and add scroll-to-load
Hub search was capped at 20 results because it shared the same normalizeLimit() path as GitHub search. Hub indexes are static JSON (~100 entries), so returning all results is expected. - Remove normalizeLimit() from hub search path; limit=0 means no limit - Backend defaults to limit=0 for hub requests, 20 for GitHub - CLI uses limit=0 when --hub is set without explicit --limit - Frontend searchHub() no longer sends a limit parameter - Replace IIFE rendering with useMemo for stable filter results - Add IntersectionObserver-based scroll-to-load (20 items per batch)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<CheckResult>('/check'),
|
||||
discover: (source: string) =>
|
||||
apiFetch<DiscoverResult>('/discover', {
|
||||
|
||||
+46
-16
@@ -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<string | null>(null);
|
||||
|
||||
// Incremental rendering
|
||||
const PAGE_SIZE = 20;
|
||||
const [visibleCount, setVisibleCount] = useState(PAGE_SIZE);
|
||||
const sentinelRef = useRef<HTMLDivElement>(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<DiscoveredSkill[]>([]);
|
||||
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() {
|
||||
</Card>
|
||||
|
||||
{/* 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 && (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center gap-3 flex-wrap">
|
||||
<p className="text-base text-pencil-light whitespace-nowrap">
|
||||
@@ -406,10 +436,10 @@ export default function SearchPage() {
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{filteredResults.map((r, i) => (
|
||||
{visible.map((r) => (
|
||||
<Card
|
||||
key={r.source}
|
||||
className={i % 2 === 0 ? 'rotate-[-0.15deg]' : 'rotate-[0.15deg]'}
|
||||
className="odd:rotate-[-0.15deg] even:rotate-[0.15deg]"
|
||||
>
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<div className="flex-1 min-w-0">
|
||||
@@ -458,9 +488,9 @@ export default function SearchPage() {
|
||||
</div>
|
||||
</Card>
|
||||
))}
|
||||
{hasMore && <div ref={sentinelRef} className="h-4" />}
|
||||
</div>
|
||||
);
|
||||
})()}
|
||||
)}
|
||||
|
||||
{results && results.length === 0 && (
|
||||
<EmptyState
|
||||
|
||||
Reference in New Issue
Block a user