Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions client/src/components/RecentSearches.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
52 changes: 52 additions & 0 deletions client/src/components/RecentSearches.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<RecentSearches
entries={[]}
open={false}
error="Could not load recent searches."
onSelect={vi.fn()}
onClear={vi.fn()}
onRetry={onRetry}
/>,
);
expect(screen.queryByText('Could not load recent searches.')).not.toBeInTheDocument();
expect(
screen.queryByRole('button', { name: 'Retry recent searches' }),
).not.toBeInTheDocument();

rerender(
<RecentSearches
entries={[]}
open={true}
error="Could not load recent searches."
onSelect={vi.fn()}
onClear={vi.fn()}
onRetry={onRetry}
/>,
);
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(
<RecentSearches
entries={[]}
open={false}
error="Could not load recent searches."
onSelect={vi.fn()}
onClear={vi.fn()}
onRetry={onRetry}
/>,
);
expect(
screen.queryByRole('region', { name: 'Recent searches' }),
).not.toBeInTheDocument();
expect(
screen.queryByRole('button', { name: 'Retry recent searches' }),
).not.toBeInTheDocument();
});
});
130 changes: 72 additions & 58 deletions client/src/components/RecentSearches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,82 +41,96 @@ export default function RecentSearches({
?.scrollIntoView?.({ block: 'nearest' });
}, [open, activeIndex, listId]);

const showDropdown = open && (recent.length > 0 || Boolean(error));

return (
<div className="recent-searches__popover">
{open && recent.length > 0 && (
{showDropdown && (
<section className="recent-searches" aria-labelledby={headingId}>
<div className="recent-searches__header">
<h2 id={headingId}>Recent searches</h2>
</div>
<ul
id={listId}
role="listbox"
aria-labelledby={headingId}
className="recent-searches__list"
>
{recent.map(({ query }, index) => (
<li key={query} role="presentation">
{recent.length > 0 && (
<>
<ul
id={listId}
role="listbox"
aria-labelledby={headingId}
className="recent-searches__list"
>
{recent.map(({ query }, index) => (
<li key={query} role="presentation">
<button
type="button"
role="option"
id={`${listId}-option-${index}`}
tabIndex={-1}
aria-selected={index === activeIndex}
onMouseDown={(event) => event.preventDefault()}
onClick={() => onSelect(query)}
>
<svg
aria-hidden="true"
width="18"
height="18"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="1.7"
strokeLinecap="round"
strokeLinejoin="round"
>
<path d="M3 11a9 9 0 1 1 2.6 7.4M3 4v7h7" />
<path d="M12 7v5l3 2" />
</svg>
<span>{query}</span>
</button>
</li>
))}
</ul>
<button
type="button"
className="recent-searches__clear"
aria-disabled={clearing}
aria-busy={clearing}
onClick={() => {
if (!clearing) onClear();
}}
>
Clear recent searches
</button>
</>
)}
{error && (
<div className="recent-searches__error">
<p role="alert">{error}</p>
{onRetry && (
<button
type="button"
role="option"
id={`${listId}-option-${index}`}
tabIndex={-1}
aria-selected={index === activeIndex}
onMouseDown={(event) => event.preventDefault()}
onClick={() => onSelect(query)}
className="recent-searches__retry"
onClick={onRetry}
>
<svg
aria-hidden="true"
width="18"
height="18"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="1.7"
strokeLinecap="round"
strokeLinejoin="round"
>
<path d="M3 11a9 9 0 1 1 2.6 7.4M3 4v7h7" />
<path d="M12 7v5l3 2" />
</svg>
<span>{query}</span>
Retry recent searches
</button>
</li>
))}
</ul>
<button
type="button"
className="recent-searches__clear"
aria-disabled={clearing}
aria-busy={clearing}
onClick={() => {
if (!clearing) onClear();
}}
>
Clear recent searches
</button>
)}
</div>
)}
</section>
)}
<p
className={error ? 'recent-searches__error' : 'visually-hidden'}
className="visually-hidden"
role="status"
aria-live="polite"
aria-label="Search history status"
>
{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}
</p>
{error && onRetry && (
<button type="button" onClick={onRetry}>
Retry recent searches
</button>
)}
</div>
);
}
16 changes: 14 additions & 2 deletions client/src/components/SearchForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface Props {
clearing: boolean;
error: string | null;
message: string;
retry?: () => void;
retry?: () => Promise<boolean> | void;
clearHistory: () => Promise<boolean>;
};
}
Expand Down Expand Up @@ -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 (
<div
className="search-area"
Expand Down Expand Up @@ -182,7 +194,7 @@ export default function SearchForm({ query, onSearch, history }: Props) {
clearing={history.clearing}
error={history.error}
message={history.message}
onRetry={history.retry}
onRetry={history.retry ? () => void retryHistory() : undefined}
/>
)}
</div>
Expand Down
9 changes: 7 additions & 2 deletions client/src/hooks/useSearchHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
49 changes: 43 additions & 6 deletions client/src/searchHistory.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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([]),
Expand All @@ -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');
});
Expand Down
1 change: 1 addition & 0 deletions docs/AI-USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <uuid-prefix>` 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

Expand Down