v4: settings are stored on the server, starting with the style, the color scheme and the digest switches — every setting lived in the browser's localStorage, so it didn't follow an account to another browser and the server couldn't read it, which the digests need (whether to send each, and in which style). user_settings (migration 0019) holds one row per user who changed anything, the defaults otherwise, and GET/PATCH /api/users/me/settings read and change it (settings-service, model/settings, validators/settings, shared/settings). AuthProvider reads the settings into the session alongside the user, on mount and on focus, so a change made elsewhere arrives; useSettings changes them at once and puts them back if the server refuses. ThemeProvider now sits inside AuthProvider: a signed-in user's choice comes from their settings and is mirrored to localStorage for index.html's first-paint script, a visitor's stays in the browser, and an account with no choice yet takes the one this browser had, once. Until anyone picks a style, the instance's GERBEUR_DEFAULT_STYLE applies, written into index.html's default-style tag along with email-enabled (src/config/instance.ts), and a browser no longer stores the default as if it had been chosen, so changing the instance's style reaches everyone who never picked one. The settings tab gets an Email section with the weekly digest and monthly recap switches, disabled with a note when the server has no SMTP. The style and scheme names moved to shared/theme.ts in the previous commit; the default feed tab and sounds stay in the browser for now. 223 backend tests (new: settings defaults, patches, isolation, refusals and cascade; index.html's new tags) and 658 frontend tests (new: useSettings, the account's theme winning and a browser's carried over, settings read into the session, the digest switches) pass, and tsc, eslint, doc:lint, deno check, deno lint and deno fmt are clean.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
43
shared/settings.ts
Normal file
43
shared/settings.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* A user's settings follow their account from browser to browser, and the
|
||||
* server reads some of them itself (a digest is drawn in its reader's style).
|
||||
* This module types them for `GET` and `PATCH /api/users/me/settings`; the
|
||||
* client keeps them with its session.
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
|
||||
import type { ColorScheme, StyleName } from "./theme.ts";
|
||||
|
||||
/**
|
||||
* Returned by `GET /api/users/me/settings`, and by a `PATCH` once applied.
|
||||
* The client's `useSettings` reads it from the session.
|
||||
*/
|
||||
export interface UserSettings {
|
||||
/**
|
||||
* Null until the user picks one, so the instance's default style
|
||||
* (`GERBEUR_DEFAULT_STYLE`) applies, and so a browser's earlier choice can be
|
||||
* carried over on first sign-in.
|
||||
*/
|
||||
style: StyleName | null;
|
||||
/** Null until the user picks one, which reads as "auto". */
|
||||
colorScheme: ColorScheme | null;
|
||||
/** Whether the weekly digest is sent. */
|
||||
digestWeekly: boolean;
|
||||
/** Whether the monthly recap is sent. */
|
||||
digestMonthly: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sent to `PATCH /api/users/me/settings` with the settings to change; the
|
||||
* others keep their value.
|
||||
*/
|
||||
export type UpdateSettingsRequest = Partial<UserSettings>;
|
||||
|
||||
/** The settings of a user who never changed any. Digests are on by default. */
|
||||
export const DEFAULT_SETTINGS: UserSettings = {
|
||||
style: null,
|
||||
colorScheme: null,
|
||||
digestWeekly: true,
|
||||
digestMonthly: true,
|
||||
};
|
||||
Reference in New Issue
Block a user