feat(coach): add an opt-out for proactive ambient suggestions

Add a per-user toggle that turns off the proactive ambient example suggestions
(the daily seeded opener on the Coach hero). The flag rides the existing coach
notification-prefs blob (coach.ambientSuggestions, default on) — no schema
change — and a shared hook makes it the single source every ambient suggestion
surface consults, so the seeded opener and its fetch both stand down when off.
This commit is contained in:
Marc-André Bombeck committed 2026-06-28 16:04:22 +02:00
1 parent e55058a1ce
commit c862b4880f
12 files changed
+139 -8

No files matched your search

@@ -0,0 +1,34 @@
"use client";
import { useQuery } from "@tanstack/react-query";
import { queryKeys } from "@/lib/query-keys";
import { apiGet } from "@/lib/api/api-fetch";
import { useAuth } from "@/hooks/use-auth";
/**
* v1.25.0 — the single client-side gate for proactive ambient Coach
* SUGGESTIONS (today: the daily seeded example opener on the Coach hero).
*
* Reads the per-user opt-out from the shared notification-prefs blob
* (`coach.ambientSuggestions`). Default ON: an unauthenticated read, a
* still-loading query, or a missing field all resolve to `true` so the
* suggestions show out of the box and only hide once the user explicitly turns
* them off in Settings. Shares the `authNotificationPrefs` query key with the
* settings card, so toggling the switch there flips this read in lockstep.
*/
interface AmbientSuggestionsPrefsShape {
coach?: { ambientSuggestions?: boolean };
}
export function useCoachAmbientSuggestionsEnabled(): boolean {
const { isAuthenticated } = useAuth();
const { data } = useQuery({
queryKey: queryKeys.authNotificationPrefs(),
queryFn: async () =>
apiGet<AmbientSuggestionsPrefsShape>("/api/auth/me/notification-prefs"),
enabled: isAuthenticated,
staleTime: 5 * 60 * 1000,
});
return data?.coach?.ambientSuggestions ?? true;
}