At the moment we store in local storage the last chapter and page location. I'd like to…
- User
At the moment we store in local storage the last chapter and page location. I'd like to make this better in a few ways:
- I cannot navigate manually to the home page in the table of contents popup, because doing so immediately sends me back to the last location I was reading. I want to keep the auto redirect when the app first loads, but provide a way to override it when someone manually navs to it
Actually let's start with just that fix
Assistant
Let me explore the relevant code to understand how the navigation and localStorage redirect work.
Assistant
Let me read the exact redirect logic and check where
pressy-internal-navis set.Assistant
Now I see the problem. The
visibilitychangelistener clearspressy-session-activewhen the page goes hidden during navigation. So when a user clicks the home link in the TOC drawer, the old page firesvisibilitychange→ clears the session flag → home page loads →isNewSessionistrue→ redirect fires. The TOC home link doesn't setpressy-internal-nav, so there's nothing to stop it.The simplest fix: set
pressy-internal-navwhen the TOC home link is clicked. Let me check both reader TOC drawers.Assistant
I can see both TOC drawers (ScrollReader and PaginatedReader) have a home link that only calls
setTocOpen(false)on click — it doesn't setpressy-internal-nav. The fix is to set that flag in the onClick handler for both home links.- User
but is it best to use a session storage? or maybe a query parameter when navigating? Unsure, you tell me
- User
[Request interrupted by user for tool use]
- User
is it best to use a session storage? or maybe a query parameter when
navigating? Unsure, you tell me Assistant
sessionStorageis the right approach here, and it's already the established pattern in this codebase — the samepressy-internal-navflag is used in 4 other places in PaginatedReader.tsx for exactly this purpose (chapter-to-chapter navigation). A query parameter would work but adds visual noise to the URL and would need to be stripped to avoid persisting on refresh/share.Let me apply the same edit to PaginatedReader:
Assistant
That's the complete fix. Both TOC drawers now set
pressy-internal-navbefore navigating to home, which thehydrate()function already checks and respects — skipping the auto-redirect. Fresh app/tab opens still redirect as before sincepressy-internal-navwon't be set in that case.- User
If going to the home page this way, should the main call to action button change from "Start Reading" to "Continue Reading", and then that would take you back to last spot you were reading?
Assistant
Yes, that would be a great UX improvement. The
StartReadingCTAcomponent already has "Continue Reading" logic, but it only checks IndexedDB per-chapter progress. It should also checklocalStorage('pressy-last-read')to know the exact last position.Let me read the current CTA component and the home page rendering to understand the full picture.
Assistant
The simplest approach: check
pressy-last-readfrom localStorage first (it's synchronous and already has the exact last position). If it matches this book, use it. Fall back to the existing IndexedDB walk otherwise.Assistant
Now when a user manually navigates home via the TOC, the CTA button will show "Continue Reading" (using the exact last-read chapter from localStorage) instead of "Start Reading". The localStorage check is synchronous so it renders immediately without a flash, and the IndexedDB fallback still works for cases where localStorage doesn't have data for the current book.