fix(setup): plex library setting validation (#1233)

* fix(setup): plex library setting validation

* fix(setup): fixes plex continue button and scroll-to-top when clicked issue in setup
This commit is contained in:
Fallenbagel
2025-01-10 07:05:13 +08:00
committed by GitHub
parent 24c6208a3c
commit b8dbfaaed0
2 changed files with 41 additions and 46 deletions

View File

@@ -350,6 +350,10 @@ const SettingsPlex = ({ onComplete }: SettingsPlexProps) => {
); );
if (!res.ok) throw new Error(); if (!res.ok) throw new Error();
} }
if (onComplete) {
onComplete();
}
setIsSyncing(false); setIsSyncing(false);
revalidate(); revalidate();
}; };
@@ -435,10 +439,6 @@ const SettingsPlex = ({ onComplete }: SettingsPlexProps) => {
autoDismiss: true, autoDismiss: true,
appearance: 'success', appearance: 'success',
}); });
if (onComplete) {
onComplete();
}
} catch (e) { } catch (e) {
if (toastId) { if (toastId) {
removeToast(toastId); removeToast(toastId);

View File

@@ -97,18 +97,36 @@ const Setup = () => {
settings.currentSettings.mediaServerType !== settings.currentSettings.mediaServerType !==
MediaServerType.NOT_CONFIGURED MediaServerType.NOT_CONFIGURED
) { ) {
setCurrentStep(3);
setMediaServerType(settings.currentSettings.mediaServerType); setMediaServerType(settings.currentSettings.mediaServerType);
if (currentStep < 3) {
setCurrentStep(3);
}
} }
if (currentStep === 3) { if (currentStep === 3) {
validateLibraries();
}
}, [
settings.currentSettings.mediaServerType,
settings.currentSettings.initialized,
router,
toasts,
intl,
currentStep,
mediaServerType,
]);
const validateLibraries = async () => { const validateLibraries = async () => {
try { try {
const endpoint = const endpointMap: Record<MediaServerType, string> = {
settings.currentSettings.mediaServerType === [MediaServerType.JELLYFIN]: '/api/v1/settings/jellyfin',
MediaServerType.JELLYFIN || MediaServerType.EMBY [MediaServerType.EMBY]: '/api/v1/settings/jellyfin',
? '/api/v1/settings/jellyfin' [MediaServerType.PLEX]: '/api/v1/settings/plex',
: '/api/v1/settings/plex'; [MediaServerType.NOT_CONFIGURED]: '',
};
const endpoint = endpointMap[mediaServerType];
if (!endpoint) return;
const res = await fetch(endpoint); const res = await fetch(endpoint);
if (!res.ok) throw new Error('Fetch failed'); if (!res.ok) throw new Error('Fetch failed');
@@ -119,11 +137,6 @@ const Setup = () => {
); );
setMediaServerSettingsComplete(hasEnabledLibraries); setMediaServerSettingsComplete(hasEnabledLibraries);
if (hasEnabledLibraries) {
localStorage.setItem('mediaServerSettingsComplete', 'true');
} else {
localStorage.removeItem('mediaServerSettingsComplete');
}
} catch (e) { } catch (e) {
toasts.addToast(intl.formatMessage(messages.librarieserror), { toasts.addToast(intl.formatMessage(messages.librarieserror), {
autoDismiss: true, autoDismiss: true,
@@ -131,29 +144,11 @@ const Setup = () => {
}); });
setMediaServerSettingsComplete(false); 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.initialized,
router,
currentStep,
toasts,
intl,
]);
const handleComplete = () => { const handleComplete = () => {
setMediaServerSettingsComplete(true); validateLibraries();
localStorage.setItem('mediaServerSettingsComplete', 'true');
}; };
if (settings.currentSettings.initialized) return <></>; if (settings.currentSettings.initialized) return <></>;