5.2.1
New welcome note & subscribe reminders
This commit is contained in:
@@ -626,6 +626,30 @@ export function useAppState() {
|
||||
};
|
||||
const openWelcome = () => setWelcomeOpen(true);
|
||||
|
||||
// ── Weekly subscribe nudge (free users only) ─────────────────────────
|
||||
// At most once every 7 days, and never on the first visit - the welcome
|
||||
// popup owns that moment. The last-shown date lives in localStorage;
|
||||
// subscribing (isPro) suppresses it entirely.
|
||||
const NUDGE_KEY = 'sunscope_nudge_last';
|
||||
const NUDGE_COOLDOWN = 7 * 24 * 60 * 60 * 1000;
|
||||
const [weeklyNudgeOpen, setWeeklyNudgeOpen] = useState(false);
|
||||
useEffect(() => {
|
||||
if (isPro || welcomeOpen) return;
|
||||
let last = 0;
|
||||
try {
|
||||
last = Number(localStorage.getItem(NUDGE_KEY)) || 0;
|
||||
// First run for an existing user: start the clock, don't nudge yet.
|
||||
if (!last) { localStorage.setItem(NUDGE_KEY, String(Date.now())); return; }
|
||||
} catch (e) { return; }
|
||||
if (Date.now() - last < NUDGE_COOLDOWN) return;
|
||||
setWeeklyNudgeOpen(true);
|
||||
track('weekly_nudge_shown');
|
||||
}, [isPro, welcomeOpen]);
|
||||
const closeWeeklyNudge = () => {
|
||||
try { localStorage.setItem(NUDGE_KEY, String(Date.now())); } catch (e) { /* ignore */ }
|
||||
setWeeklyNudgeOpen(false);
|
||||
};
|
||||
|
||||
// Restore-access modal ("Already subscribed?").
|
||||
const [restoreOpen, setRestoreOpen] = useState(false);
|
||||
const openRestore = () => setRestoreOpen(true);
|
||||
@@ -910,6 +934,7 @@ export function useAppState() {
|
||||
utciEnv, setUtciEnv: setUtciEnvAndSave,
|
||||
showDecimals, toggleShowDecimals,
|
||||
welcomeOpen, closeWelcome, openWelcome,
|
||||
weeklyNudgeOpen, closeWeeklyNudge,
|
||||
restoreOpen, openRestore, closeRestore,
|
||||
panelOpen, openPanel, closePanel,
|
||||
showUnits, toggleShowUnits,
|
||||
|
||||
Reference in New Issue
Block a user