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() {
|
export default function RekordboxReader() {
|
||||||
const { playlists, setPlaylists, loading: xmlLoading } = useXmlParser();
|
const { playlists, setPlaylists, loading: xmlLoading } = useXmlParser();
|
||||||
const [selectedSong, setSelectedSong] = useState<Song | null>(null);
|
const [selectedSong, setSelectedSong] = useState<Song | null>(null);
|
||||||
|
const [isDatabaseInitialized, setIsDatabaseInitialized] = useState(false);
|
||||||
|
|
||||||
// Memoized song selection handler to prevent unnecessary re-renders
|
// Memoized song selection handler to prevent unnecessary re-renders
|
||||||
const handleSongSelect = useCallback((song: Song) => {
|
const handleSongSelect = useCallback((song: Song) => {
|
||||||
@ -81,6 +82,25 @@ export default function RekordboxReader() {
|
|||||||
if (!durationSeconds) return "";
|
if (!durationSeconds) return "";
|
||||||
return formatTotalDuration(durationSeconds);
|
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 navigate = useNavigate();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
@ -359,7 +379,7 @@ export default function RekordboxReader() {
|
|||||||
userSelect={isResizing ? 'none' : 'auto'}
|
userSelect={isResizing ? 'none' : 'auto'}
|
||||||
>
|
>
|
||||||
{/* Welcome Modal */}
|
{/* Welcome Modal */}
|
||||||
{!xmlLoading && songs.length === 0 && (
|
{!xmlLoading && !isDatabaseInitialized && (
|
||||||
<Modal isOpen={isWelcomeOpen} onClose={onWelcomeClose} isCentered>
|
<Modal isOpen={isWelcomeOpen} onClose={onWelcomeClose} isCentered>
|
||||||
<ModalOverlay />
|
<ModalOverlay />
|
||||||
<ModalContent bg="gray.800" maxW="md">
|
<ModalContent bg="gray.800" maxW="md">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user