fix(setup): fix continue button disabled on refresh in setup 3 (#1211)
This commit resolves an issue where the continue button in setup step 3 remained disabled after a page refresh even when libraries are toggled. This was happening because `mediaServerSettingsComplete` state was reset on refresh and not correctly re-initialized.
This commit is contained in:
@@ -14,10 +14,12 @@ import useLocale from '@app/hooks/useLocale';
|
|||||||
import useSettings from '@app/hooks/useSettings';
|
import useSettings from '@app/hooks/useSettings';
|
||||||
import defineMessages from '@app/utils/defineMessages';
|
import defineMessages from '@app/utils/defineMessages';
|
||||||
import { MediaServerType } from '@server/constants/server';
|
import { MediaServerType } from '@server/constants/server';
|
||||||
|
import type { Library } from '@server/lib/settings';
|
||||||
import Image from 'next/image';
|
import Image from 'next/image';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
|
import { useToasts } from 'react-toast-notifications';
|
||||||
import useSWR, { mutate } from 'swr';
|
import useSWR, { mutate } from 'swr';
|
||||||
import SetupLogin from './SetupLogin';
|
import SetupLogin from './SetupLogin';
|
||||||
|
|
||||||
@@ -35,6 +37,8 @@ const messages = defineMessages('components.Setup', {
|
|||||||
signin: 'Sign In',
|
signin: 'Sign In',
|
||||||
configuremediaserver: 'Configure Media Server',
|
configuremediaserver: 'Configure Media Server',
|
||||||
configureservices: 'Configure Services',
|
configureservices: 'Configure Services',
|
||||||
|
librarieserror:
|
||||||
|
'Validation failed. Please toggle the libraries again to continue.',
|
||||||
});
|
});
|
||||||
|
|
||||||
const Setup = () => {
|
const Setup = () => {
|
||||||
@@ -49,6 +53,7 @@ const Setup = () => {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { locale } = useLocale();
|
const { locale } = useLocale();
|
||||||
const settings = useSettings();
|
const settings = useSettings();
|
||||||
|
const toasts = useToasts();
|
||||||
|
|
||||||
const finishSetup = async () => {
|
const finishSetup = async () => {
|
||||||
setIsUpdating(true);
|
setIsUpdating(true);
|
||||||
@@ -87,6 +92,7 @@ const Setup = () => {
|
|||||||
if (settings.currentSettings.initialized) {
|
if (settings.currentSettings.initialized) {
|
||||||
router.push('/');
|
router.push('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
settings.currentSettings.mediaServerType !==
|
settings.currentSettings.mediaServerType !==
|
||||||
MediaServerType.NOT_CONFIGURED
|
MediaServerType.NOT_CONFIGURED
|
||||||
@@ -94,12 +100,62 @@ const Setup = () => {
|
|||||||
setCurrentStep(3);
|
setCurrentStep(3);
|
||||||
setMediaServerType(settings.currentSettings.mediaServerType);
|
setMediaServerType(settings.currentSettings.mediaServerType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (currentStep === 3) {
|
||||||
|
const validateLibraries = async () => {
|
||||||
|
try {
|
||||||
|
const endpoint =
|
||||||
|
settings.currentSettings.mediaServerType ===
|
||||||
|
MediaServerType.JELLYFIN || MediaServerType.EMBY
|
||||||
|
? '/api/v1/settings/jellyfin'
|
||||||
|
: '/api/v1/settings/plex';
|
||||||
|
|
||||||
|
const res = await fetch(endpoint);
|
||||||
|
if (!res.ok) throw new Error('Fetch failed');
|
||||||
|
const data = await res.json();
|
||||||
|
|
||||||
|
const hasEnabledLibraries = data?.libraries?.some(
|
||||||
|
(library: Library) => library.enabled
|
||||||
|
);
|
||||||
|
|
||||||
|
setMediaServerSettingsComplete(hasEnabledLibraries);
|
||||||
|
if (hasEnabledLibraries) {
|
||||||
|
localStorage.setItem('mediaServerSettingsComplete', 'true');
|
||||||
|
} else {
|
||||||
|
localStorage.removeItem('mediaServerSettingsComplete');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
toasts.addToast(intl.formatMessage(messages.librarieserror), {
|
||||||
|
autoDismiss: true,
|
||||||
|
appearance: 'error',
|
||||||
|
});
|
||||||
|
|
||||||
|
setMediaServerSettingsComplete(false);
|
||||||
|
localStorage.removeItem('mediaServerSettingsComplete');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
validateLibraries();
|
||||||
|
} else {
|
||||||
|
// Initialize from localStorage on mount
|
||||||
|
const storedState =
|
||||||
|
localStorage.getItem('mediaServerSettingsComplete') === 'true';
|
||||||
|
setMediaServerSettingsComplete(storedState);
|
||||||
|
}
|
||||||
}, [
|
}, [
|
||||||
settings.currentSettings.mediaServerType,
|
settings.currentSettings.mediaServerType,
|
||||||
settings.currentSettings.initialized,
|
settings.currentSettings.initialized,
|
||||||
router,
|
router,
|
||||||
|
currentStep,
|
||||||
|
toasts,
|
||||||
|
intl,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const handleComplete = () => {
|
||||||
|
setMediaServerSettingsComplete(true);
|
||||||
|
localStorage.setItem('mediaServerSettingsComplete', 'true');
|
||||||
|
};
|
||||||
|
|
||||||
if (settings.currentSettings.initialized) return <></>;
|
if (settings.currentSettings.initialized) return <></>;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -225,14 +281,9 @@ const Setup = () => {
|
|||||||
{currentStep === 3 && (
|
{currentStep === 3 && (
|
||||||
<div className="p-2">
|
<div className="p-2">
|
||||||
{mediaServerType === MediaServerType.PLEX ? (
|
{mediaServerType === MediaServerType.PLEX ? (
|
||||||
<SettingsPlex
|
<SettingsPlex onComplete={handleComplete} />
|
||||||
onComplete={() => setMediaServerSettingsComplete(true)}
|
|
||||||
/>
|
|
||||||
) : (
|
) : (
|
||||||
<SettingsJellyfin
|
<SettingsJellyfin isSetupSettings onComplete={handleComplete} />
|
||||||
isSetupSettings
|
|
||||||
onComplete={() => setMediaServerSettingsComplete(true)}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
<div className="actions">
|
<div className="actions">
|
||||||
<div className="flex justify-end">
|
<div className="flex justify-end">
|
||||||
|
|||||||
@@ -1137,6 +1137,7 @@
|
|||||||
"components.Setup.continue": "Continue",
|
"components.Setup.continue": "Continue",
|
||||||
"components.Setup.finish": "Finish Setup",
|
"components.Setup.finish": "Finish Setup",
|
||||||
"components.Setup.finishing": "Finishing…",
|
"components.Setup.finishing": "Finishing…",
|
||||||
|
"components.Setup.librarieserror": "Validation failed. Please toggle the libraries again to continue.",
|
||||||
"components.Setup.servertype": "Choose Server Type",
|
"components.Setup.servertype": "Choose Server Type",
|
||||||
"components.Setup.setup": "Setup",
|
"components.Setup.setup": "Setup",
|
||||||
"components.Setup.signin": "Sign In",
|
"components.Setup.signin": "Sign In",
|
||||||
|
|||||||
Reference in New Issue
Block a user