File tree Expand file tree Collapse file tree 2 files changed +16
-15
lines changed Expand file tree Collapse file tree 2 files changed +16
-15
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,7 @@ const ConfigurationModal = ({ closeModal }: ConfigurationModalProps) => {
91
91
92
92
function App ( ) {
93
93
const { isMinimode } = useMinimode ( ) ;
94
+ const [ isDead , setDead ] = React . useState ( false ) ;
94
95
const [ currentPage , setCurrentPage ] = React . useState ( PAGES . PLAYER_LIST ) ;
95
96
96
97
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -138,17 +139,15 @@ function App() {
138
139
} ;
139
140
140
141
const verificationRoutine = async ( ) => {
141
- let connected = false ;
142
- let dead = false ;
143
- do {
144
- connected = await isBackendConnected ( ) ;
145
- if ( ! connected ) {
146
- dead = true ;
147
- await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ; // Wait 1 second before retrying
142
+ if ( await isBackendConnected ( ) ) {
143
+ if ( isDead ) {
144
+ setDead ( false ) ;
145
+ closeModal ( ) ;
148
146
}
149
- } while ( ! connected ) ;
150
- if ( dead ) closeModal ( ) ; // If backend died, we need to remove the modal once it recovers.
151
- verifyConfigured ( ) ;
147
+ verifyConfigured ( ) ;
148
+ } else {
149
+ if ( ! isDead ) setDead ( true ) ;
150
+ }
152
151
} ;
153
152
154
153
React . useEffect ( ( ) => {
@@ -163,14 +162,12 @@ function App() {
163
162
164
163
// Don't verify backend if we're using fakedata (dev environment)
165
164
if ( useFakedata ) return ;
166
-
167
- verificationRoutine ( ) ;
168
165
const intervalId = setInterval ( verificationRoutine , 1000 ) ;
169
166
170
167
return ( ) => {
171
168
clearInterval ( intervalId ) ;
172
169
} ;
173
- } , [ currentPage ] ) ;
170
+ } , [ currentPage , isDead ] ) ;
174
171
175
172
return (
176
173
< div className = "App" >
Original file line number Diff line number Diff line change @@ -15,9 +15,13 @@ export const COMMAND_ENDPOINT = `${APIURL}/commands/v1`;
15
15
export const useFakedata = process . env . NODE_ENV ?. includes ( 'development' ) ;
16
16
17
17
export async function verifyBackend ( ) : Promise < boolean > {
18
- return await fetch ( SERVERFETCH )
18
+ const controller = new AbortController ( ) ;
19
+ const timeoutId = setTimeout ( ( ) => controller . abort ( ) , 500 ) ;
20
+
21
+ return await fetch ( SERVERFETCH , { signal : controller . signal } )
19
22
. then ( ( res ) => res . ok )
20
- . catch ( ( ) => false ) ;
23
+ . catch ( ( ) => false )
24
+ . finally ( ( ) => clearTimeout ( timeoutId ) ) ;
21
25
}
22
26
23
27
export async function isBackendConfigured ( ) : Promise < boolean > {
You can’t perform that action at this time.
0 commit comments