fix: Restore playlist switching functionality - Add previousPlaylistRef to properly detect playlist changes - Fix playlist change detection logic that was broken by ref updates - Ensure playlist switching works while maintaining infinite scroll fix
This commit is contained in:
parent
08de2afa0e
commit
e8bb2a4326
@ -24,6 +24,7 @@ export const usePaginatedSongs = (options: UsePaginatedSongsOptions = {}) => {
|
|||||||
const loadingRef = useRef(false);
|
const loadingRef = useRef(false);
|
||||||
const currentPlaylistRef = useRef(playlistName);
|
const currentPlaylistRef = useRef(playlistName);
|
||||||
const currentSearchQueryRef = useRef(searchQuery);
|
const currentSearchQueryRef = useRef(searchQuery);
|
||||||
|
const previousPlaylistRef = useRef(playlistName);
|
||||||
const abortControllerRef = useRef<AbortController | null>(null);
|
const abortControllerRef = useRef<AbortController | null>(null);
|
||||||
|
|
||||||
// Cleanup function to prevent memory leaks
|
// Cleanup function to prevent memory leaks
|
||||||
@ -134,20 +135,14 @@ export const usePaginatedSongs = (options: UsePaginatedSongsOptions = {}) => {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Update refs when values change
|
|
||||||
useEffect(() => {
|
|
||||||
currentPlaylistRef.current = playlistName;
|
|
||||||
}, [playlistName]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
currentSearchQueryRef.current = searchQuery;
|
|
||||||
}, [searchQuery]);
|
|
||||||
|
|
||||||
// Handle playlist changes
|
// Handle playlist changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (currentPlaylistRef.current !== playlistName) {
|
if (!isInitialLoad && previousPlaylistRef.current !== playlistName) {
|
||||||
|
// Update refs
|
||||||
currentPlaylistRef.current = playlistName;
|
currentPlaylistRef.current = playlistName;
|
||||||
if (!isInitialLoad) {
|
currentSearchQueryRef.current = searchQuery;
|
||||||
|
previousPlaylistRef.current = playlistName;
|
||||||
|
|
||||||
// Clear songs for new playlist to replace them
|
// Clear songs for new playlist to replace them
|
||||||
setSongs([]);
|
setSongs([]);
|
||||||
setHasMore(true);
|
setHasMore(true);
|
||||||
@ -159,7 +154,6 @@ export const usePaginatedSongs = (options: UsePaginatedSongsOptions = {}) => {
|
|||||||
loadPage(1, initialSearch, playlistName);
|
loadPage(1, initialSearch, playlistName);
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}, [playlistName, isInitialLoad, initialSearch, loadPage]);
|
}, [playlistName, isInitialLoad, initialSearch, loadPage]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user