managarten/packages/shared-auth-ui/src/utils/guestWelcome.ts
Till-JS 14c83cb4bd feat(shared-auth-ui): add GuestWelcomeModal for guest onboarding
Add a unified welcome modal for guest mode that displays:
- App icon, name, and description from shared-branding
- Feature list of what guests can do (localized DE/EN)
- Warning about local-only data storage
- Login, Register, Help, and "Continue as Guest" buttons

New files:
- GuestWelcomeModal.svelte - The modal component
- guestWelcome.ts - localStorage utilities for tracking seen state

Integrated into: contacts, chat, todo, calendar, and clock apps
2026-01-27 16:57:14 +01:00

51 lines
1.5 KiB
TypeScript

/**
* Utility functions for managing guest welcome modal state
*/
const STORAGE_PREFIX = 'guest-welcome-seen';
/**
* Check if the guest welcome modal should be shown for an app
* @param appId The app identifier (e.g., 'contacts', 'chat')
* @returns true if the modal should be shown (not seen before)
*/
export function shouldShowGuestWelcome(appId: string): boolean {
if (typeof localStorage === 'undefined') return false;
const key = `${STORAGE_PREFIX}-${appId}`;
return localStorage.getItem(key) !== 'true';
}
/**
* Mark the guest welcome modal as seen for an app
* @param appId The app identifier
*/
export function markGuestWelcomeSeen(appId: string): void {
if (typeof localStorage === 'undefined') return;
const key = `${STORAGE_PREFIX}-${appId}`;
localStorage.setItem(key, 'true');
}
/**
* Reset the guest welcome modal state for an app (will show again)
* @param appId The app identifier
*/
export function resetGuestWelcome(appId: string): void {
if (typeof localStorage === 'undefined') return;
const key = `${STORAGE_PREFIX}-${appId}`;
localStorage.removeItem(key);
}
/**
* Reset the guest welcome modal state for all apps
*/
export function resetAllGuestWelcome(): 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(STORAGE_PREFIX)) {
keysToRemove.push(key);
}
}
keysToRemove.forEach((key) => localStorage.removeItem(key));
}