/** * 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=`; 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}` : ""; }