Something went wrong. Try again.
link aggregator for FIRST Tech Challenge tools & resources firsttech.tools
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185import { createSignal, createMemo, For, Show } from "solid-js";import type { Category, Tool } from "../lib/schema.ts";import ToolCard from "./ToolCard.tsx";
interface Props { categories: Category[]; tools: Tool[];}
export default function ToolDirectory(props: Props) { const [selectedKeys, setSelectedKeys] = createSignal<Set<string>>(new Set()); const [query, setQuery] = createSignal(""); const [drawerOpen, setDrawerOpen] = createSignal(false);
function toggleCategory(key: string) { setSelectedKeys((prev) => { const next = new Set(prev); if (next.has(key)) { next.delete(key); } else { next.add(key); } return next; }); }
function clearFilters() { setSelectedKeys(new Set<string>()); setQuery(""); }
const activeFilterCount = createMemo( () => selectedKeys().size + (query().trim() !== "" ? 1 : 0) );
const visibleTools = createMemo(() => { const keys = selectedKeys(); const q = query().toLowerCase().trim();
return props.tools.filter((tool) => { // Category filter: if no keys selected, pass all; else OR/union const categoryMatch = keys.size === 0 || tool.categories.some((k) => keys.has(k));
// Text search: case-insensitive substring on name, description, author const textMatch = q === "" || tool.name.toLowerCase().includes(q) || tool.description.toLowerCase().includes(q) || (tool.author?.toLowerCase().includes(q) ?? false);
return categoryMatch && textMatch; }); });
// Shared filter controls, reused by the desktop header row and the mobile drawer. const FilterControls = (props2: { compact?: boolean }) => ( <div class="flex flex-col gap-3"> <input type="search" placeholder="Search tools..." value={query()} onInput={(e) => setQuery(e.currentTarget.value)} class={`rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring ${ props2.compact ? "w-full" : "w-full max-w-xs" }`} />
<div class={`flex gap-2 ${props2.compact ? "flex-col" : "flex-wrap"}`}> <For each={props.categories}> {(cat) => { const active = () => selectedKeys().has(cat.key); return ( <button onClick={() => toggleCategory(cat.key)} class={`rounded-full px-3 py-1 text-xs font-medium border transition-colors ${ props2.compact ? "text-left" : "" } ${ active() ? "bg-primary text-primary-foreground border-primary" : "bg-background text-foreground border-border hover:bg-accent" }`} > {cat.label} </button> ); }} </For> </div>
<Show when={activeFilterCount() > 0}> <button onClick={clearFilters} class="self-start rounded-md border border-border bg-background text-foreground text-xs px-3 py-1 hover:bg-accent transition-colors" > Clear filters ({activeFilterCount()}) </button> </Show> </div> );
return ( <div class="flex flex-col gap-5"> {/* Mobile: filters trigger button (hidden on sm+) */} <div class="sm:hidden flex items-center justify-between"> <button onClick={() => setDrawerOpen(true)} class="inline-flex items-center gap-2 rounded-md border border-border bg-background px-3 py-2 text-sm font-medium hover:bg-accent transition-colors" > Filters <Show when={activeFilterCount() > 0}> <span class="inline-flex items-center justify-center rounded-full bg-primary text-primary-foreground text-[10px] font-semibold h-4 min-w-4 px-1"> {activeFilterCount()} </span> </Show> </button> <span class="text-xs text-muted-foreground"> {visibleTools().length} tool{visibleTools().length === 1 ? "" : "s"} </span> </div>
{/* Desktop: inline filter header (hidden below sm) */} <div class="hidden sm:block"> <FilterControls /> </div>
{/* Card grid or empty state */} <Show when={visibleTools().length > 0} fallback={ <div class="text-center py-16 flex flex-col items-center gap-3"> <p class="text-muted-foreground text-sm">No tools match your filters.</p> <button onClick={clearFilters} class="rounded-md border border-border bg-background text-foreground text-sm px-4 py-2 hover:bg-accent transition-colors" > Clear filters </button> </div> } > <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3"> <For each={visibleTools()}> {(tool) => <ToolCard tool={tool} />} </For> </div> </Show>
{/* Mobile drawer */} <Show when={drawerOpen()}> <div class="sm:hidden fixed inset-0 z-50"> {/* Backdrop */} <div class="absolute inset-0 bg-black/50 animate-in fade-in" onClick={() => setDrawerOpen(false)} /> {/* Panel */} <div class="absolute inset-y-0 left-0 w-72 max-w-[80%] bg-background border-r border-border shadow-xl p-4 flex flex-col gap-4 animate-in slide-in-from-left"> <div class="flex items-center justify-between"> <h2 class="text-sm font-semibold">Filters</h2> <button onClick={() => setDrawerOpen(false)} aria-label="Close filters" class="rounded-md p-1 text-muted-foreground hover:bg-accent transition-colors" > Close </button> </div> <div class="flex-1 overflow-y-auto"> <FilterControls compact /> </div> <button onClick={() => setDrawerOpen(false)} class="rounded-md bg-primary text-primary-foreground text-sm font-medium px-4 py-2 hover:bg-primary/90 transition-colors" > Show {visibleTools().length} tool{visibleTools().length === 1 ? "" : "s"} </button> </div> </div> </Show> </div> );}