mirror of
https://github.com/nicetry247/offlineacademy.git
synced 2026-07-26 11:58:44 +00:00
49 lines
1.2 KiB
TypeScript
Executable File
49 lines
1.2 KiB
TypeScript
Executable File
'use client'
|
|
|
|
import * as React from 'react'
|
|
import { ThemeProvider } from '@/components/ThemeToggle'
|
|
import { ToastProvider } from '@/hooks/use-toast'
|
|
import { SplashScreen } from '@/components/SplashScreen'
|
|
|
|
const SPLASH_SESSION_KEY = 'offlineacademy:splash-seen'
|
|
|
|
export function Providers({ children }: { children: React.ReactNode }) {
|
|
const [showSplash, setShowSplash] = React.useState(true)
|
|
|
|
React.useLayoutEffect(() => {
|
|
try {
|
|
if (sessionStorage.getItem(SPLASH_SESSION_KEY) === 'true') {
|
|
setShowSplash(false)
|
|
}
|
|
} catch {
|
|
setShowSplash(false)
|
|
}
|
|
}, [])
|
|
|
|
React.useEffect(() => {
|
|
if (!showSplash) return
|
|
const timer = window.setTimeout(() => setShowSplash(false), 2500)
|
|
return () => window.clearTimeout(timer)
|
|
}, [showSplash])
|
|
|
|
const completeSplash = React.useCallback(() => {
|
|
try {
|
|
sessionStorage.setItem(SPLASH_SESSION_KEY, 'true')
|
|
} catch {
|
|
// Storage can be unavailable in hardened/private browser modes.
|
|
}
|
|
setShowSplash(false)
|
|
}, [])
|
|
|
|
return (
|
|
<ThemeProvider>
|
|
<ToastProvider>
|
|
{children}
|
|
{showSplash && (
|
|
<SplashScreen onComplete={completeSplash} minDuration={550} />
|
|
)}
|
|
</ToastProvider>
|
|
</ThemeProvider>
|
|
)
|
|
}
|