()
| 57 | } |
| 58 | |
| 59 | function SearchContent() { |
| 60 | const router = useRouter() |
| 61 | const searchParams = useSearchParams() |
| 62 | |
| 63 | const typeParam = searchParams.get("type") as ExtensionType | null |
| 64 | const queryParam = searchParams.get("q") || "" |
| 65 | const tagParam = searchParams.get("tag") || "" |
| 66 | |
| 67 | const [searchQuery, setSearchQuery] = useState(queryParam) |
| 68 | const extensions = useQuery(api.extensions.listAllApproved) |
| 69 | |
| 70 | // Update URL with filters |
| 71 | const updateFilters = useCallback((updates: { type?: string | null; q?: string; tag?: string }) => { |
| 72 | const params = new URLSearchParams(searchParams.toString()) |
| 73 | |
| 74 | if (updates.type !== undefined) { |
| 75 | if (updates.type) { |
| 76 | params.set("type", updates.type) |
| 77 | } else { |
| 78 | params.delete("type") |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | if (updates.q !== undefined) { |
| 83 | if (updates.q) { |
| 84 | params.set("q", updates.q) |
| 85 | } else { |
| 86 | params.delete("q") |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | if (updates.tag !== undefined) { |
| 91 | if (updates.tag) { |
| 92 | params.set("tag", updates.tag) |
| 93 | } else { |
| 94 | params.delete("tag") |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | const queryString = params.toString() |
| 99 | router.push(queryString ? `/search?${queryString}` : "/search") |
| 100 | }, [router, searchParams]) |
| 101 | |
| 102 | // Filter extensions based on search params |
| 103 | const filteredExtensions = useMemo(() => { |
| 104 | if (!extensions) return [] |
| 105 | |
| 106 | return extensions.filter((ext) => { |
| 107 | // Filter by type |
| 108 | if (typeParam && ext.type !== typeParam) return false |
| 109 | |
| 110 | // Filter by tag |
| 111 | if (tagParam && !ext.tags.some(t => t.toLowerCase() === tagParam.toLowerCase())) return false |
| 112 | |
| 113 | // Filter by search query |
| 114 | if (queryParam) { |
| 115 | const query = queryParam.toLowerCase() |
| 116 | const matchesName = ext.displayName.toLowerCase().includes(query) |
nothing calls this directly
no outgoing calls
no test coverage detected