1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Merge pull request #4083 from thornbill/connection-state-refactor

Refactor ConnectionState to a shared enum
This commit is contained in:
Bill Thornton 2022-10-31 10:12:09 -04:00 committed by GitHub
commit feb35ede21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 25 deletions

View file

@ -1,11 +1,13 @@
import React, { FunctionComponent, useEffect, useState } from 'react';
import { Outlet, useNavigate } from 'react-router-dom';
import type { ConnectResponse } from 'jellyfin-apiclient';
import alert from './alert';
import { appRouter } from './appRouter';
import Loading from './loading/LoadingComponent';
import ServerConnections from './ServerConnections';
import globalize from '../scripts/globalize';
import { ConnectionState } from '../utils/jellyfin-apiclient/ConnectionState';
enum BounceRoutes {
Home = '/home.html',
@ -14,14 +16,6 @@ enum BounceRoutes {
StartWizard = '/wizardstart.html'
}
// TODO: This should probably be in the SDK
enum ConnectionState {
SignedIn = 'SignedIn',
ServerSignIn = 'ServerSignIn',
ServerSelection = 'ServerSelection',
ServerUpdateNeeded = 'ServerUpdateNeeded'
}
type ConnectionRequiredProps = {
isAdminRequired?: boolean,
isUserRequired?: boolean
@ -42,7 +36,7 @@ const ConnectionRequired: FunctionComponent<ConnectionRequiredProps> = ({
useEffect(() => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const bounce = async (connectionResponse: any) => {
const bounce = async (connectionResponse: ConnectResponse) => {
switch (connectionResponse.State) {
case ConnectionState.SignedIn:
// Already logged in, bounce to the home page

View file

@ -9,6 +9,7 @@ import loading from './loading/loading';
import viewManager from './viewManager/viewManager';
import ServerConnections from './ServerConnections';
import alert from './alert';
import { ConnectionState } from '../utils/jellyfin-apiclient/ConnectionState.ts';
export const history = createHashHistory();
@ -201,17 +202,17 @@ class AppRouter {
#handleConnectionResult(result) {
switch (result.State) {
case 'SignedIn':
case ConnectionState.SignedIn:
loading.hide();
this.goHome();
break;
case 'ServerSignIn':
case ConnectionState.ServerSignIn:
this.showLocalLogin(result.ApiClient.serverId());
break;
case 'ServerSelection':
case ConnectionState.ServerSelection:
this.showSelectServer();
break;
case 'ServerUpdateNeeded':
case ConnectionState.ServerUpdateNeeded:
alert({
text: globalize.translate('ServerUpdateNeeded', 'https://github.com/jellyfin/jellyfin'),
html: globalize.translate('ServerUpdateNeeded', '<a href="https://github.com/jellyfin/jellyfin">https://github.com/jellyfin/jellyfin</a>')
@ -365,7 +366,7 @@ class AppRouter {
this.firstConnectionResult = null;
if (firstResult) {
if (firstResult.State === 'ServerSignIn') {
if (firstResult.State === ConnectionState.ServerSignIn) {
const url = firstResult.ApiClient.serverAddress() + '/System/Info/Public';
fetch(url).then(response => {
if (!response.ok) return Promise.reject('fetch failed');
@ -382,7 +383,7 @@ class AppRouter {
});
return;
} else if (firstResult.State !== 'SignedIn') {
} else if (firstResult.State !== ConnectionState.SignedIn) {
this.#handleConnectionResult(firstResult);
return;
}