diff --git a/src/lib/components/PlaylistSuggestions.svelte b/src/lib/components/PlaylistSuggestions.svelte index 1ef0dc90d..76fdcd76d 100644 --- a/src/lib/components/PlaylistSuggestions.svelte +++ b/src/lib/components/PlaylistSuggestions.svelte @@ -13,11 +13,14 @@ formatDuration } from '$lib/services/playlistSuggestionsService'; import TrackInfoModal from './TrackInfoModal.svelte'; + import { t } from '$lib/i18n'; interface Props { playlistId: number; artists: PlaylistArtist[]; excludeTrackIds: number[]; + /** Number of tracks in the playlist (used to gate auto-launch) */ + trackCount?: number; /** Existing tracks in playlist for title+artist deduplication */ existingTracks?: Array<{ title: string; artist?: string }>; /** Callback when track is added - receives full track data for local state update */ @@ -32,6 +35,7 @@ playlistId, artists, excludeTrackIds, + trackCount = 0, existingTracks = [], onAddTrack, onGoToAlbum, @@ -40,6 +44,9 @@ showReasons = false }: Props = $props(); + /** Large playlists (>500 tracks) require manual launch */ + const MANUAL_LAUNCH_THRESHOLD = 500; + /** * Normalize a string for comparison (lowercase, trim, remove extra whitespace) */ @@ -151,6 +158,7 @@ const canLoadMoreVariety = $derived(hasLoadedOnce && pool.length >= EXPANDED_POOL && pool.length < MAX_POOL && !loadingMore); const isEmpty = $derived(filteredPool.length === 0 && !loading && hasLoadedOnce); const showVarietyPrompt = $derived(completedCycles >= 1 && canLoadMoreVariety); + const needsManualLaunch = $derived(trackCount > MANUAL_LAUNCH_THRESHOLD && !hasLoadedOnce && !loading); // Track the last playlist we loaded for let lastLoadedPlaylistId = $state(null); @@ -161,20 +169,24 @@ console.log(`[${ts}] [Suggestions]`, ...args); } - // Load suggestions when playlist/artists change + // Load suggestions when playlist/artists change (auto-launch only for small playlists) $effect(() => { const artistCount = artists.length; const currentPlaylistId = playlistId; // Only load if we have artists and haven't loaded for this playlist yet if (artistCount > 0 && currentPlaylistId !== lastLoadedPlaylistId && !loading) { - log('Effect triggered, playlist:', currentPlaylistId, 'artists:', artistCount); + log('Effect triggered, playlist:', currentPlaylistId, 'artists:', artistCount, 'trackCount:', trackCount); lastLoadedPlaylistId = currentPlaylistId; hasLoadedOnce = false; pool = []; completedCycles = 0; lastAddedAt = 0; - void loadSuggestions(false); + + // Large playlists require manual launch + if (trackCount <= MANUAL_LAUNCH_THRESHOLD) { + void loadSuggestions(false); + } } }); @@ -347,25 +359,35 @@ onArtistClick={onGoToArtist} /> -{#if artists.length > 0 && !isEmpty} +{#if artists.length > 0 && (!isEmpty || needsManualLaunch)}

Suggested songs

- + {#if !needsManualLaunch} + + {/if}
- {#if loading && pool.length === 0} + {#if needsManualLaunch} +
+

{$t('playlist.suggestionsLargePlaylist')}

+ +
+ {:else if loading && pool.length === 0}

Finding similar artists...

@@ -800,4 +822,39 @@ border-radius: 50%; animation: spin 0.6s linear infinite; } + + .manual-launch { + display: flex; + flex-direction: column; + align-items: center; + gap: 12px; + padding: 24px 16px; + } + + .manual-launch-hint { + font-size: 13px; + color: var(--text-muted); + text-align: center; + margin: 0; + } + + .manual-launch-btn { + display: flex; + align-items: center; + gap: 8px; + padding: 10px 20px; + background: var(--bg-tertiary); + border: 1px solid var(--alpha-8); + border-radius: 8px; + color: var(--text-primary); + font-size: 13px; + font-weight: 500; + cursor: pointer; + transition: background 150ms ease, border-color 150ms ease; + } + + .manual-launch-btn:hover { + background: var(--alpha-12); + border-color: var(--alpha-20); + } diff --git a/src/lib/components/views/PlaylistDetailView.svelte b/src/lib/components/views/PlaylistDetailView.svelte index 510831701..f8e7c5be8 100644 --- a/src/lib/components/views/PlaylistDetailView.svelte +++ b/src/lib/components/views/PlaylistDetailView.svelte @@ -1914,12 +1914,13 @@ {/if}
- - {#if playlist && !searchQuery && playlistArtists.length > 0 && isOwnPlaylist} + + {#if playlist && !searchQuery && playlistArtists.length > 0 && isOwnPlaylist && (playlist.tracks_count ?? 0) < 2000} !trk.isLocal).map(trk => ({ title: trk.title, artist: trk.artist }))} onAddTrack={handleAddSuggestedTrack} onGoToAlbum={onTrackGoToAlbum} diff --git a/src/lib/i18n/locales/en.json b/src/lib/i18n/locales/en.json index 434d61296..516155bd9 100644 --- a/src/lib/i18n/locales/en.json +++ b/src/lib/i18n/locales/en.json @@ -282,7 +282,9 @@ "addAll": "Add all tracks", "addNew": "Add only new tracks", "adding": "Adding..." - } + }, + "suggestSongs": "Suggest songs for this playlist", + "suggestionsLargePlaylist": "This playlist has many tracks. Tap the button to generate suggestions." }, "sort": { "nameAZ": "Name (A-Z)", diff --git a/src/lib/i18n/locales/es.json b/src/lib/i18n/locales/es.json index 2292ed341..1d791f76c 100644 --- a/src/lib/i18n/locales/es.json +++ b/src/lib/i18n/locales/es.json @@ -282,7 +282,9 @@ "addAll": "Agregar todas", "addNew": "Agregar solo nuevas", "adding": "Agregando..." - } + }, + "suggestSongs": "Sugerir canciones para esta lista", + "suggestionsLargePlaylist": "Esta lista tiene muchas pistas. Presiona el botón para generar sugerencias." }, "sort": { "nameAZ": "Nombre (A-Z)",