11// =================================================================================
2- // Chapter 1: Imports & Dependencies
2+ // Area 1: Constants, Imports & Dependencies
33// =================================================================================
44
5+ // 1.1: Timing constants
6+ // how long each welcome message displays (in milliseconds)
7+ const MESSAGE_DISPLAY_MS = 1800 ;
8+ // delay before first message appears (in seconds)
9+ const INITIAL_DELAY_SEC = 1 ;
10+
511import React , { useEffect , useState } from 'react' ;
612import messages from './messages' ;
713import './WelcomeWrap.css' ;
814import { useStateManager } from '../../stores/StateManager/StateManager' ;
915
1016// =================================================================================
11- // Chapter 2: Component Definition & State Manager Setup
17+ // Area 2: Component Definition & State Setup
1218// =================================================================================
1319
1420const WelcomeWrap = ( ) => {
15- // Initialize state manager hooks
21+ // 2.1: State manager hooks
1622 const { state, editStateValue, refreshState } = useStateManager ( ) ;
1723
18- // Determine if welcome screen is enabled in global state
24+ // 2.2: Check if welcome screen is enabled
1925 const welcomeEnabledStr =
2026 state . groups . welcomeWrap && state . groups . welcomeWrap . welcomeEnabled ;
2127 const welcomeEnabled = welcomeEnabledStr === "false" ? false : true ;
2228 if ( ! welcomeEnabled ) return null ;
2329
24- // Timing configuration for messages and animations
25- const totalDuration = 10 ;
26- const initialDelay = 1 ;
30+ // 2.3: Timing configuration
2731 const messageCount = messages . length ;
28- const messageDuration = ( totalDuration - initialDelay ) / messageCount ;
32+ // 2.3.1: per-message duration in seconds
33+ const messageDuration = MESSAGE_DISPLAY_MS / 1000 ;
34+ // 2.3.2: total seconds until switching to loading
35+ const totalDuration = INITIAL_DELAY_SEC + messageCount * messageDuration ;
2936
30- // Local UI state
37+ // 2.4: Local UI state flags
3138 const [ showWelcome , setShowWelcome ] = useState ( true ) ;
3239 const [ showLoading , setShowLoading ] = useState ( false ) ;
3340 const [ messageIndex , setMessageIndex ] = useState ( - 1 ) ;
@@ -36,80 +43,79 @@ const WelcomeWrap = () => {
3643 const [ fadeHello , setFadeHello ] = useState ( false ) ;
3744
3845 // =================================================================================
39- // Chapter 3: Mount Effect: Hide UI on Mount
46+ // Area 3: Mount Effect: Hide UI on Mount
4047 // =================================================================================
4148
4249 useEffect ( ( ) => {
43- // Hide dock, desktop icons, and menubar immediately
50+ // 3.1: Hide dock, icons, menubar immediately
4451 editStateValue ( "dock" , "dockVisible" , "false" ) ;
4552 editStateValue ( "desktop" , "iconVisible" , "false" ) ;
4653 editStateValue ( "desktop" , "menubarVisible" , "false" ) ;
4754 refreshState ( ) ;
4855 } , [ ] ) ;
4956
5057 // =================================================================================
51- // Chapter 4: Effect: Show Loading and Fade Welcome
58+ // Area 4: Effect: Show Loading and Fade Welcome
5259 // =================================================================================
5360
5461 useEffect ( ( ) => {
55- // After totalDuration seconds, transition to loading screen
62+ // 4.1: After totalDuration (sec), show loading and fade out welcome
5663 const t = setTimeout ( ( ) => {
5764 setShowLoading ( true ) ;
5865 setFadeWelcome ( true ) ;
59- // Remove welcome screen after fade-out
66+ // remove welcome after fade completes (1s)
6067 setTimeout ( ( ) => setShowWelcome ( false ) , 1000 ) ;
6168 } , totalDuration * 1000 ) ;
6269 return ( ) => clearTimeout ( t ) ;
6370 } , [ totalDuration ] ) ;
6471
6572 // =================================================================================
66- // Chapter 5: Effect: Cycle Welcome Messages
73+ // Area 5: Effect: Cycle Welcome Messages
6774 // =================================================================================
6875
6976 useEffect ( ( ) => {
7077 if ( ! showWelcome ) return ;
71- // Start cycling messages after initial delay
78+ // 5.1: first message after INITIAL_DELAY_SEC
7279 if ( messageIndex === - 1 ) {
73- const t = setTimeout ( ( ) => setMessageIndex ( 0 ) , initialDelay * 1000 ) ;
80+ const t = setTimeout ( ( ) => setMessageIndex ( 0 ) , INITIAL_DELAY_SEC * 1000 ) ;
7481 return ( ) => clearTimeout ( t ) ;
7582 }
76- // Advance to next message until all shown
83+ // 5.2: advance until the last message
7784 if ( messageIndex < messageCount - 1 ) {
7885 const t = setTimeout (
7986 ( ) => setMessageIndex ( i => i + 1 ) ,
8087 messageDuration * 1000
8188 ) ;
8289 return ( ) => clearTimeout ( t ) ;
8390 }
84- } , [ showWelcome , messageIndex , messageCount , messageDuration , initialDelay ] ) ;
91+ } , [ showWelcome , messageIndex , messageCount , messageDuration ] ) ;
8592
8693 // =================================================================================
87- // Chapter 6: Handler: Hello Animation End and Restore UI
94+ // Area 6: Handler: Hello Animation End and Restore UI
8895 // =================================================================================
8996
9097 const handleHelloAnimationEnd = ( ) => {
91- // Trigger fade-out of the SVG “hello”
9298 setFadeHello ( true ) ;
99+ // 6.1: wait 1s, restore UI, then fade loading
93100 setTimeout ( ( ) => {
94- // Restore dock, desktop icons, and menubar
95101 editStateValue ( "dock" , "dockVisible" , "true" ) ;
96102 editStateValue ( "desktop" , "iconVisible" , "true" ) ;
97103 editStateValue ( "desktop" , "menubarVisible" , "true" ) ;
98- // Disable further welcome screens
99- editStateValue ( "welcomeWrap" , "welcomeEnabled" , "false" ) ;
100104 refreshState ( ) ;
101-
102- // Fade out loading screen and then hide it
103105 setFadeLoading ( true ) ;
104- setTimeout ( ( ) => setShowLoading ( false ) , 1000 ) ;
106+ // 6.2: after fade, hide loading & disable future welcomes
107+ setTimeout ( ( ) => {
108+ setShowLoading ( false ) ;
109+ editStateValue ( "welcomeWrap" , "welcomeEnabled" , "false" ) ;
110+ refreshState ( ) ;
111+ } , 1000 ) ;
105112 } , 1000 ) ;
106113 } ;
107114
108- // Prevent pointer-events during welcome/loading phases
109115 const isBlocking = showWelcome || showLoading ;
110116
111117 // =================================================================================
112- // Chapter 7: Rendering: Conditional Screens and Animations
118+ // Area 7: Rendering
113119 // =================================================================================
114120
115121 return (
@@ -127,12 +133,11 @@ const WelcomeWrap = () => {
127133 ) }
128134 </ div >
129135 ) }
130-
131136 { showLoading && (
132137 < div className = { `loading-screen ${ fadeLoading ? 'fade-out' : '' } ` } >
133138 < div className = "loading-animation" >
134139 < div className = { `hello__div ${ fadeHello ? 'fade-out' : '' } ` } >
135- < svg
140+ < svg
136141 className = "hello__svg"
137142 viewBox = "0 0 1230.94 414.57"
138143 onAnimationEnd = { handleHelloAnimationEnd }
0 commit comments