Skip to content

Conversation

manerlan
Copy link
Member

Closes #72. Continuation of #65 and #71.

What

Users can put wines on their lists from the wine cards and the wine page. The lists are stored on the user, so they follow the user between browsers, and the buttons change at once without a reload. Also fixes the frontend review comments on #65, and answers the questions on #71.

  • useWineList(wineId, list): returns { isSaved, toggle, error }. Reads myLists from the Apollo cache (useFragment), so every button for the same wine agrees. The change shows at once (optimisticResponse, with the same rules as the API in lib/wineLists.ts), and goes back with a Norwegian message if saving fails.
  • myLists in the wine queries (search, landing page, wine page, lists): no extra request per page. The backend batches it with a DataLoader.
  • Wine page: «Favoritt», «Vil prøve» and «Har prøvd» as toggle buttons (aria-pressed) with visible text, in a named group.
  • Wine cards: heart («Favoritt») and bookmark («Vil prøve»), icon buttons named with the wine («Favoritt Origem Merlot»). «Har prøvd» is on the wine page only, to keep the cards calm.
  • Visitors are sent to /konto and back to the same page after logging in.
  • «Mine anmeldelser»: «Vil prøve» from the API (me.wines), 24 per page with «Last inn flere», behind RequireAuth. A wine taken off the list disappears at once; the live region says so and focus moves to the list heading.
  • Cache: User.wines keeps one list per name, with pages merged. updateListPages takes a wine out of the lists it left at once, and drops a list it joined, so it is fetched again with the new wine first.
  • One-time import: a «Vil prøve» list stored in the browser before login (kk:wishlist) moves to the user, oldest first. Wines that no longer exist are skipped. The old list is removed only when every wine has been handled, so a failed connection tries again at the next login.
  • Removed: the localStorage wishlist (useWishlist, useWishlistWines, wishlistQuery).

Review comments from #65 (frontend)

  • Expired session: a link in lib/apollo.ts fetches me again when any request answers UNAUTHENTICATED, so the header, the review form and the list buttons all show that the user is logged out.
  • AuthProvider: the writeQuery before resetStore() was useless, as the review said, since resetStore() empties the cache right after. It is gone. resetStore() fetches me again with the new cookie, so the server decides who is logged in. Not clearStore() followed by writeQuery: in Apollo 4, clearStore() also discards the cache watches (discardWatches: true), so the header would not see the new user.
  • AuthForm: setWorking(false) is in finally. If onSubmit throws, the form shows «Noe uventet gikk galt» instead of staying at «Logger inn …».

Questions on #71

  • A tried wine back on «Vil prøve»: deliberate. The user may want to taste it again, for example another vintage. Only «Har prøvd» moves a wine between the two lists. Now a row in the rules table in docs/api.md, and tested in lists-api.db.test.ts.
  • The demo user on the VM: the README now says plainly that anyone with the link can change it, and that npm run db:seed:demo in backend/ puts it back as it was.
  • Migrating the test database: «Database tests» in docs/api.md now has the PowerShell version too, since DATABASE_URL=... npm run db:migrate only works in bash and Git Bash.

Commits

  1. fix(frontend): refetch the user when the session ends, and review fixes from Tie reviews to user accounts #65
  2. feat(frontend): useWineList against the API, with myLists in the wine queries
  3. feat(frontend): favourite, «Vil prøve» and «Har prøvd» buttons on the wine page
  4. feat(frontend): list buttons on the wine cards, and «Vil prøve» from the API on «Mine anmeldelser»
  5. feat(frontend): move a «Vil prøve» list from before login to the user, once
  6. test(e2e): wine lists, login on the way, and the move of an old list
  7. docs: wine lists in the interface, and manual tests for them
  8. docs: answers to the review of Wine lists in the backend (favourites, want to try, tried) #71

Tests

  • lib/wineLists.test.ts: the list rules, the same as the API's.
  • features/lists/useWineList.test.tsx: reads the cache, changes at once, «Har prøvd» takes the wine off «Vil prøve», goes back with a message on failure, updates the list pages, and sends a visitor to log in.
  • features/lists/components/WineListButtons.test.tsx and components/ui/WineCard.test.tsx: names, pressed state, keyboard (Tab, Space, Enter), several cards for the same wine, visitors, and axe.
  • features/my/MyPage.test.tsx: the list from the API, removal with focus and live region, «Last inn flere» with focus, errors, and axe.
  • features/lists/api/listCache.test.ts and lib/apollo.test.ts: the cache rules for the lists, the session link, and User.wines.
  • features/lists/legacyWishlist.test.ts and useLegacyWishlistImport.test.tsx: the import order, skipped wines, a failed connection, once only, and nothing for visitors.
  • features/auth/components/AuthForm.test.tsx: the form recovers when sending throws.
  • e2e/lists.spec.ts (desktop and mobile), against a fake API that remembers the lists: keyboard on a card bookmark, the list after a new page load, removal on «Mine anmeldelser», «Har prøvd» on the wine page, a visitor logging in on the way, the move of an old list, and axe on «Mine anmeldelser».
  • backend/src/lists/lists-api.db.test.ts: a tried wine can go back on «Vil prøve».

Test helpers: meMock, TEST_USER and AuthReady in src/test/. renderWithRouter now includes Apollo and AuthProvider, like the app, since the wine cards need to know who is logged in.

cd frontend
npm run e2e
cd ..
npm run check

Also tested by hand, following docs/manual-testing.md sections 2, 5 and 6.

Updated test counts for frontend and e2e in README.md

How to review

  • Run the backend from Wine lists in the backend (favourites, want to try, tried) #71 with npm run db:seed:demo, and log in as demo / kork-og-krone.
  • Try the heart and the bookmark on the landing page and in the search, then the three buttons on the wine page, then «Mine anmeldelser». Open the same user in a private window: the lists are the same.
  • Log out and press a heart: you go to /konto, and back after logging in.
  • To try the import: logged out, run localStorage.setItem('kk:wishlist', JSON.stringify(['<id>', '<id>'])) in the console, then log in and open «Mine anmeldelser».

After merge (VM)

No new migrations: the backend from #71 is enough. Build the frontend again:

cd frontend
npm ci
npm run buildvm

If the demo user has been changed, run npm run db:seed:demo in backend/.

Not in this PR

  • The profile page («Min side») with the top 4, all three lists and the user's reviews, and choosing the top 4: coming in Profile page #73 .

@manerlan manerlan requested a review from a team as a code owner November 19, 2026 14:59
@manerlan manerlan linked an issue Nov 19, 2026 that may be closed by this pull request
5 tasks
Copy link
Member

@siverne siverne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally as demo: npm run check passes. Hearts and bookmarks on the cards change at once and match the buttons on the wine page, «Har prøvd» takes the wine off «Vil prøve», the list is the same in a private window, and a visitor pressing a heart goes to /konto and comes back to the same page after logging in. I did not try the import of an old list.

Nicely done, and thanks for answering the questions from #65 and #71. Reading the button state from the same cache object with useFragment is a clean way to keep every heart in agreement, and only forgetting the old list once everything is handled is the right call.

One thing to get right on the VM: the description says the frontend is all that is needed, since «the backend from #71 is enough». But the VM does not run #71 yet: its API answers Cannot query field "myLists" right now. Since myLists is in every wine query, publishing the frontend first would break the landing page and the search. The backend has to be updated and migrated first, as you wrote in #81.

Small notes, none blocking:

pending is per button, so two different buttons for the same list (a card heart and «Favoritt» on the wine page) can still send at the same time. Unlikely in practice.
The list rules now live in both lib/wineLists.ts and the backend. They are tested and commented, but have to change together.
The old browser list is imported into whoever logs in, so on a shared computer it could be someone else’s. It only covers data from before this version, so not worth much more than a note.

@siverne siverne merged commit f3a974d into main Nov 19, 2026
@manerlan manerlan deleted the 72-interface-wine-lists branch November 19, 2026 15:29
@manerlan
Copy link
Member Author

Tested locally as demo: npm run check passes. Hearts and bookmarks on the cards change at once and match the buttons on the wine page, «Har prøvd» takes the wine off «Vil prøve», the list is the same in a private window, and a visitor pressing a heart goes to /konto and comes back to the same page after logging in. I did not try the import of an old list.

Nicely done, and thanks for answering the questions from #65 and #71. Reading the button state from the same cache object with useFragment is a clean way to keep every heart in agreement, and only forgetting the old list once everything is handled is the right call.

One thing to get right on the VM: the description says the frontend is all that is needed, since «the backend from #71 is enough». But the VM does not run #71 yet: its API answers Cannot query field "myLists" right now. Since myLists is in every wine query, publishing the frontend first would break the landing page and the search. The backend has to be updated and migrated first, as you wrote in #81.

Small notes, none blocking:

pending is per button, so two different buttons for the same list (a card heart and «Favoritt» on the wine page) can still send at the same time. Unlikely in practice. The list rules now live in both lib/wineLists.ts and the backend. They are tested and commented, but have to change together. The old browser list is imported into whoever logs in, so on a shared computer it could be someone else’s. It only covers data from before this version, so not worth much more than a note.

Good catch regarding the vm, have deploy again in the right order, currently working as it should. Will look into the other notes while working on #73 .

Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wine lists in the interface
2 participants