mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Fix complexity warnings in ConnectionRequired
This commit is contained in:
parent
a6c8c63d2e
commit
6fc90c1740
1 changed files with 101 additions and 98 deletions
|
@ -1,4 +1,4 @@
|
||||||
import React, { FunctionComponent, useEffect, useState } from 'react';
|
import React, { FunctionComponent, useCallback, useEffect, useState } from 'react';
|
||||||
import { Outlet, useLocation, useNavigate } from 'react-router-dom';
|
import { Outlet, useLocation, useNavigate } from 'react-router-dom';
|
||||||
import type { ConnectResponse } from 'jellyfin-apiclient';
|
import type { ConnectResponse } from 'jellyfin-apiclient';
|
||||||
|
|
||||||
|
@ -35,8 +35,7 @@ const ConnectionRequired: FunctionComponent<ConnectionRequiredProps> = ({
|
||||||
|
|
||||||
const [ isLoading, setIsLoading ] = useState(true);
|
const [ isLoading, setIsLoading ] = useState(true);
|
||||||
|
|
||||||
useEffect(() => {
|
const bounce = useCallback(async (connectionResponse: ConnectResponse) => {
|
||||||
const bounce = async (connectionResponse: ConnectResponse) => {
|
|
||||||
switch (connectionResponse.State) {
|
switch (connectionResponse.State) {
|
||||||
case ConnectionState.SignedIn:
|
case ConnectionState.SignedIn:
|
||||||
// Already logged in, bounce to the home page
|
// Already logged in, bounce to the home page
|
||||||
|
@ -73,14 +72,9 @@ const ConnectionRequired: FunctionComponent<ConnectionRequiredProps> = ({
|
||||||
}
|
}
|
||||||
|
|
||||||
console.warn('[ConnectionRequired] unhandled connection state', connectionResponse.State);
|
console.warn('[ConnectionRequired] unhandled connection state', connectionResponse.State);
|
||||||
};
|
}, [location.pathname, navigate]);
|
||||||
|
|
||||||
const validateConnection = async () => {
|
const handleIncompleteWizard = useCallback(async (firstConnection: ConnectResponse) => {
|
||||||
// Check connection status on initial page load
|
|
||||||
const firstConnection = appRouter.firstConnectionResult;
|
|
||||||
appRouter.firstConnectionResult = null;
|
|
||||||
|
|
||||||
if (firstConnection && firstConnection.State !== ConnectionState.SignedIn) {
|
|
||||||
if (firstConnection.State === ConnectionState.ServerSignIn) {
|
if (firstConnection.State === ConnectionState.ServerSignIn) {
|
||||||
// Verify the wizard is complete
|
// Verify the wizard is complete
|
||||||
try {
|
try {
|
||||||
|
@ -106,12 +100,9 @@ const ConnectionRequired: FunctionComponent<ConnectionRequiredProps> = ({
|
||||||
|
|
||||||
// Bounce to the correct page in the login flow
|
// Bounce to the correct page in the login flow
|
||||||
bounce(firstConnection);
|
bounce(firstConnection);
|
||||||
return;
|
}, [bounce, navigate]);
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: appRouter will call appHost.exit() if navigating back when you are already at the default route.
|
|
||||||
// This case will need to be handled elsewhere before appRouter can be killed.
|
|
||||||
|
|
||||||
|
const validateUserAccess = useCallback(async () => {
|
||||||
const client = ServerConnections.currentApiClient();
|
const client = ServerConnections.currentApiClient();
|
||||||
|
|
||||||
// If this is a user route, ensure a user is logged in
|
// If this is a user route, ensure a user is logged in
|
||||||
|
@ -141,10 +132,22 @@ const ConnectionRequired: FunctionComponent<ConnectionRequiredProps> = ({
|
||||||
}
|
}
|
||||||
|
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
};
|
}, [bounce, isAdminRequired, isUserRequired]);
|
||||||
|
|
||||||
validateConnection();
|
useEffect(() => {
|
||||||
}, [ isAdminRequired, isUserRequired, location.pathname, navigate ]);
|
// TODO: appRouter will call appHost.exit() if navigating back when you are already at the default route.
|
||||||
|
// This case will need to be handled elsewhere before appRouter can be killed.
|
||||||
|
|
||||||
|
// Check connection status on initial page load
|
||||||
|
const firstConnection = appRouter.firstConnectionResult;
|
||||||
|
appRouter.firstConnectionResult = null;
|
||||||
|
|
||||||
|
if (firstConnection && firstConnection.State !== ConnectionState.SignedIn) {
|
||||||
|
handleIncompleteWizard(firstConnection);
|
||||||
|
} else {
|
||||||
|
validateUserAccess();
|
||||||
|
}
|
||||||
|
}, [handleIncompleteWizard, validateUserAccess]);
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return <Loading />;
|
return <Loading />;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue