mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-15 19:19:41 +02:00
- Add GuestRegistrationNudge component: shows a floating banner after X minutes of guest usage to encourage sign-up (bottom-center, dismissible) - Add guestNudge.ts utilities (session tracking, delay, dismiss via localStorage) - Add feature texts for all 16 missing apps in GuestWelcomeModal - Integrate nudge in Todo app as reference implementation (3min delay) - Improve SkillTree seed: 3 skills across branches, 6 activities, 1 achievement - Improve Zitare seed: 5 favorites, 2 themed lists instead of 1 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
69 lines
2.1 KiB
TypeScript
69 lines
2.1 KiB
TypeScript
/**
|
|
* Utility functions for managing guest registration nudge state.
|
|
* Shows a nudge after X minutes of guest usage to encourage sign-up.
|
|
*/
|
|
|
|
const SESSION_PREFIX = 'guest-nudge-session';
|
|
const DISMISSED_PREFIX = 'guest-nudge-dismissed';
|
|
|
|
/**
|
|
* Record the start of a guest session for an app (call once on mount).
|
|
* Only sets the timestamp if one doesn't already exist.
|
|
*/
|
|
export function startGuestSession(appId: string): void {
|
|
if (typeof localStorage === 'undefined') return;
|
|
const key = `${SESSION_PREFIX}-${appId}`;
|
|
if (!localStorage.getItem(key)) {
|
|
localStorage.setItem(key, Date.now().toString());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check if enough time has passed to show the registration nudge.
|
|
* Returns false if already dismissed or not enough time elapsed.
|
|
*/
|
|
export function shouldShowGuestNudge(appId: string, delayMinutes = 5): boolean {
|
|
if (typeof localStorage === 'undefined') return false;
|
|
|
|
// Already dismissed?
|
|
if (localStorage.getItem(`${DISMISSED_PREFIX}-${appId}`) === 'true') return false;
|
|
|
|
// Check elapsed time
|
|
const sessionStart = localStorage.getItem(`${SESSION_PREFIX}-${appId}`);
|
|
if (!sessionStart) return false;
|
|
|
|
const elapsed = Date.now() - parseInt(sessionStart, 10);
|
|
return elapsed >= delayMinutes * 60 * 1000;
|
|
}
|
|
|
|
/**
|
|
* Permanently dismiss the nudge for an app.
|
|
*/
|
|
export function dismissGuestNudge(appId: string): void {
|
|
if (typeof localStorage === 'undefined') return;
|
|
localStorage.setItem(`${DISMISSED_PREFIX}-${appId}`, 'true');
|
|
}
|
|
|
|
/**
|
|
* Reset nudge state for an app (will show again after delay).
|
|
*/
|
|
export function resetGuestNudge(appId: string): void {
|
|
if (typeof localStorage === 'undefined') return;
|
|
localStorage.removeItem(`${SESSION_PREFIX}-${appId}`);
|
|
localStorage.removeItem(`${DISMISSED_PREFIX}-${appId}`);
|
|
}
|
|
|
|
/**
|
|
* Reset nudge state for all apps.
|
|
*/
|
|
export function resetAllGuestNudges(): void {
|
|
if (typeof localStorage === 'undefined') return;
|
|
const keysToRemove: string[] = [];
|
|
for (let i = 0; i < localStorage.length; i++) {
|
|
const key = localStorage.key(i);
|
|
if (key?.startsWith(SESSION_PREFIX) || key?.startsWith(DISMISSED_PREFIX)) {
|
|
keysToRemove.push(key);
|
|
}
|
|
}
|
|
keysToRemove.forEach((key) => localStorage.removeItem(key));
|
|
}
|