forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStartupModals.tsx
More file actions
63 lines (52 loc) · 2.15 KB
/
Copy pathStartupModals.tsx
File metadata and controls
63 lines (52 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use client';
import { useEffect, useState } from 'react';
import { AnimatePresence } from 'framer-motion';
import { BetaWelcomeModal } from '@/components/ui/BetaWelcomeModal';
import { WhatsNewModal } from '@/components/ui/WhatsNewModal';
// Increment this version when adding new features
const WHATS_NEW_VERSION = 1;
const BETA_WELCOME_STORAGE_KEY = 'omi_beta_welcome_seen';
const WHATS_NEW_STORAGE_KEY = 'omi_whats_new_version';
type StartupModal = 'beta-welcome' | 'whats-new' | null;
export function StartupModals() {
const [activeModal, setActiveModal] = useState<StartupModal>(null);
const [whatsNewPending, setWhatsNewPending] = useState(false);
useEffect(() => {
// Check if user has already seen the welcome modal
const hasSeenWelcome = localStorage.getItem(BETA_WELCOME_STORAGE_KEY);
// Check the last version the user has seen
const lastSeenVersion = localStorage.getItem(WHATS_NEW_STORAGE_KEY);
const lastVersion = lastSeenVersion ? parseInt(lastSeenVersion, 10) : 0;
const shouldShowWhatsNew = lastVersion < WHATS_NEW_VERSION;
setWhatsNewPending(shouldShowWhatsNew);
if (!hasSeenWelcome) {
// Small delay to let the page load first
const timer = setTimeout(() => setActiveModal('beta-welcome'), 500);
return () => clearTimeout(timer);
}
// Show modal if there's a new version
if (shouldShowWhatsNew) {
// Small delay to let the page load first
const timer = setTimeout(() => setActiveModal('whats-new'), 800);
return () => clearTimeout(timer);
}
}, []);
const dismissBetaWelcome = () => {
localStorage.setItem(BETA_WELCOME_STORAGE_KEY, 'true');
setActiveModal(whatsNewPending ? 'whats-new' : null);
};
const dismissWhatsNew = () => {
localStorage.setItem(WHATS_NEW_STORAGE_KEY, WHATS_NEW_VERSION.toString());
setActiveModal(null);
};
return (
<AnimatePresence mode="wait">
{activeModal === 'beta-welcome' && (
<BetaWelcomeModal key="beta-welcome" onDismiss={dismissBetaWelcome} />
)}
{activeModal === 'whats-new' && (
<WhatsNewModal key="whats-new" onDismiss={dismissWhatsNew} />
)}
</AnimatePresence>
);
}