Files
gerbeur/src/components/profile/ProfileSettingsTab.tsx
khannurien f20ca83f0c v4: every email is rendered by its template in api/mail/ on one layout that takes the instance's style, and sent one way — the welcome email was built and sent inside the register route and the reset link in its service, each writing Markdown, running marked, and calling a nodemailer wrapper whose cc, bcc, replyTo and send result nothing used. Now api/mail/ holds one template per email (welcome.ts, password-reset.ts) on layout.ts's EmailKit, which draws each block with inline styles in a style from styles.ts: the six site styles' palettes, copied from src/themes/, and what makes each recognisable in a mail client (Brutalist's hard border and shadow, GeoCities' ridge and rainbow rules, Times' underlined ink links, Kanagawa's colored quotes, dates and wordmark, Melange's spice bar). On the "auto" scheme the light palette is inlined and the dark one swapped in by a prefers-color-scheme block; a chosen scheme sends only its own. User-written text is escaped where it lands. strings.ts holds every email's words in English and French. GERBEUR_EMAIL_LOCALE picks the language and GERBEUR_DEFAULT_STYLE the instance's style, which the welcome and reset emails are drawn in; GERBEUR_WELCOME_EMAIL_BODY still replaces the welcome's Markdown, whose blocks now take the style too. email-service sends a rendered email with its recipient and headers, refuses to load when GERBEUR_SMTPS_URL is set without GERBEUR_FROM_EMAIL (sends used to fail one by one), and takes a test transport, through which the tests now read what was sent. The welcome send moves to user-service's sendWelcomeEmail. The style and scheme names move to shared/theme.ts, which the server now needs. README, mod.ts and .env.example describe mail/ and the new variables, and drop the "notifications, invites" email that never existed. 221 backend tests pass (new: the layout's schemes, styles and escaping, both templates, the welcome on sign-up, a reset link from the email that works), and deno check, deno lint, doc:lint, deno fmt, tsc and eslint are clean.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 21:11:54 +00:00

126 lines
4.5 KiB
TypeScript

/**
* Renders the "settings" tab of the signed-in user's own profile, where they
* change their password and this browser's preferences.
*
* @module
*/
import { useState } from "react";
import { Trans } from "@lingui/react/macro";
import type { ColorScheme, StyleName } from "../../../shared/theme.ts";
import type { FeedTab } from "../../config/feedTabs.ts";
import { useTheme } from "../../hooks/theme/useTheme.ts";
import { useDefaultFeedTab } from "../../hooks/feed/useDefaultFeedTab.ts";
import { useSoundsEnabled } from "../../hooks/shared/useSoundsEnabled.ts";
import { previewChime } from "../../utils/shared/sound.ts";
import { Segmented, type SegmentedOption } from "../shared/Segmented.tsx";
import { ChangePasswordModal } from "./ChangePasswordModal.tsx";
import { ProfileSection } from "./ProfileSection.tsx";
import { SettingRow } from "./SettingRow.tsx";
// The styles' names are their own, in every language.
const STYLE_OPTIONS: SegmentedOption<StyleName>[] = [
{ value: "smooth", label: "Smooth" },
{ value: "brutalist", label: "Brutalist" },
{ value: "geocities", label: "GeoCities" },
{ value: "nyt", label: "Times" },
{ value: "kanagawa", label: "Kanagawa" },
{ value: "melange", label: "Melange" },
];
const COLOR_SCHEME_OPTIONS: SegmentedOption<ColorScheme>[] = [
{ value: "auto", label: <Trans>Auto</Trans> },
{ value: "light", label: <Trans>Light</Trans> },
{ value: "dark", label: <Trans>Dark</Trans> },
];
const FEED_TAB_OPTIONS: SegmentedOption<FeedTab>[] = [
{ value: "hot", label: <Trans>Hot</Trans> },
{ value: "new", label: <Trans>New</Trans> },
{ value: "journal", label: <Trans>Journal</Trans> },
{ value: "followed", label: <Trans>Followed</Trans> },
];
const ON_OFF_OPTIONS: SegmentedOption<boolean>[] = [
{ value: true, label: <Trans>On</Trans> },
{ value: false, label: <Trans>Off</Trans> },
];
/**
* Renders the password change, which opens {@link ChangePasswordModal}, and
* the style, color scheme, default feed tab and sounds, each stored for this
* browser as soon as it is clicked. `UserPublicProfile` renders it on one's
* own profile only.
*/
export function ProfileSettingsTab(): React.JSX.Element {
const { style, colorScheme, setStyle, setColorScheme } = useTheme();
const [defaultFeedTab, setDefaultFeedTab] = useDefaultFeedTab();
const [soundsEnabled, setSoundsEnabled] = useSoundsEnabled();
const [changePasswordOpen, setChangePasswordOpen] = useState(false);
return (
<>
<ProfileSection title={<Trans>Account</Trans>}>
<div className="profile-appearance-grid">
<SettingRow label={<Trans>Password</Trans>}>
<button
type="button"
className="btn btn--ghost"
onClick={() => setChangePasswordOpen(true)}
>
<Trans>Change password…</Trans>
</button>
</SettingRow>
</div>
</ProfileSection>
<ProfileSection title={<Trans>Appearance</Trans>}>
<div className="profile-appearance-grid">
<SettingRow label={<Trans>Style</Trans>}>
<Segmented
options={STYLE_OPTIONS}
value={style}
onChange={setStyle}
/>
</SettingRow>
<SettingRow label={<Trans>Color scheme</Trans>}>
<Segmented
options={COLOR_SCHEME_OPTIONS}
value={colorScheme}
onChange={setColorScheme}
/>
</SettingRow>
</div>
</ProfileSection>
<ProfileSection title={<Trans>Feeds</Trans>}>
<div className="profile-appearance-grid">
<SettingRow label={<Trans>Default tab</Trans>}>
<Segmented
options={FEED_TAB_OPTIONS}
value={defaultFeedTab}
onChange={setDefaultFeedTab}
/>
</SettingRow>
</div>
</ProfileSection>
<ProfileSection title={<Trans>Notifications</Trans>}>
<div className="profile-appearance-grid">
<SettingRow label={<Trans>Sounds</Trans>}>
<Segmented
options={ON_OFF_OPTIONS}
value={soundsEnabled}
onChange={(on) => {
setSoundsEnabled(on);
// Let the user hear what they just turned on.
if (on) previewChime("notify");
}}
/>
</SettingRow>
</div>
</ProfileSection>
{changePasswordOpen && (
<ChangePasswordModal onClose={() => setChangePasswordOpen(false)} />
)}
</>
);
}