fix: Prevent welcome modal from showing during playlist switches - Add isDatabaseInitialized state to track actual database status - Check for songs and playlists to determine if database is initialized - Only show welcome modal when database is truly empty - Fixes issue where modal appeared when switching playlists
This commit is contained in:
parent
02ae12294c
commit
743ed6a54e
@ -70,6 +70,7 @@ const findPlaylistByName = (playlists: PlaylistNode[], name: string): PlaylistNo
|
||||
export default function RekordboxReader() {
|
||||
const { playlists, setPlaylists, loading: xmlLoading } = useXmlParser();
|
||||
const [selectedSong, setSelectedSong] = useState<Song | null>(null);
|
||||
const [isDatabaseInitialized, setIsDatabaseInitialized] = useState(false);
|
||||
|
||||
// Memoized song selection handler to prevent unnecessary re-renders
|
||||
const handleSongSelect = useCallback((song: Song) => {
|
||||
@ -81,6 +82,25 @@ export default function RekordboxReader() {
|
||||
if (!durationSeconds) return "";
|
||||
return formatTotalDuration(durationSeconds);
|
||||
}, []);
|
||||
|
||||
// Check if database is initialized (has songs or playlists)
|
||||
useEffect(() => {
|
||||
const checkDatabaseInitialized = async () => {
|
||||
try {
|
||||
// Check if there are any songs in the database
|
||||
const songCount = await api.getSongCount();
|
||||
const hasPlaylists = playlists.length > 0;
|
||||
setIsDatabaseInitialized(songCount > 0 || hasPlaylists);
|
||||
} catch (error) {
|
||||
// If we can't get the song count, assume database is not initialized
|
||||
setIsDatabaseInitialized(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (!xmlLoading) {
|
||||
checkDatabaseInitialized();
|
||||
}
|
||||
}, [xmlLoading, playlists.length]);
|
||||
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
@ -359,7 +379,7 @@ export default function RekordboxReader() {
|
||||
userSelect={isResizing ? 'none' : 'auto'}
|
||||
>
|
||||
{/* Welcome Modal */}
|
||||
{!xmlLoading && songs.length === 0 && (
|
||||
{!xmlLoading && !isDatabaseInitialized && (
|
||||
<Modal isOpen={isWelcomeOpen} onClose={onWelcomeClose} isCentered>
|
||||
<ModalOverlay />
|
||||
<ModalContent bg="gray.800" maxW="md">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user