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,63 +97,58 @@ 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) {
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(); 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, toasts,
intl, intl,
currentStep,
mediaServerType,
]); ]);
const validateLibraries = async () => {
try {
const endpointMap: Record<MediaServerType, string> = {
[MediaServerType.JELLYFIN]: '/api/v1/settings/jellyfin',
[MediaServerType.EMBY]: '/api/v1/settings/jellyfin',
[MediaServerType.PLEX]: '/api/v1/settings/plex',
[MediaServerType.NOT_CONFIGURED]: '',
};
const endpoint = endpointMap[mediaServerType];
if (!endpoint) return;
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);
} catch (e) {
toasts.addToast(intl.formatMessage(messages.librarieserror), {
autoDismiss: true,
appearance: 'error',
});
setMediaServerSettingsComplete(false);
}
};
const handleComplete = () => { const handleComplete = () => {
setMediaServerSettingsComplete(true); validateLibraries();
localStorage.setItem('mediaServerSettingsComplete', 'true');
}; };
if (settings.currentSettings.initialized) return <></>; if (settings.currentSettings.initialized) return <></>;