diff --git a/app/(app)/settings/page.tsx b/app/(app)/settings/page.tsx index 63b6e5fe..8b8f4cda 100644 --- a/app/(app)/settings/page.tsx +++ b/app/(app)/settings/page.tsx @@ -31,6 +31,7 @@ import { ChangePasswordModal } from "@/components/auth/change-password-modal"; import { ReadingSettings } from "@/components/reading-settings"; import { PushToggle } from "@/components/push/push-toggle"; import { ReminderToggle } from "@/components/sadhna/reminder-toggle"; +import { LikeEmailToggle } from "@/components/notifications/like-email-toggle"; const BFF_BASE = process.env.NEXT_PUBLIC_BFF_URL || "http://localhost:8080"; @@ -64,6 +65,7 @@ export default function SettingsPage() { > +
diff --git a/components/notifications/like-email-toggle.tsx b/components/notifications/like-email-toggle.tsx new file mode 100644 index 00000000..0ac198c1 --- /dev/null +++ b/components/notifications/like-email-toggle.tsx @@ -0,0 +1,83 @@ +"use client"; + +/** + * LikeEmailToggle — settings control for aggregated "someone liked your post" + * emails. Reads the current preference and lets the user opt out (push + + * in-app like notifications are unaffected). Matches the other settings rows. + */ + +import { useEffect, useState } from "react"; +import { toast } from "sonner"; +import { notifications } from "@/lib/social"; + +export function LikeEmailToggle() { + const [enabled, setEnabled] = useState(null); + const [busy, setBusy] = useState(false); + + useEffect(() => { + let cancelled = false; + notifications + .emailPrefs() + .then((r) => { + if (!cancelled) setEnabled(r.like_emails); + }) + .catch(() => { + if (!cancelled) setEnabled(true); // default-on; toggle still works + }); + return () => { + cancelled = true; + }; + }, []); + + async function toggle() { + if (enabled === null) return; + const next = !enabled; + setBusy(true); + try { + await notifications.setEmailPrefs(next); + setEnabled(next); + toast.success(next ? "Like emails turned on" : "Like emails turned off"); + } catch { + toast.error("Could not update preference"); + } finally { + setBusy(false); + } + } + + return ( +
    +
  • +
    + Like emails +

    + Get an email when someone likes your post (bundled — one email per + post). Push and in-app notifications stay on either way. +

    +
    +
    + {enabled === null ? ( + … + ) : ( + + )} +
    +
  • +
+ ); +} diff --git a/lib/social.ts b/lib/social.ts index 7f18d847..35687fba 100644 --- a/lib/social.ts +++ b/lib/social.ts @@ -468,6 +468,16 @@ export const notifications = { markAllRead() { return call("/notifications/read", { method: "POST" }); }, + /** Email-notification preferences (currently aggregated like emails). */ + emailPrefs() { + return call<{ like_emails: boolean }>("/notifications/email-prefs"); + }, + setEmailPrefs(likeEmails: boolean) { + return call<{ like_emails: boolean }>("/notifications/email-prefs", { + method: "PUT", + body: JSON.stringify({ like_emails: likeEmails }), + }); + }, }; export const relationships = {