feat(suggestions): add track preview and clean up UI
- Add preview (play) button to suggested tracks
- Remove pagination info for cleaner UX ("Showing X of Y")
- Remove "Load more" links (auto-loads when cycling)
- Add onPreviewTrack callback to play suggested tracks
- Convert SuggestedTrack to DisplayTrack for playback
This commit is contained in:
1 parent
fab1ff3003
commit
b4fe6c87b5
2 files changed
+64
-55
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { invoke } from '@tauri-apps/api/core';
|
import { invoke } from '@tauri-apps/api/core';
|
||||||
import { RefreshCw, Plus, X, Info, Sparkles } from 'lucide-svelte';
|
import { RefreshCw, Plus, X, Info, Sparkles, Play } from 'lucide-svelte';
|
||||||
import {
|
import {
|
||||||
type SuggestedTrack,
|
type SuggestedTrack,
|
||||||
type SuggestionResult,
|
type SuggestionResult,
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
onAddTrack?: (trackId: number) => Promise<void>;
|
onAddTrack?: (trackId: number) => Promise<void>;
|
||||||
onGoToAlbum?: (albumId: string) => void;
|
onGoToAlbum?: (albumId: string) => void;
|
||||||
onGoToArtist?: (artistId: number) => void;
|
onGoToArtist?: (artistId: number) => void;
|
||||||
|
onPreviewTrack?: (track: SuggestedTrack) => void;
|
||||||
showReasons?: boolean;
|
showReasons?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,6 +30,7 @@
|
|||||||
onAddTrack,
|
onAddTrack,
|
||||||
onGoToAlbum,
|
onGoToAlbum,
|
||||||
onGoToArtist,
|
onGoToArtist,
|
||||||
|
onPreviewTrack,
|
||||||
showReasons = false
|
showReasons = false
|
||||||
}: Props = $props();
|
}: Props = $props();
|
||||||
|
|
||||||
@@ -342,15 +344,23 @@
|
|||||||
{formatDuration(track.duration)}
|
{formatDuration(track.duration)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="actions">
|
||||||
|
{#if onPreviewTrack}
|
||||||
<button
|
<button
|
||||||
class="info-btn"
|
class="action-btn preview"
|
||||||
|
onclick={(e) => { e.stopPropagation(); onPreviewTrack(track); }}
|
||||||
|
title="Preview"
|
||||||
|
>
|
||||||
|
<Play size={14} />
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
<button
|
||||||
|
class="action-btn info"
|
||||||
onclick={(e) => { e.stopPropagation(); handleShowTrackInfo(track.track_id); }}
|
onclick={(e) => { e.stopPropagation(); handleShowTrackInfo(track.track_id); }}
|
||||||
title={showReasons && track.reason ? track.reason : 'Track info'}
|
title={showReasons && track.reason ? track.reason : 'Track info'}
|
||||||
>
|
>
|
||||||
<Info size={14} />
|
<Info size={14} />
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<div class="actions">
|
|
||||||
<button
|
<button
|
||||||
class="action-btn add"
|
class="action-btn add"
|
||||||
onclick={() => handleAddTrack(track)}
|
onclick={() => handleAddTrack(track)}
|
||||||
@@ -370,18 +380,10 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if filteredPool.length > VISIBLE_COUNT || canLoadMore || canLoadMoreVariety}
|
<!-- Pagination hidden for cleaner UX - auto-loads more when cycling -->
|
||||||
<div class="pagination-info">
|
|
||||||
{#if loadingMore}
|
{#if loadingMore}
|
||||||
Loading more...
|
<div class="loading-more">
|
||||||
{:else}
|
<div class="spinner-small"></div>
|
||||||
Showing {currentPage * VISIBLE_COUNT + 1}-{Math.min((currentPage + 1) * VISIBLE_COUNT, filteredPool.length)} of {filteredPool.length}
|
|
||||||
{#if canLoadMore}
|
|
||||||
<button class="load-more-link" onclick={handleLoadMore}>Load more</button>
|
|
||||||
{:else if showVarietyPrompt}
|
|
||||||
<button class="load-more-link" onclick={handleLoadMoreVariety}>Load more variety</button>
|
|
||||||
{/if}
|
|
||||||
{/if}
|
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
@@ -563,31 +565,6 @@
|
|||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.info-btn {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
width: 28px;
|
|
||||||
height: 28px;
|
|
||||||
background: transparent;
|
|
||||||
border: none;
|
|
||||||
color: var(--text-muted);
|
|
||||||
cursor: pointer;
|
|
||||||
border-radius: 4px;
|
|
||||||
opacity: 0;
|
|
||||||
transition: opacity 150ms ease, background-color 150ms ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.suggestion-row:hover .info-btn {
|
|
||||||
opacity: 0.6;
|
|
||||||
}
|
|
||||||
|
|
||||||
.info-btn:hover {
|
|
||||||
opacity: 1 !important;
|
|
||||||
background: var(--bg-tertiary);
|
|
||||||
color: var(--text-primary);
|
|
||||||
}
|
|
||||||
|
|
||||||
.meta-link {
|
.meta-link {
|
||||||
background: none;
|
background: none;
|
||||||
border: none;
|
border: none;
|
||||||
@@ -646,26 +623,36 @@
|
|||||||
color: var(--text-primary);
|
color: var(--text-primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.pagination-info {
|
.action-btn.preview {
|
||||||
margin-top: 12px;
|
|
||||||
text-align: center;
|
|
||||||
font-size: 12px;
|
|
||||||
color: var(--text-muted);
|
color: var(--text-muted);
|
||||||
}
|
}
|
||||||
|
|
||||||
.load-more-link {
|
.action-btn.preview:hover {
|
||||||
background: none;
|
background: var(--accent-primary);
|
||||||
border: none;
|
color: white;
|
||||||
color: var(--accent-primary);
|
|
||||||
cursor: pointer;
|
|
||||||
font-size: 12px;
|
|
||||||
margin-left: 8px;
|
|
||||||
padding: 0;
|
|
||||||
text-decoration: underline;
|
|
||||||
text-underline-offset: 2px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.load-more-link:hover {
|
.action-btn.info {
|
||||||
|
color: var(--text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-btn.info:hover {
|
||||||
|
background: var(--bg-tertiary);
|
||||||
color: var(--text-primary);
|
color: var(--text-primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.loading-more {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 12px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spinner-small {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
border: 2px solid var(--bg-tertiary);
|
||||||
|
border-top-color: var(--accent-primary);
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: spin 1s linear infinite;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -1203,6 +1203,27 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Preview a suggested track
|
||||||
|
function handlePreviewSuggestedTrack(track: import('$lib/services/playlistSuggestionsService').SuggestedTrack) {
|
||||||
|
if (!onTrackPlay) return;
|
||||||
|
|
||||||
|
// Convert SuggestedTrack to DisplayTrack format
|
||||||
|
const displayTrack: DisplayTrack = {
|
||||||
|
id: track.track_id,
|
||||||
|
number: 0,
|
||||||
|
title: track.title,
|
||||||
|
artist: track.artist_name,
|
||||||
|
album: track.album_title,
|
||||||
|
albumArt: track.album_image_url,
|
||||||
|
albumId: track.album_id,
|
||||||
|
artistId: track.artist_id,
|
||||||
|
duration: formatDuration(track.duration),
|
||||||
|
durationSeconds: track.duration
|
||||||
|
};
|
||||||
|
|
||||||
|
onTrackPlay(displayTrack);
|
||||||
|
}
|
||||||
|
|
||||||
async function handlePlayAll() {
|
async function handlePlayAll() {
|
||||||
// Get all display tracks (Qobuz + local, respecting search/sort)
|
// Get all display tracks (Qobuz + local, respecting search/sort)
|
||||||
const allTracks = displayTracks;
|
const allTracks = displayTracks;
|
||||||
@@ -1684,6 +1705,7 @@
|
|||||||
onAddTrack={handleAddSuggestedTrack}
|
onAddTrack={handleAddSuggestedTrack}
|
||||||
onGoToAlbum={onTrackGoToAlbum}
|
onGoToAlbum={onTrackGoToAlbum}
|
||||||
onGoToArtist={onTrackGoToArtist}
|
onGoToArtist={onTrackGoToArtist}
|
||||||
|
onPreviewTrack={handlePreviewSuggestedTrack}
|
||||||
showReasons={false}
|
showReasons={false}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
Reference in new issue
Block a user