50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
|
|
/**
|
||
|
|
* Public-demo helpers.
|
||
|
|
*
|
||
|
|
* The demo build (VITE_DEMO=1) replays the intro/onboarding on each visit, but
|
||
|
|
* only once per calendar day per browser — tracked in localStorage so it
|
||
|
|
* survives the short-lived backend session. Also exposes the shared demo
|
||
|
|
* credentials shown on the login screen.
|
||
|
|
*/
|
||
|
|
|
||
|
|
export const IS_DEMO =
|
||
|
|
import.meta.env.VITE_DEMO === '1' || import.meta.env.VITE_DEMO === 'true'
|
||
|
|
|
||
|
|
/** Memorable shared password for the public demo (must match the mock backend). */
|
||
|
|
export const DEMO_PASSWORD = 'entertoexit'
|
||
|
|
|
||
|
|
const INTRO_DATE_KEY = 'demo_intro_date'
|
||
|
|
|
||
|
|
function todayKey(): string {
|
||
|
|
// Local calendar day, e.g. "2026-06-22".
|
||
|
|
const d = new Date()
|
||
|
|
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
|
||
|
|
}
|
||
|
|
|
||
|
|
/** True if this browser already watched the intro earlier today. */
|
||
|
|
export function demoIntroSeenToday(): boolean {
|
||
|
|
try {
|
||
|
|
return localStorage.getItem(INTRO_DATE_KEY) === todayKey()
|
||
|
|
} catch {
|
||
|
|
return false
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/** Record that the intro has been seen today, so it won't replay until tomorrow. */
|
||
|
|
export function markDemoIntroSeen(): void {
|
||
|
|
try {
|
||
|
|
localStorage.setItem(INTRO_DATE_KEY, todayKey())
|
||
|
|
} catch {
|
||
|
|
/* ignore (private mode / storage disabled) */
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/** Forget today's "seen" marker so the intro plays again (e.g. "Replay Intro"). */
|
||
|
|
export function clearDemoIntroSeen(): void {
|
||
|
|
try {
|
||
|
|
localStorage.removeItem(INTRO_DATE_KEY)
|
||
|
|
} catch {
|
||
|
|
/* ignore */
|
||
|
|
}
|
||
|
|
}
|