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
@@ -22,6 +22,7 @@ use super::store::ArtistVectorStore;
|
|||||||
|
|
||||||
/// Configuration for suggestion generation
|
/// Configuration for suggestion generation
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[serde(default)]
|
||||||
pub struct SuggestionConfig {
|
pub struct SuggestionConfig {
|
||||||
/// Maximum number of artists to consider for suggestions
|
/// Maximum number of artists to consider for suggestions
|
||||||
pub max_artists: usize,
|
pub max_artists: usize,
|
||||||
|
|||||||
@@ -54,14 +54,33 @@
|
|||||||
const canLoadMore = $derived(hasLoadedOnce && pool.length < EXPANDED_POOL && !loadingMore);
|
const canLoadMore = $derived(hasLoadedOnce && pool.length < EXPANDED_POOL && !loadingMore);
|
||||||
const isEmpty = $derived(filteredPool.length === 0 && !loading && hasLoadedOnce);
|
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(() => {
|
$effect(() => {
|
||||||
if (artists.length > 0 && !hasLoadedOnce) {
|
// Read artists.length to track changes
|
||||||
console.log('[Suggestions] Effect triggered, artists:', artists.length);
|
const artistCount = artists.length;
|
||||||
|
|
||||||
|
if (artistCount > 0 && !loadingInitiated && !loading) {
|
||||||
|
console.log('[Suggestions] Effect triggered, artists:', artistCount);
|
||||||
|
loadingInitiated = true;
|
||||||
void loadSuggestions(false);
|
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) {
|
async function loadSuggestions(expanded: boolean) {
|
||||||
if (loading) {
|
if (loading) {
|
||||||
console.log('[Suggestions] Already loading, skipping');
|
console.log('[Suggestions] Already loading, skipping');
|
||||||
|
|||||||
Reference in new issue
Block a user