@@ -12,7 +12,8 @@ function App() {
1212 // State for results and UI feedback
1313 const [ result , setResult ] = useState ( null ) ;
1414 const [ error , setError ] = useState ( '' ) ;
15- const [ loading , setLoading ] = useState ( false ) ;
15+ const [ isCompressing , setIsCompressing ] = useState ( false ) ;
16+ const [ isDecompressing , setIsDecompressing ] = useState ( false ) ;
1617
1718 // API endpoint base URL for local development
1819 //const API_URL = 'http://localhost:8080/api';
@@ -28,7 +29,10 @@ function App() {
2829 setError ( 'Please enter text to compress.' ) ;
2930 return ;
3031 }
31- setLoading ( true ) ;
32+
33+ if ( isDecompressing ) return ;
34+
35+ setIsCompressing ( true ) ;
3236 setError ( '' ) ;
3337 setResult ( null ) ;
3438
@@ -71,7 +75,7 @@ function App() {
7175 setError ( 'Failed to compress text. Make sure the backend server is running.' ) ;
7276 console . error ( e ) ;
7377 } finally {
74- setLoading ( false ) ;
78+ setIsCompressing ( false ) ;
7579 }
7680 } ;
7781
@@ -85,14 +89,16 @@ function App() {
8589 return ;
8690 }
8791
92+ if ( isCompressing ) return ;
93+
8894 try {
8995 parsedCodeTable = JSON . parse ( codeTableInput ) ;
9096 } catch ( e ) {
9197 setError ( 'Invalid JSON in the code table. Please check the format.' ) ;
9298 return ;
9399 }
94100
95- setLoading ( true ) ;
101+ setIsDecompressing ( true ) ;
96102 setError ( '' ) ;
97103 setResult ( null ) ;
98104
@@ -122,7 +128,7 @@ function App() {
122128 setError ( 'Failed to decompress text. Make sure the backend server is running and the inputs are correct.' ) ;
123129 console . error ( e ) ;
124130 } finally {
125- setLoading ( false ) ;
131+ setIsDecompressing ( false ) ;
126132 }
127133 } ;
128134
@@ -146,8 +152,8 @@ function App() {
146152 placeholder = "Type your text here..."
147153 rows = "8"
148154 />
149- < button className = "btn" onClick = { handleCompress } disabled = { loading } >
150- { loading ? 'Compressing...' : 'Compress' }
155+ < button className = "btn" onClick = { handleCompress } disabled = { isCompressing || isDecompressing } >
156+ { isCompressing ? 'Compressing...' : 'Compress' }
151157 </ button >
152158 </ div >
153159
@@ -169,8 +175,8 @@ function App() {
169175 placeholder = 'Code table in JSON format (e.g., {"a": "01", "b": "10"})'
170176 rows = "4"
171177 />
172- < button className = "btn" onClick = { handleDecompress } disabled = { loading } >
173- { loading ? 'Decompressing...' : 'Decompress' }
178+ < button className = "btn" onClick = { handleDecompress } disabled = { isCompressing || isDecompressing } >
179+ { isDecompressing ? 'Decompressing...' : 'Decompress' }
174180 </ button >
175181 </ div >
176182 </ div >
0 commit comments