44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
/**
|
|
* 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,
|
|
};
|