Add Notifications preferences (session-expiry reminder lead time)

- New Notifications screen (Account > Notifications): enable/disable expiry
  reminders + a 5-minute-increment stepper (5–60 min), default 15 min
- localReminders.scheduleExpiryReminder now reads the persisted lead time + enabled
  flag, so it's ready to fire once the start-session flow is wired

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Hank 2026-07-06 11:33:17 -07:00
parent a566f41d66
commit 9a5c9d445f
5 changed files with 173 additions and 3 deletions

View file

@ -0,0 +1,37 @@
import AsyncStorage from '@react-native-async-storage/async-storage';
/**
* How many minutes before a session's expiry to fire the local reminder.
* Configurable in Notifications preferences, in 5-minute increments.
*/
const KEY = 'ps_reminder_lead_minutes';
export const DEFAULT_LEAD_MINUTES = 15;
export const MIN_LEAD_MINUTES = 5;
export const MAX_LEAD_MINUTES = 60;
export const LEAD_STEP = 5;
/** When true, expiry reminders are enabled at all. */
const ENABLED_KEY = 'ps_reminder_enabled';
export async function getReminderLeadMinutes(): Promise<number> {
const raw = await AsyncStorage.getItem(KEY);
const n = raw != null ? parseInt(raw, 10) : NaN;
return Number.isFinite(n) ? n : DEFAULT_LEAD_MINUTES;
}
export async function setReminderLeadMinutes(minutes: number): Promise<void> {
const clamped = Math.min(
MAX_LEAD_MINUTES,
Math.max(MIN_LEAD_MINUTES, Math.round(minutes / LEAD_STEP) * LEAD_STEP),
);
await AsyncStorage.setItem(KEY, String(clamped));
}
export async function getRemindersEnabled(): Promise<boolean> {
const raw = await AsyncStorage.getItem(ENABLED_KEY);
return raw == null ? true : raw === 'true';
}
export async function setRemindersEnabled(on: boolean): Promise<void> {
await AsyncStorage.setItem(ENABLED_KEY, String(on));
}