11import { BrowserRouter as Router , Routes , Route , Navigate } from 'react-router-dom' ;
2- import { useEffect } from 'react' ;
2+ import { useEffect , useState } from 'react' ;
33import Register from './components/pages/Register' ;
44import Login from './components/pages/Login' ;
55import Tos from './components/pages/Tos' ;
@@ -11,8 +11,35 @@ import MainLayout from './components/layout/MainLayout';
1111import { toggleDevTools } from './lib/utils' ;
1212import PrivacyPolicy from './components/pages/PrivacyPolicy' ;
1313import FileReader from './components/pages/FileReader' ;
14+ import ApplicationSplash from './components/modals/ApplicationSplash' ;
15+ import { AnimatePresence } from 'framer-motion' ;
16+
17+ // Key for session storage to check if app has been loaded before
18+ const APP_LOADED_KEY = 'cloudnotes-app-loaded' ;
1419
1520function App ( ) {
21+ const [ isLoading , setIsLoading ] = useState ( true ) ;
22+
23+ // Handle application loading state
24+ useEffect ( ( ) => {
25+ // Check if this is the first load of the app in this session
26+ const hasLoadedBefore = sessionStorage . getItem ( APP_LOADED_KEY ) ;
27+
28+ if ( hasLoadedBefore ) {
29+ // If app has been loaded before in this session, skip the loading screen
30+ setIsLoading ( false ) ;
31+ } else {
32+ // First load in this session - show loading for 10 seconds
33+ const loadingTimer = setTimeout ( ( ) => {
34+ setIsLoading ( false ) ;
35+ // Mark app as loaded for this session
36+ sessionStorage . setItem ( APP_LOADED_KEY , 'true' ) ;
37+ } , 8000 ) ;
38+
39+ return ( ) => clearTimeout ( loadingTimer ) ;
40+ }
41+ } , [ ] ) ;
42+
1643 // Add keyboard listeners for development tools
1744 useEffect ( ( ) => {
1845 const handleKeyDown = ( e : KeyboardEvent ) => {
@@ -30,58 +57,77 @@ function App() {
3057 } , [ ] ) ;
3158
3259 return (
33- < Router >
34- < Routes >
35- { /* Auth routes without MainLayout */ }
36- < Route path = "/register" element = {
37- < MainLayout >
38- < Register />
39- </ MainLayout >
40- } />
41- < Route path = "/login" element = {
42- < MainLayout >
43- < Login />
44- </ MainLayout >
45- } />
46- < Route path = "/tos" element = {
47- < MainLayout >
48- < Tos />
49- </ MainLayout >
50- } />
51- < Route path = "/privacy-policy" element = {
52- < MainLayout >
53- < PrivacyPolicy />
54- </ MainLayout >
55- } />
56- < Route path = "/forgot-password" element = {
57- < MainLayout >
58- < ForgotPassword />
59- </ MainLayout >
60- } />
61- < Route path = "/verify-otp" element = {
62- < MainLayout >
63- < VerifyOTP />
64- </ MainLayout >
65- } />
66- < Route path = "/reset-password" element = {
67- < MainLayout >
68- < ResetPassword />
69- </ MainLayout >
70- } />
71- < Route path = "/reset-password-success" element = {
72- < MainLayout >
73- < ResetPasswordSuccess />
74- </ MainLayout >
75- } />
76-
77- { /* FileReader route without MainLayout */ }
78- < Route path = "/reader" element = { < FileReader /> } />
79-
80- { /* Default route */ }
81- < Route path = "*" element = { < Navigate to = "/register" replace /> } />
82- </ Routes >
83- </ Router >
60+ < >
61+ { /* Splash screen with animation */ }
62+ < AnimatePresence >
63+ { isLoading && < ApplicationSplash isOpen = { true } /> }
64+ </ AnimatePresence >
65+
66+ { /* Render the app regardless of loading state, but it will be hidden behind the splash screen */ }
67+ < div className = { isLoading ? 'invisible' : 'visible' } >
68+ < Router >
69+ < Routes >
70+ { /* Auth routes without MainLayout */ }
71+ < Route path = "/register" element = {
72+ < MainLayout >
73+ < Register />
74+ </ MainLayout >
75+ } />
76+ < Route path = "/login" element = {
77+ < MainLayout >
78+ < Login />
79+ </ MainLayout >
80+ } />
81+ < Route path = "/tos" element = {
82+ < MainLayout >
83+ < Tos />
84+ </ MainLayout >
85+ } />
86+ < Route path = "/privacy-policy" element = {
87+ < MainLayout >
88+ < PrivacyPolicy />
89+ </ MainLayout >
90+ } />
91+ < Route path = "/forgot-password" element = {
92+ < MainLayout >
93+ < ForgotPassword />
94+ </ MainLayout >
95+ } />
96+ < Route path = "/verify-otp" element = {
97+ < MainLayout >
98+ < VerifyOTP />
99+ </ MainLayout >
100+ } />
101+ < Route path = "/reset-password" element = {
102+ < MainLayout >
103+ < ResetPassword />
104+ </ MainLayout >
105+ } />
106+ < Route path = "/reset-password-success" element = {
107+ < MainLayout >
108+ < ResetPasswordSuccess />
109+ </ MainLayout >
110+ } />
111+
112+ { /* FileReader route without MainLayout */ }
113+ < Route path = "/reader" element = { < FileReader /> } />
114+
115+ { /* Default route */ }
116+ < Route path = "*" element = { < Navigate to = "/register" replace /> } />
117+ </ Routes >
118+ </ Router >
119+ </ div >
120+ </ >
84121 ) ;
85122}
86123
124+ // Function to manually trigger the loading screen (will be exported and used in LeftSidebar)
125+ export function triggerLoadingScreen ( ) {
126+ // Clear the loaded flag so next refresh will show the loading screen
127+ sessionStorage . removeItem ( APP_LOADED_KEY ) ;
128+
129+ // Reload the page to show the loading screen
130+ window . location . reload ( ) ;
131+ }
132+
87133export default App ;
0 commit comments