Archive several saved articles at once
React · React · intermediate · modification
Readers asked for a way to clear out their reading list without opening each article, so the table now has a checkbox per row and an `Archive selected (N)` button. `src/api/readingList.js` adds `archiveArticles(ids)` for the new archive endpoint. `src/reading/ArticleTable.jsx` keeps one checked flag per article, renders the checkbox column next to the existing `Hide read` filtering and computes the ids the button sends. `src/reading/ReadingListPage.jsx` runs the archive request, disables the button while it is in flight, reloads the list on success and shows an error message on failure. `src/reading/ArticleTable.test.jsx` (new) adds component tests for the selection and the archive button.
Reading-list SPA on React 18.3 (Vite, function components, plain `fetch`). Tests run with `npm test`: Vitest 2 with @testing-library/react 16 in jsdom. Existing and unchanged: the router renders `ReadingListPage` at `/reading-list` for a signed-in reader; requests are same-origin and carry the session cookie, and the server's CSRF check accepts same-origin JSON requests like this one. `GET /api/reading-list` returns the reader's saved articles that are not archived, newest first, at most 200, as `[{ id, title, url, siteName, savedLabel, read }]`: `id` a unique non-empty string, `title` and `siteName` non-empty strings, `url` an absolute http(s) URL, `savedLabel` the save date already formatted by the API (for example `Oct 30`), `read` a boolean. `POST /api/reading-list/archive` (shipped in the backend already) takes `{ "ids": [...] }` with 1 to 200 ids, archives them in one transaction and answers 204; on any error it archives nothing and answers 4xx or 5xx. The articles do not change while the page shows them: the list has no live updates, and `ArticleTable` is mounted afresh for every load because the page renders the loading state in its place. The table's existing classes are styled in `src/reading/reading.css` (unchanged) with theme tokens.
Requirements
- Each row of the reading list table gets a checkbox. Checking a row selects that article and unchecking it deselects it; nothing is selected when the list first shows.
- An `Archive selected (N)` button above the table archives the selected articles that the table currently shows, through `archiveArticles(ids)` (new), which sends `POST /api/reading-list/archive` with `{ "ids": [...] }`. N is the number of articles the button will archive, and the button is disabled when N is 0 or while an archive request is in flight.
- The existing `Hide read` toggle keeps working while articles are checked. An article it hides is not archived, even if it was checked before it was hidden, and it is still checked when the toggle is turned off again.
- After a successful archive the list reloads as it does on first open (loading state, then the fresh list with nothing selected). If the archive request fails, the page shows `Could not archive the selected articles. Try again.`, nothing is reloaded and the selection is kept.
- Unchanged: the title links, the Site and Saved columns, the read-row style, the loading and error states with Retry, and the empty messages (`No unread articles.` with `Hide read` on, `Nothing saved yet.` otherwise).
Files touched
- src/api/readingList.js
- src/reading/ArticleTable.jsx
- src/reading/ReadingListPage.jsx
- src/reading/ArticleTable.test.jsx