Off / the footer was a plain link home. It is now the same Menu.Root everywhere; off / its dialog entries link to /?account=<dialog>, which Home opens once its account is ready and drops from the URL. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N4f2nya58RoRu4yEmJgRGE
34 lines
1.5 KiB
TypeScript
34 lines
1.5 KiB
TypeScript
/**
|
|
* The account menu on every page (TASK-self-edit-avatar-menu-20260928 S2).
|
|
*
|
|
* The account dialogs live on `/`. Off `/`, the same menu's dialog entries
|
|
* are links to `/?account=<dialog>`; Home opens that dialog once its account
|
|
* is ready and drops the parameter, so a reload or Back never opens it again.
|
|
* Theme needs no dialog and applies where the reader is.
|
|
*
|
|
* No dependencies: this ships with the shared sidebar.
|
|
*/
|
|
|
|
export const ACCOUNT_DIALOG_QUERY_KEY = "account";
|
|
export const ACCOUNT_DIALOG_INTENTS = ["profile", "general", "billing", "logout"] as const;
|
|
export type AccountDialogIntent = (typeof ACCOUNT_DIALOG_INTENTS)[number];
|
|
|
|
export function accountDialogHref(dialog: AccountDialogIntent): string {
|
|
return `/?${ACCOUNT_DIALOG_QUERY_KEY}=${dialog}`;
|
|
}
|
|
|
|
/** The dialog the URL asks for; null when absent or not one of the four. */
|
|
export function parseAccountDialogIntent(search: string): AccountDialogIntent | null {
|
|
const params = new URLSearchParams(search.startsWith("?") ? search.slice(1) : search);
|
|
const value = params.get(ACCOUNT_DIALOG_QUERY_KEY);
|
|
return (ACCOUNT_DIALOG_INTENTS as readonly string[]).includes(value ?? "") ? value as AccountDialogIntent : null;
|
|
}
|
|
|
|
/** The same query without the account intent (a malformed value is dropped too). */
|
|
export function searchWithoutAccountDialogIntent(search: string): string {
|
|
const params = new URLSearchParams(search.startsWith("?") ? search.slice(1) : search);
|
|
params.delete(ACCOUNT_DIALOG_QUERY_KEY);
|
|
const query = params.toString();
|
|
return query ? `?${query}` : "";
|
|
}
|