diff --git a/client/src/components/RecentSearches.css b/client/src/components/RecentSearches.css index 52e48b3..daf1ae8 100644 --- a/client/src/components/RecentSearches.css +++ b/client/src/components/RecentSearches.css @@ -77,11 +77,25 @@ font-size: 0.85rem; } .recent-searches__error { - padding: 0.75rem; - border: 1px solid var(--border-strong); - border-radius: 5px; - background: var(--surface); + display: flex; + flex-direction: column; + align-items: flex-start; + gap: 0.5rem; + padding: 0.5rem 0.65rem; color: var(--text); + font-size: 0.9rem; +} +.recent-searches__error p { + margin: 0; +} +.search-form .recent-searches .recent-searches__retry { + width: auto; + padding: 0.35rem 0.75rem; + border: 1px solid var(--border-strong); + border-radius: 4px; + color: var(--accent); + font-size: 0.85rem; + font-weight: 600; } @media (pointer: coarse) { .search-form .recent-searches button { diff --git a/client/src/components/RecentSearches.test.tsx b/client/src/components/RecentSearches.test.tsx index 33d984a..5ec8c92 100644 --- a/client/src/components/RecentSearches.test.tsx +++ b/client/src/components/RecentSearches.test.tsx @@ -79,4 +79,56 @@ describe('RecentSearches', () => { expect(onSelect).not.toHaveBeenCalled(); expect(onSubmit).not.toHaveBeenCalled(); }); + + it('only renders the error message and retry button inside the dropdown while open', () => { + const onRetry = vi.fn(); + const { rerender } = render( + , + ); + expect(screen.queryByText('Could not load recent searches.')).not.toBeInTheDocument(); + expect( + screen.queryByRole('button', { name: 'Retry recent searches' }), + ).not.toBeInTheDocument(); + + rerender( + , + ); + const region = screen.getByRole('region', { name: 'Recent searches' }); + expect(within(region).getByText('Could not load recent searches.')).toBeVisible(); + fireEvent.click( + within(region).getByRole('button', { name: 'Retry recent searches' }), + ); + expect(onRetry).toHaveBeenCalledOnce(); + + rerender( + , + ); + expect( + screen.queryByRole('region', { name: 'Recent searches' }), + ).not.toBeInTheDocument(); + expect( + screen.queryByRole('button', { name: 'Retry recent searches' }), + ).not.toBeInTheDocument(); + }); }); diff --git a/client/src/components/RecentSearches.tsx b/client/src/components/RecentSearches.tsx index dea8419..cb74ea7 100644 --- a/client/src/components/RecentSearches.tsx +++ b/client/src/components/RecentSearches.tsx @@ -41,82 +41,96 @@ export default function RecentSearches({ ?.scrollIntoView?.({ block: 'nearest' }); }, [open, activeIndex, listId]); + const showDropdown = open && (recent.length > 0 || Boolean(error)); + return (
- {open && recent.length > 0 && ( + {showDropdown && (

Recent searches

-
    - {recent.map(({ query }, index) => ( -
  • + {recent.length > 0 && ( + <> +
      + {recent.map(({ query }, index) => ( +
    • + +
    • + ))} +
    + + + )} + {error && ( +
    +

    {error}

    + {onRetry && ( -
  • - ))} -
- + )} +
+ )} )}

- {error ?? - (clearing - ? 'Clearing recent searches…' - : loading - ? 'Loading recent searches…' - : open && recent.length > 0 - ? `${recent.length} recent searches available. Use the Up and Down arrow keys to choose, then Enter to search.` - : message)} + {clearing + ? 'Clearing recent searches…' + : loading + ? 'Loading recent searches…' + : open && recent.length > 0 + ? `${recent.length} recent searches available. Use the Up and Down arrow keys to choose, then Enter to search.` + : message}

- {error && onRetry && ( - - )} ); } diff --git a/client/src/components/SearchForm.tsx b/client/src/components/SearchForm.tsx index bb58527..8646dcb 100644 --- a/client/src/components/SearchForm.tsx +++ b/client/src/components/SearchForm.tsx @@ -12,7 +12,7 @@ interface Props { clearing: boolean; error: string | null; message: string; - retry?: () => void; + retry?: () => Promise | void; clearHistory: () => Promise; }; } @@ -100,6 +100,18 @@ export default function SearchForm({ query, onSearch, history }: Props) { } } + async function retryHistory() { + const previousFocus = document.activeElement; + const succeeded = await history?.retry?.(); + if ( + succeeded !== false && + (document.activeElement === previousFocus || + document.activeElement === document.body) + ) { + input.current?.focus(); + } + } + return (
void retryHistory() : undefined} /> )}
diff --git a/client/src/hooks/useSearchHistory.ts b/client/src/hooks/useSearchHistory.ts index 3e3e07e..c2b15a0 100644 --- a/client/src/hooks/useSearchHistory.ts +++ b/client/src/hooks/useSearchHistory.ts @@ -75,8 +75,13 @@ export function useSearchHistory() { error: error ?? (loadError ? 'Could not load recent searches.' : null), message, retry: loadError - ? () => { - void refetch().catch(() => {}); + ? async () => { + try { + const result = await refetch(); + return !result.error; + } catch { + return false; + } } : undefined, recordSearch, diff --git a/client/src/searchHistory.test.tsx b/client/src/searchHistory.test.tsx index bba8296..b26961d 100644 --- a/client/src/searchHistory.test.tsx +++ b/client/src/searchHistory.test.tsx @@ -254,8 +254,33 @@ describe('Discover search history', () => { await waitForClear(); }); + it('hides load error and retry UI while the dropdown is closed, then shows them when opened', async () => { + const user = userEvent.setup(); + start([albums(), history(new Error('Offline'))], false); + await waitForHistory(); + expect(screen.queryByText('Could not load recent searches.')).not.toBeInTheDocument(); + expect( + screen.queryByRole('button', { name: 'Retry recent searches' }), + ).not.toBeInTheDocument(); + + await user.click(input()); + const region = await screen.findByRole('region', { name: 'Recent searches' }); + expect(region).toHaveTextContent('Could not load recent searches.'); + expect( + screen.getByRole('button', { name: 'Retry recent searches' }), + ).toBeInTheDocument(); + + await user.keyboard('{Escape}'); + expect( + screen.queryByRole('region', { name: 'Recent searches' }), + ).not.toBeInTheDocument(); + expect( + screen.queryByRole('button', { name: 'Retry recent searches' }), + ).not.toBeInTheDocument(); + }); + it.each(['initial load', 'post-save refresh'])( - 'retries a failed %s without resaving', + 'retries a failed %s without resaving and restores focus to the search input', async (stage) => { const user = userEvent.setup(); const saved = record('Blue'); @@ -265,18 +290,26 @@ describe('Discover search history', () => { if (stage === 'post-save refresh') { await waitForHistory(); submit('Blue'); + expect( + screen.queryByRole('button', { name: 'Retry recent searches' }), + ).not.toBeInTheDocument(); + await user.click(input()); } - await screen.findByText('Could not load recent searches.'); + const region = await screen.findByRole('region', { name: 'Recent searches' }); + expect(region).toHaveTextContent('Could not load recent searches.'); expect(input()).toBeEnabled(); - await user.click(screen.getByRole('button', { name: 'Retry recent searches' })); + const retry = screen.getByRole('button', { name: 'Retry recent searches' }); + retry.focus(); + await user.keyboard('{Enter}'); await waitForHistory(); - await user.click(input()); expect(await screen.findByRole('option', { name: 'Blue' })).toBeVisible(); + expect(input()).toHaveFocus(); expect(saved.result).toHaveBeenCalledTimes(stage === 'initial load' ? 0 : 1); }, ); - it('reports save errors without losing the active search', async () => { + it('reports save errors inside the dropdown without losing the active search', async () => { + const user = userEvent.setup(); start([ albums(), history([]), @@ -285,7 +318,11 @@ describe('Discover search history', () => { ]); await waitForHistory(); submit('Blue'); - await screen.findByText('Could not save recent search. Submit it again to retry.'); + await user.click(input()); + const region = await screen.findByRole('region', { name: 'Recent searches' }); + expect(region).toHaveTextContent( + 'Could not save recent search. Submit it again to retry.', + ); expect(window.location.search).toBe('?q=Blue'); expect(input()).toHaveValue('Blue'); }); diff --git a/docs/AI-USAGE.md b/docs/AI-USAGE.md index 745f626..30a0a84 100644 --- a/docs/AI-USAGE.md +++ b/docs/AI-USAGE.md @@ -104,6 +104,7 @@ the part that matters most. | 2026-11-13 | robertky | Codex (ChatGPT) | Assisted me with #26: polished the README, added screenshots and project-document links, and verified the local setup from a clean clone. I reviewed the changes and updated the implementation notes to reflect merged browsing and country-filter features. | | 2026-11-17 | erikhfj | Antigravity | #91, E2E search helper fix: updated `e2e/tests/search.spec.ts` to match the `Search` and `Filters` buttons with `exact: true` so `Clear recent searches` does not trigger a strict-mode violation, and cleared `E2E_USER_ID`'s recorded search history during cleanup. Verified locally with two consecutive full `pnpm test:e2e` runs against a throwaway seeded PostgreSQL stack. | | 2026-11-20 | erikhfj | Antigravity | #100, review author privacy: removed `User.id` from `schema.graphql` and the `AlbumDetail` query, replaced `Listener ` with deterministic SHA-256 music pseudonyms in `server/src/userIdentity.ts` (including read-time sanitization of legacy labels in `Review.user`), added `User` cache merge policy, and updated schema/unit/client tests and `docs/architecture.md`. Verified with `pnpm codegen`, `pnpm format:check`, `pnpm lint`, `pnpm typecheck`, `pnpm test`, and `pnpm build`. | +| 2026-11-20 | erikhfj | Antigravity | #103, search history error visibility and focus: moved the search history error message and Retry button inside the open `RecentSearches` dropdown so closed-state errors cannot overlap page content, returned retry success from `useSearchHistory`, restored focus to the search input after a successful retry in `SearchForm`, and added unit/integration tests. Verified with `pnpm format:check && pnpm lint && pnpm typecheck && pnpm test && pnpm build`. | ## Notes