fix(suggestions): fix config deserialization and effect loop
- Add #[serde(default)] to SuggestionConfig to allow partial config from frontend (fixes "missing field max_artists" error) - Fix effect loop in PlaylistSuggestions.svelte: - Add loadingInitiated flag to prevent re-triggering - Add cleanup effect when playlistId changes - Prevent concurrent loading attempts
This commit is contained in:
1 parent
1560cd4e3d
commit
541c93f06d
2 files changed
+23
-3
No files matched your search
@@ -54,14 +54,33 @@
|
||||
const canLoadMore = $derived(hasLoadedOnce && pool.length < EXPANDED_POOL && !loadingMore);
|
||||
const isEmpty = $derived(filteredPool.length === 0 && !loading && hasLoadedOnce);
|
||||
|
||||
// Load suggestions when artists change
|
||||
// Track if we've initiated loading for this playlist
|
||||
let loadingInitiated = $state(false);
|
||||
|
||||
// Load suggestions when artists change (only once per playlist)
|
||||
$effect(() => {
|
||||
if (artists.length > 0 && !hasLoadedOnce) {
|
||||
console.log('[Suggestions] Effect triggered, artists:', artists.length);
|
||||
// Read artists.length to track changes
|
||||
const artistCount = artists.length;
|
||||
|
||||
if (artistCount > 0 && !loadingInitiated && !loading) {
|
||||
console.log('[Suggestions] Effect triggered, artists:', artistCount);
|
||||
loadingInitiated = true;
|
||||
void loadSuggestions(false);
|
||||
}
|
||||
});
|
||||
|
||||
// Reset when playlist changes
|
||||
$effect(() => {
|
||||
// Track playlistId changes
|
||||
const currentPlaylistId = playlistId;
|
||||
return () => {
|
||||
// Cleanup when playlist changes
|
||||
loadingInitiated = false;
|
||||
hasLoadedOnce = false;
|
||||
pool = [];
|
||||
};
|
||||
});
|
||||
|
||||
async function loadSuggestions(expanded: boolean) {
|
||||
if (loading) {
|
||||
console.log('[Suggestions] Already loading, skipping');
|
||||
|
||||
Reference in new issue
Block a user