The last selection still living in a global. `?folder=sent` is now the state, the folder pills are links, and the open email carries it — a bare `/email/:id` would have dropped the query string and snapped the list back to inbox, so the row links and the arrow-key navigate pass it through. The auto-switch to "all" when the inbox is empty writes with `replace`: it is the app correcting its own default, not a place you chose to be. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
14 lines
960 B
TypeScript
14 lines
960 B
TypeScript
import { useParams } from 'react-router';
|
|
|
|
// Which email is open is `/email/:emailId`. The route pair already existed, but the URL was a mirror
|
|
// rather than the state: the selection lived in an `EMAIL_SELECTED` global and two effects copied it
|
|
// back and forth with the route. That round-trip is what kept a row a `<button>` — nothing to link to,
|
|
// no cmd-click, no middle-click — and it meant Back raced the effect that had just written the URL
|
|
// with `replace`. The param is the state now; there is nothing to keep in sync.
|
|
|
|
/** `search` carries the folder you are reading in (`?folder=sent`), which a bare pathname would drop. */
|
|
export const emailPath = (id: string, search = '') => `/email/${encodeURIComponent(id)}${search}`;
|
|
|
|
/** The open email, or null on the bare `/email` route — which is a real state, not one to redirect away. */
|
|
export const useSelectedEmailId = (): string | null => useParams<{ emailId?: string }>().emailId ?? null;
|