fix: plex Login

This commit is contained in:
notfakie
2022-04-27 08:06:44 +12:00
parent 9fbc4074e4
commit 9d54776a2c
2 changed files with 12 additions and 15 deletions

View File

@@ -15,12 +15,12 @@ const messages = defineMessages({
});
interface LoginWithMediaServerProps {
onComplete: () => void;
onComplete: (onComplete: MediaServerType) => void;
}
const SetupLogin: React.FC<LoginWithMediaServerProps> = ({ onComplete }) => {
const [authToken, setAuthToken] = useState<string | undefined>(undefined);
const [mediaServerType, setMediaServerType] = useState<number>(
const [mediaServerType, setMediaServerType] = useState<MediaServerType>(
MediaServerType.NOT_CONFIGURED
);
const { user, revalidate } = useUser();
@@ -46,9 +46,9 @@ const SetupLogin: React.FC<LoginWithMediaServerProps> = ({ onComplete }) => {
useEffect(() => {
if (user) {
onComplete();
onComplete(mediaServerType);
}
}, [user, onComplete]);
}, [user, mediaServerType, onComplete]);
return (
<div>

View File

@@ -3,6 +3,7 @@ import { useRouter } from 'next/router';
import React, { useState } from 'react';
import { defineMessages, useIntl } from 'react-intl';
import useSWR, { mutate } from 'swr';
import { MediaServerType } from '../../../server/constants/server';
import useLocale from '../../hooks/useLocale';
import AppDataWarning from '../AppDataWarning';
import Badge from '../Common/Badge';
@@ -35,7 +36,9 @@ const Setup: React.FC = () => {
const [currentStep, setCurrentStep] = useState(1);
const [mediaServerSettingsComplete, setMediaServerSettingsComplete] =
useState(false);
const [mediaServerType, setMediaServerType] = useState('');
const [mediaServerType, setMediaServerType] = useState(
MediaServerType.NOT_CONFIGURED
);
const router = useRouter();
const { locale } = useLocale();
@@ -54,11 +57,6 @@ const Setup: React.FC = () => {
}
};
const getMediaServerType = async () => {
const MainSettings = await axios.get('/api/v1/settings/main');
setMediaServerType(MainSettings.data.mediaServerType);
return;
};
const { data: backdrops } = useSWR<string[]>('/api/v1/backdrops', {
refreshInterval: 0,
refreshWhenHidden: false,
@@ -113,16 +111,15 @@ const Setup: React.FC = () => {
<div className="mt-10 w-full rounded-md border border-gray-600 bg-gray-800 bg-opacity-50 p-4 text-white">
{currentStep === 1 && (
<SetupLogin
onComplete={() => {
getMediaServerType().then(() => {
onComplete={(mServerType) => {
setMediaServerType(mServerType);
setCurrentStep(2);
});
}}
/>
)}
{currentStep === 2 && (
<div>
{mediaServerType == 'PLEX' ? (
{mediaServerType === MediaServerType.PLEX ? (
<SettingsPlex
onComplete={() => setMediaServerSettingsComplete(true)}
/>