Fix: Fix Library selection wont show after server connected
This commit is contained in:
@@ -35,10 +35,12 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
const [selectedLibraryId, setSelectedLibraryId] = useState<string>('');
|
||||
|
||||
const abortControllerRef = useRef<AbortController | null>(null);
|
||||
const prevIsOpenRef = useRef(isOpen);
|
||||
|
||||
// Reset state when opening
|
||||
useEffect(() => {
|
||||
if (isOpen) {
|
||||
// Only execute reset logic when modal opens (isOpen changes from false to true)
|
||||
if (isOpen && !prevIsOpenRef.current) {
|
||||
setError(null);
|
||||
setConnectedServerInfo(null);
|
||||
setLibraries([]);
|
||||
@@ -54,12 +56,15 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
}));
|
||||
}
|
||||
}
|
||||
return () => {
|
||||
// Cleanup any pending request if modal closes
|
||||
|
||||
// Cleanup when closing
|
||||
if (!isOpen && prevIsOpenRef.current) {
|
||||
if (abortControllerRef.current) {
|
||||
abortControllerRef.current.abort();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
prevIsOpenRef.current = isOpen;
|
||||
}, [isOpen, initialSettings]);
|
||||
|
||||
if (!isOpen) return null;
|
||||
@@ -139,10 +144,11 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
onShowMessage(`Successfully connected to ${info.name || 'Plex Server'}`);
|
||||
|
||||
const libs = info.libraries || [];
|
||||
setLibraries(libs);
|
||||
if (libs.length > 0) {
|
||||
const musicLibraries = libs.filter((lib) => lib.type === 'artist').sort((a, b) => a.title.localeCompare(b.title));
|
||||
setLibraries(musicLibraries);
|
||||
if (musicLibraries.length > 0) {
|
||||
const preferred = info.libraryName || formData.libraryName;
|
||||
const defaultLib = libs.find(lib => lib.title === preferred) || libs[0];
|
||||
const defaultLib = musicLibraries.find(lib => lib.title === preferred) || musicLibraries[0];
|
||||
setSelectedLibraryId(defaultLib.id);
|
||||
setFormData(prev => ({ ...prev, libraryName: defaultLib.title }));
|
||||
onConnectSuccess({
|
||||
|
||||
@@ -38,7 +38,7 @@ const mapPlaylist = (item: any): Playlist => ({
|
||||
const mapLibrary = (item: any): PlexLibrary => ({
|
||||
id: item.id ?? item.title,
|
||||
title: item.title ?? item.id,
|
||||
type: item.type ?? 'artist',
|
||||
type: item.type || item.libraryType || item.library_type || item.section?.type || '',
|
||||
});
|
||||
|
||||
// Helper function to map raw rules array to ReplacementRule[]
|
||||
|
||||
Reference in New Issue
Block a user