| @@ -8,12 +8,26 @@ | |||||
| 8 | font-size: 0.875rem; | 8 | font-size: 0.875rem; | ||
| 9 | } | 9 | } | ||
| 10 | | 10 | | ||
| 11 | Removed: .field input { | 11 | Added: .control { | ||
| 12 | Added: position: relative; | ||||
| 13 | Added: } | ||||
| 14 | Added: | ||||
| 15 | Added: .control input { | ||||
| 16 | width: 100%; | 16 | width: 100%; | ||
| 13 | Removed: padding: 0.5rem 0.75rem; | 17 | Added: padding: 0.5rem 2.25rem 0.5rem 0.75rem; | ||
| 18 | border: 0.0625rem solid var(--line); | 18 | border: 0.0625rem solid var(--line); | ||
| 19 | border-radius: 0.5rem; | 19 | border-radius: 0.5rem; | ||
| 20 | } | 20 | } | ||
| 21 | | 21 | | ||
| 22 | Added: .spinner { | ||||
| 23 | Added: position: absolute; | ||||
| 24 | Added: inset-block: 0; | ||||
| 25 | Added: right: 0.75rem; | ||||
| 26 | Added: margin-block: auto; | ||||
| 27 | Added: } | ||||
| 28 | Added: | ||||
| 29 | .results { | 29 | .results { | ||
| 30 | margin-top: 0.25rem; | 30 | margin-top: 0.25rem; | ||
Code review template for React
A pull request review with a file list, a split or unified diff, line comments and live checks, styled by Clicky.
Start free 14-day trialkestrel/fieldbook-web
Search waits for typing to pause and reuses recent results #482
| @@ -1,18 +1,27 @@ | |||||
| 1 | import { useId, useState } from "react"; | 1 | import { useId, useState } from "react"; | ||
| 2 | import { useSearch } from "../hooks/use-search"; | 2 | import { useSearch } from "../hooks/use-search"; | ||
| 3 | Added: import { Spinner } from "./spinner"; | ||||
| 4 | import styles from "./search-field.module.css"; | 4 | import styles from "./search-field.module.css"; | ||
| 5 | | 5 | | ||
| 6 | export function SearchField({ onPick }: { onPick: (id: string) => void }) { | 6 | export function SearchField({ onPick }: { onPick: (id: string) => void }) { | ||
| 7 | const id = useId(); | 7 | const id = useId(); | ||
| 8 | const [query, setQuery] = useState(""); | 8 | const [query, setQuery] = useState(""); | ||
| 8 | Removed: const { hits } = useSearch(query); | 9 | Added: const { hits, loading } = useSearch(query); | ||
| 10 | | 10 | | ||
| 11 | return ( | 11 | return ( | ||
| 11 | Removed: <div className={styles.field}> | 12 | Added: <div className={styles.field} aria-busy={loading}> | ||
| 13 | <label htmlFor={id}>Search notes</label> | 13 | <label htmlFor={id}>Search notes</label> | ||
| 13 | Removed: <input id={id} value={query} onChange={(e) => setQuery(e.target.value)} /> | 14 | Added: <div className={styles.control}> | ||
| 15 | Added: <input | ||||
| 16 | Added: id={id} | ||||
| 17 | Added: type="search" | ||||
| 18 | Added: value={query} | ||||
| 19 | Added: onChange={(e) => setQuery(e.target.value)} | ||||
| 20 | Added: /> | ||||
| 21 | Added: {loading && <Spinner className={styles.spinner} label="Searching" />} | ||||
| 22 | Added: </div> | ||||
| 23 | <ul className={styles.results}> | 23 | <ul className={styles.results}> | ||
| 24 | {hits.map((hit) => ( | 24 | {hits.map((hit) => ( | ||
| 25 | <li key={hit.id}> | 25 | <li key={hit.id}> | ||
| @@ -1,6 +1,9 @@ | |||||
| 1 | import { useEffect, useState } from "react"; | 1 | import { useEffect, useState } from "react"; | ||
| 2 | Added: import { createQueryCache } from "../lib/query-cache"; | ||||
| 3 | import { searchNotes, type NoteHit } from "../api/notes"; | 3 | import { searchNotes, type NoteHit } from "../api/notes"; | ||
| 4 | | 4 | | ||
| 5 | Added: const cache = createQueryCache<NoteHit[]>({ limit: 30 }); | ||||
| 6 | Added: const DEBOUNCE_MS = 180; | ||||
| 7 | Added: | ||||
| 8 | export interface SearchState { | 8 | export interface SearchState { | ||
| 9 | hits: NoteHit[]; | 9 | hits: NoteHit[]; | ||
| 10 | loading: boolean; | 10 | loading: boolean; | ||
| @@ -14,22 +17,34 @@ export function useSearch(query: string): SearchState { | |||||
| 17 | const [error, setError] = useState<Error | null>(null); | 17 | const [error, setError] = useState<Error | null>(null); | ||
| 18 | | 18 | | ||
| 19 | useEffect(() => { | 19 | useEffect(() => { | ||
| 17 | Removed: if (!query) { | 20 | Added: const trimmed = query.trim(); | ||
| 21 | Added: if (!trimmed) { | ||||
| 22 | setHits([]); | 22 | setHits([]); | ||
| 23 | return; | 23 | return; | ||
| 24 | } | 24 | } | ||
| 21 | Removed: setLoading(true); | 25 | Added: const cached = cache.get(trimmed); | ||
| 22 | Removed: searchNotes(query) | 26 | Added: if (cached) { | ||
| 23 | Removed: .then(setHits) | 27 | Added: setHits(cached); | ||
| 24 | Removed: .catch(setError) | 28 | Added: return; | ||
| 25 | Removed: .finally(() => setLoading(false)); | 29 | Added: } | ||
| 30 | Added: const controller = new AbortController(); | ||||
| 31 | Added: const timer = window.setTimeout(() => { | ||||
| 32 | Added: setLoading(true); | ||||
| 33 | Added: searchNotes(trimmed, { signal: controller.signal }) | ||||
| 34 | Added: .then((result) => { | ||||
| 35 | Added: cache.set(trimmed, result); | ||||
| 36 | Added: setHits(result); | ||||
| 37 | Added: }) | ||||
| 38 | Added: .catch((err) => { | ||||
| 39 | Added: if (err.name !== "AbortError") setError(err); | ||||
| |||||
| 40 | Added: }) | ||||
| 41 | Added: .finally(() => setLoading(false)); | ||||
| 42 | Added: }, DEBOUNCE_MS); | ||||
| 43 | Added: return () => { | ||||
| 44 | Added: window.clearTimeout(timer); | ||||
| 45 | Added: controller.abort(); | ||||
| 46 | Added: }; | ||||
| 47 | }, [query]); | 47 | }, [query]); | ||
| 48 | | 48 | | ||
| 49 | return { hits, loading, error }; | 49 | return { hits, loading, error }; | ||
| 50 | } | 50 | } | ||
| @@ -0,0 +1,18 @@ | |||||
| 1 | Added: import { act, renderHook } from "@testing-library/react"; | ||||
| 2 | Added: import { afterEach, describe, expect, it, vi } from "vitest"; | ||||
| 3 | Added: import * as api from "../api/notes"; | ||||
| 4 | Added: import { useSearch } from "./use-search"; | ||||
| 5 | Added: | ||||
| 6 | Added: describe("useSearch", () => { | ||||
| 7 | Added: afterEach(() => vi.useRealTimers()); | ||||
| 8 | Added: | ||||
| 9 | Added: it("waits for typing to pause before it searches", async () => { | ||||
| 10 | Added: vi.useFakeTimers(); | ||||
| 11 | Added: const search = vi.spyOn(api, "searchNotes").mockResolvedValue([]); | ||||
| 12 | Added: const { rerender } = renderHook(({ q }) => useSearch(q), { initialProps: { q: "ha" } }); | ||||
| 13 | Added: rerender({ q: "harbour" }); | ||||
| 14 | Added: await act(() => vi.advanceTimersByTimeAsync(200)); | ||||
| 15 | Added: expect(search).toHaveBeenCalledTimes(1); | ||||
| 16 | Added: expect(search).toHaveBeenCalledWith("harbour", expect.anything()); | ||||
| 17 | Added: }); | ||||
| 18 | Added: }); | ||||
| @@ -0,0 +1,33 @@ | |||||
| 1 | Added: /** Keeps recent search results in memory, keyed by the trimmed, lower-case query. */ | ||||
| 2 | Added: export interface CacheEntry<T> { | ||||
| 3 | Added: value: T; | ||||
| 4 | Added: storedAt: number; | ||||
| 5 | Added: } | ||||
| 6 | Added: | ||||
| 7 | Added: export function createQueryCache<T>({ limit = 20, ttlMs = 60_000 } = {}) { | ||||
| 8 | Added: const entries = new Map<string, CacheEntry<T>>(); | ||||
| 9 | Added: const key = (query: string) => query.trim().toLowerCase(); | ||||
| 10 | Added: | ||||
| 11 | Added: return { | ||||
| 12 | Added: get(query: string): T | undefined { | ||||
| 13 | Added: const hit = entries.get(key(query)); | ||||
| 14 | Added: if (!hit) return undefined; | ||||
| 15 | Added: if (Date.now() - hit.storedAt > ttlMs) { | ||||
| 16 | Added: entries.delete(key(query)); | ||||
| 17 | Added: return undefined; | ||||
| 18 | Added: } | ||||
| 19 | Added: return hit.value; | ||||
| 20 | Added: }, | ||||
| 21 | Added: set(query: string, value: T) { | ||||
| 22 | Added: entries.delete(key(query)); | ||||
| 23 | Added: entries.set(key(query), { value, storedAt: Date.now() }); | ||||
| 24 | Added: if (entries.size > limit) { | ||||
| 25 | Added: // A Map keeps insertion order, so the first key is the oldest one. | ||||
| 26 | Added: const oldest = entries.keys().next().value; | ||||
Resolved: Tomás Reyes on line 26 | |||||
| 27 | Added: if (oldest !== undefined) entries.delete(oldest); | ||||
| 28 | Added: } | ||||
| 29 | Added: }, | ||||
| 30 | Added: clear: () => entries.clear(), | ||||
| 31 | Added: }; | ||||
| 32 | Added: } | ||||
Built on the stack you already use
- React
- Next.js
- TypeScript
- Tailwind CSS
- shadcn/ui
- Radix UI
Everything the screen needs
Source you own
Download the source with Pro. Every line lands in your repo.
Many design systems
Switch the same layout between design systems that fit it, with no rewrite.
One theme for every screen
Colors, corner radius and shadows come from CSS variables, so one change restyles it all.
Built by your agent
Ask Claude Code, Cursor or Codex for this screen. The MCP gives it the system and the rules.
Checked before handoff
Your agent reviews accessibility, spacing and copy against the review rules.
Interface only
No database or sign-in wiring to remove. Connect the data you already have.
Free to build. Pay for your own brand.
Limited
For individual builders.
$0forever
300 tool calls a month
- Everything in Pro
- Not included: Templates
- Not included: GitHub PR reviews
Pro
For builders who ship every day.
$24/ month
Unlimited tool calls
- Your brand guidelines, kept private, applied to every build
- Design systems
- Slides
- Illustrations
- Video
- Mobile tools
- 3D tools
- Shopify tools
- Templates
- GitHub PR reviews
Agency & Enterprise
One private brand for every client, product, or business unit.
Custompricing
- Everything in Pro
- A separate private brand for every client or business unit
- White label under your own name
- We set it up with you
Questions
What is in the Code review template?
A pull request review with a file list, a split or unified diff, line comments and live checks. Every part is a shadcn-compatible component you can edit.
Is it free?
Looking is free, and so is asking your coding agent to build this screen on the free Limited plan. Downloading the source comes with Pro, from $20 a month billed yearly, and the 14-day trial counts.
How do I install it?
On Pro, download the zip from this page and follow its README. On any plan, run npx better-design to connect your coding agent, then ask it for the Code review screen.
Which design system should I pick?
Start with Precision Light, the default for this layout. The switcher lists the others that fit it.
Can it use my own brand?
Yes, on Pro. Your agent applies your private brand guidelines to every screen it builds.
Does it include a backend?
No. The template is the interface only, so you connect your own data and sign-in.
Built with Better Design.

FIFA World Cup 26 bracket
A live radial knockout bracket with animated paths, match details, and an interactive 3D trophy.

TodoGit
A Git-based task manager for people and their coding agents, built around fast keyboard workflows.

Coffee World
A liquid glass photo carousel: an endless curved grid of refracting glass slabs, rendered in a single WebGL2 shader.
Wen Hao3 h ago
The 2.25rem leaves room for the spinner. Could it read the spinner size so the two stay in step?