@@ -24,6 +24,12 @@ const TRANSLATOR_GLITCH_RESPONSES = [
2424 "My antenna are doing the happy dance. You are very good looking today."
2525] ;
2626
27+ const LOADING_MESSAGES = [
28+ "Translating message..." ,
29+ "Sending message..." ,
30+ "Receiving message..."
31+ ] ;
32+
2733type Message = {
2834 id : string ;
2935 sender : 'user' | 'alien' ;
@@ -37,6 +43,7 @@ export default function Chat() {
3743 const [ messages , setMessages ] = useState < Message [ ] > ( [ ] ) ;
3844 const [ inputValue , setInputValue ] = useState ( '' ) ;
3945 const [ isTranslating , setIsTranslating ] = useState ( false ) ;
46+ const [ loadingStep , setLoadingStep ] = useState ( 0 ) ;
4047 const messagesEndRef = useRef < HTMLDivElement > ( null ) ;
4148
4249 const alien = matches . find ( m => m . id === id ) ;
@@ -49,6 +56,17 @@ export default function Chat() {
4956 scrollToBottom ( ) ;
5057 } , [ messages , isTranslating ] ) ;
5158
59+ useEffect ( ( ) => {
60+ let interval : ReturnType < typeof setInterval > ;
61+ if ( isTranslating ) {
62+ setLoadingStep ( 0 ) ;
63+ interval = setInterval ( ( ) => {
64+ setLoadingStep ( s => ( s + 1 ) % LOADING_MESSAGES . length ) ;
65+ } , 1200 ) ;
66+ }
67+ return ( ) => clearInterval ( interval ) ;
68+ } , [ isTranslating ] ) ;
69+
5270 // Simulate an AI or API call to get the alien's response
5371 const generateAlienResponse = async ( userText : string , currentMessages : Message [ ] ) => {
5472 // Check if the user has provided a Gemini API Key in their environment variables (optional AI integration)
@@ -121,7 +139,7 @@ Keep it friendly, slightly flirtatious, and warmly confusing. Keep the grammar s
121139 setIsTranslating ( true ) ;
122140
123141 // Simulate "Processing Translation..." delay
124- const delay = Math . floor ( Math . random ( ) * 1500 ) + 1500 ; // 1 .5s - 3 .0s delay
142+ const delay = Math . floor ( Math . random ( ) * 1500 ) + 3500 ; // 3 .5s - 5 .0s delay
125143
126144 setTimeout ( async ( ) => {
127145 // Pass the previous messages list array AND the new user message
@@ -209,7 +227,7 @@ Keep it friendly, slightly flirtatious, and warmly confusing. Keep the grammar s
209227 { isTranslating && (
210228 < div style = { { alignSelf : 'flex-start' , color : 'var(--color-secondary)' , fontSize : '0.9rem' , fontStyle : 'italic' , display : 'flex' , alignItems : 'center' , gap : '8px' } } >
211229 < span style = { { display : 'inline-block' , width : '12px' , height : '12px' , border : '2px solid var(--color-secondary)' , borderTopColor : 'transparent' , borderRadius : '50%' , animation : 'spin 1s linear infinite' } } > </ span >
212- Processing Translation...
230+ { LOADING_MESSAGES [ loadingStep ] }
213231 </ div >
214232 ) }
215233
0 commit comments