@@ -2,10 +2,9 @@ import React, { FunctionComponent, useCallback, useEffect, useState } from 'reac
2
2
import { Outlet , useLocation , useNavigate } from 'react-router-dom' ;
3
3
import type { ApiClient , ConnectResponse } from 'jellyfin-apiclient' ;
4
4
5
- import globalize from 'lib/globalize' ;
6
5
import { ConnectionState , ServerConnections } from 'lib/jellyfin-apiclient' ;
7
6
8
- import alert from './alert ' ;
7
+ import ConnectionErrorPage from './ConnectionErrorPage ' ;
9
8
import Loading from './loading/LoadingComponent' ;
10
9
11
10
enum AccessLevel {
@@ -56,8 +55,16 @@ const ConnectionRequired: FunctionComponent<ConnectionRequiredProps> = ({
56
55
const navigate = useNavigate ( ) ;
57
56
const location = useLocation ( ) ;
58
57
58
+ const [ errorState , setErrorState ] = useState < ConnectionState > ( ) ;
59
59
const [ isLoading , setIsLoading ] = useState ( true ) ;
60
60
61
+ const navigateIfNotThere = useCallback ( ( route : BounceRoutes ) => {
62
+ // If we try to navigate to the current route, just set isLoading = false
63
+ if ( location . pathname === route ) setIsLoading ( false ) ;
64
+ // Otherwise navigate to the route
65
+ else navigate ( route ) ;
66
+ } , [ location . pathname , navigate ] ) ;
67
+
61
68
const bounce = useCallback ( async ( connectionResponse : ConnectResponse ) => {
62
69
switch ( connectionResponse . State ) {
63
70
case ConnectionState . SignedIn :
@@ -77,31 +84,14 @@ const ConnectionRequired: FunctionComponent<ConnectionRequiredProps> = ({
77
84
return ;
78
85
case ConnectionState . ServerSelection :
79
86
// Bounce to select server page
80
- if ( location . pathname === BounceRoutes . SelectServer ) {
81
- setIsLoading ( false ) ;
82
- } else {
83
- console . debug ( '[ConnectionRequired] redirecting to select server page' ) ;
84
- navigate ( BounceRoutes . SelectServer ) ;
85
- }
86
- return ;
87
- case ConnectionState . ServerUpdateNeeded :
88
- // Show update needed message and bounce to select server page
89
- try {
90
- await alert ( {
91
- text : globalize . translate ( 'ServerUpdateNeeded' , 'https://github.com/jellyfin/jellyfin' ) ,
92
- html : globalize . translate ( 'ServerUpdateNeeded' , '<a href="https://github.com/jellyfin/jellyfin">https://github.com/jellyfin/jellyfin</a>' )
93
- } ) ;
94
- } catch ( ex ) {
95
- console . warn ( '[ConnectionRequired] failed to show alert' , ex ) ;
96
- }
97
- console . debug ( '[ConnectionRequired] server update required, redirecting to select server page' ) ;
98
- navigate ( BounceRoutes . SelectServer ) ;
87
+ console . debug ( '[ConnectionRequired] redirecting to select server page' ) ;
88
+ navigateIfNotThere ( BounceRoutes . SelectServer ) ;
99
89
return ;
100
90
}
101
91
102
92
console . warn ( '[ConnectionRequired] unhandled connection state' , connectionResponse . State ) ;
103
93
// eslint-disable-next-line react-hooks/exhaustive-deps
104
- } , [ location . pathname , navigate ] ) ;
94
+ } , [ navigateIfNotThere , location . pathname , navigate ] ) ;
105
95
106
96
const handleWizard = useCallback ( async ( firstConnection : ConnectResponse | null ) => {
107
97
const apiClient = firstConnection ?. ApiClient || ServerConnections . currentApiClient ( ) ;
@@ -194,7 +184,9 @@ const ConnectionRequired: FunctionComponent<ConnectionRequiredProps> = ({
194
184
console . debug ( '[ConnectionRequired] connection state' , firstConnection ?. State ) ;
195
185
ServerConnections . firstConnection = true ;
196
186
197
- if ( level === AccessLevel . Wizard ) {
187
+ if ( firstConnection ?. State === ConnectionState . ServerUpdateNeeded ) {
188
+ setErrorState ( firstConnection . State ) ;
189
+ } else if ( level === AccessLevel . Wizard ) {
198
190
handleWizard ( firstConnection )
199
191
. catch ( err => {
200
192
console . error ( '[ConnectionRequired] could not validate wizard status' , err ) ;
@@ -217,6 +209,10 @@ const ConnectionRequired: FunctionComponent<ConnectionRequiredProps> = ({
217
209
} ) ;
218
210
} , [ handleIncompleteWizard , handleWizard , level , validateUserAccess ] ) ;
219
211
212
+ if ( errorState ) {
213
+ return < ConnectionErrorPage state = { errorState } /> ;
214
+ }
215
+
220
216
if ( isLoading ) {
221
217
return < Loading /> ;
222
218
}
0 commit comments