Skip to content

Commit 83bb102

Browse files
authored
Merge pull request #6796 from thornbill/update-server-page
Update server update required handling
2 parents d190fdb + 3b1ed1a commit 83bb102

File tree

3 files changed

+65
-23
lines changed

3 files changed

+65
-23
lines changed
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React, { FC, useEffect, useState } from 'react';
2+
3+
import Page from 'components/Page';
4+
import globalize from 'lib/globalize';
5+
import { ConnectionState } from 'lib/jellyfin-apiclient';
6+
7+
interface ConnectionErrorPageProps {
8+
state: ConnectionState
9+
}
10+
11+
const ConnectionErrorPage: FC<ConnectionErrorPageProps> = ({
12+
state
13+
}) => {
14+
const [ title, setTitle ] = useState<string>();
15+
const [ htmlMessage, setHtmlMessage ] = useState<string>();
16+
17+
useEffect(() => {
18+
if (state === ConnectionState.ServerUpdateNeeded) {
19+
setTitle(globalize.translate('HeaderUpdateRequired'));
20+
setHtmlMessage(globalize.translate(
21+
'ServerUpdateNeeded',
22+
'<a href="https://jellyfin.org/downloads/server/">jellyfin.org/downloads/server</a>'
23+
));
24+
}
25+
}, [ state ]);
26+
27+
if (!title) return;
28+
29+
return (
30+
<Page
31+
id='connectionErrorPage'
32+
className='mainAnimatedPage standalonePage'
33+
isBackButtonEnabled={false}
34+
>
35+
<div className='padded-left padded-right'>
36+
<h1>{title}</h1>
37+
{htmlMessage && (
38+
<p dangerouslySetInnerHTML={{ __html: htmlMessage }} />
39+
)}
40+
</div>
41+
</Page>
42+
);
43+
};
44+
45+
export default ConnectionErrorPage;

src/components/ConnectionRequired.tsx

+19-23
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import React, { FunctionComponent, useCallback, useEffect, useState } from 'reac
22
import { Outlet, useLocation, useNavigate } from 'react-router-dom';
33
import type { ApiClient, ConnectResponse } from 'jellyfin-apiclient';
44

5-
import globalize from 'lib/globalize';
65
import { ConnectionState, ServerConnections } from 'lib/jellyfin-apiclient';
76

8-
import alert from './alert';
7+
import ConnectionErrorPage from './ConnectionErrorPage';
98
import Loading from './loading/LoadingComponent';
109

1110
enum AccessLevel {
@@ -56,8 +55,16 @@ const ConnectionRequired: FunctionComponent<ConnectionRequiredProps> = ({
5655
const navigate = useNavigate();
5756
const location = useLocation();
5857

58+
const [ errorState, setErrorState ] = useState<ConnectionState>();
5959
const [ isLoading, setIsLoading ] = useState(true);
6060

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+
6168
const bounce = useCallback(async (connectionResponse: ConnectResponse) => {
6269
switch (connectionResponse.State) {
6370
case ConnectionState.SignedIn:
@@ -77,31 +84,14 @@ const ConnectionRequired: FunctionComponent<ConnectionRequiredProps> = ({
7784
return;
7885
case ConnectionState.ServerSelection:
7986
// 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);
9989
return;
10090
}
10191

10292
console.warn('[ConnectionRequired] unhandled connection state', connectionResponse.State);
10393
// eslint-disable-next-line react-hooks/exhaustive-deps
104-
}, [location.pathname, navigate]);
94+
}, [ navigateIfNotThere, location.pathname, navigate ]);
10595

10696
const handleWizard = useCallback(async (firstConnection: ConnectResponse | null) => {
10797
const apiClient = firstConnection?.ApiClient || ServerConnections.currentApiClient();
@@ -194,7 +184,9 @@ const ConnectionRequired: FunctionComponent<ConnectionRequiredProps> = ({
194184
console.debug('[ConnectionRequired] connection state', firstConnection?.State);
195185
ServerConnections.firstConnection = true;
196186

197-
if (level === AccessLevel.Wizard) {
187+
if (firstConnection?.State === ConnectionState.ServerUpdateNeeded) {
188+
setErrorState(firstConnection.State);
189+
} else if (level === AccessLevel.Wizard) {
198190
handleWizard(firstConnection)
199191
.catch(err => {
200192
console.error('[ConnectionRequired] could not validate wizard status', err);
@@ -217,6 +209,10 @@ const ConnectionRequired: FunctionComponent<ConnectionRequiredProps> = ({
217209
});
218210
}, [handleIncompleteWizard, handleWizard, level, validateUserAccess]);
219211

212+
if (errorState) {
213+
return <ConnectionErrorPage state={errorState} />;
214+
}
215+
220216
if (isLoading) {
221217
return <Loading />;
222218
}

src/strings/en-us.json

+1
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@
538538
"HeaderTypeText": "Enter Text",
539539
"HeaderUninstallPlugin": "Uninstall Plugin",
540540
"HeaderUpcomingOnTV": "Upcoming On TV",
541+
"HeaderUpdateRequired": "Update Required",
541542
"HeaderUploadImage": "Upload Image",
542543
"HeaderUploadLyrics": "Upload Lyrics",
543544
"HeaderUploadSubtitle": "Upload Subtitle",

0 commit comments

Comments
 (0)