feat: add download UI for offline listening
- DownloadButton component with status indicators - TrackRow now shows download button on hover - downloadState store for managing download states - Tauri event listeners for download progress - Integration with AlbumDetailView
This commit is contained in:
1 parent
45fb498b8b
commit
7149cf5c4b
5 files changed
+443
-2
No files matched your search
@@ -0,0 +1,127 @@
|
||||
<script lang="ts">
|
||||
import { Download, Check, Loader, AlertCircle } from 'lucide-svelte';
|
||||
|
||||
type DownloadStatus = 'none' | 'queued' | 'downloading' | 'ready' | 'failed';
|
||||
|
||||
interface Props {
|
||||
status?: DownloadStatus;
|
||||
progress?: number;
|
||||
size?: number;
|
||||
onDownload?: () => void;
|
||||
onRemove?: () => void;
|
||||
}
|
||||
|
||||
let {
|
||||
status = 'none',
|
||||
progress = 0,
|
||||
size = 16,
|
||||
onDownload,
|
||||
onRemove
|
||||
}: Props = $props();
|
||||
|
||||
function handleClick(e: MouseEvent) {
|
||||
e.stopPropagation();
|
||||
|
||||
if (status === 'none' || status === 'failed') {
|
||||
onDownload?.();
|
||||
} else if (status === 'ready') {
|
||||
onRemove?.();
|
||||
}
|
||||
}
|
||||
|
||||
const title = $derived(() => {
|
||||
switch (status) {
|
||||
case 'none': return 'Download for offline';
|
||||
case 'queued': return 'Queued for download';
|
||||
case 'downloading': return `Downloading ${progress}%`;
|
||||
case 'ready': return 'Downloaded (click to remove)';
|
||||
case 'failed': return 'Download failed (click to retry)';
|
||||
default: return '';
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<button
|
||||
class="download-button"
|
||||
class:downloading={status === 'downloading' || status === 'queued'}
|
||||
class:ready={status === 'ready'}
|
||||
class:failed={status === 'failed'}
|
||||
onclick={handleClick}
|
||||
title={title()}
|
||||
disabled={status === 'queued'}
|
||||
>
|
||||
{#if status === 'ready'}
|
||||
<Check {size} />
|
||||
{:else if status === 'downloading' || status === 'queued'}
|
||||
<div class="progress-ring" style="--progress: {progress}">
|
||||
<Loader {size} class="spinning" />
|
||||
</div>
|
||||
{:else if status === 'failed'}
|
||||
<AlertCircle {size} />
|
||||
{:else}
|
||||
<Download {size} />
|
||||
{/if}
|
||||
</button>
|
||||
|
||||
<style>
|
||||
.download-button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: var(--text-muted);
|
||||
cursor: pointer;
|
||||
border-radius: 4px;
|
||||
transition: all 150ms ease;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.download-button:hover:not(:disabled) {
|
||||
color: var(--text-primary);
|
||||
background: var(--bg-hover);
|
||||
}
|
||||
|
||||
.download-button:disabled {
|
||||
cursor: default;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.download-button.ready {
|
||||
color: var(--success, #22c55e);
|
||||
}
|
||||
|
||||
.download-button.ready:hover {
|
||||
color: var(--error, #ef4444);
|
||||
}
|
||||
|
||||
.download-button.failed {
|
||||
color: var(--error, #ef4444);
|
||||
}
|
||||
|
||||
.download-button.downloading {
|
||||
color: var(--accent-primary);
|
||||
}
|
||||
|
||||
.progress-ring {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.progress-ring :global(.spinning) {
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,6 +1,9 @@
|
||||
<script lang="ts">
|
||||
import { Play, Heart } from 'lucide-svelte';
|
||||
import TrackMenu from './TrackMenu.svelte';
|
||||
import DownloadButton from './DownloadButton.svelte';
|
||||
|
||||
type DownloadStatus = 'none' | 'queued' | 'downloading' | 'ready' | 'failed';
|
||||
|
||||
interface Props {
|
||||
number: number;
|
||||
@@ -10,7 +13,11 @@
|
||||
quality?: string;
|
||||
isPlaying?: boolean;
|
||||
isFavorite?: boolean;
|
||||
downloadStatus?: DownloadStatus;
|
||||
downloadProgress?: number;
|
||||
onPlay?: () => void;
|
||||
onDownload?: () => void;
|
||||
onRemoveDownload?: () => void;
|
||||
menuActions?: TrackMenuActions;
|
||||
}
|
||||
|
||||
@@ -34,7 +41,11 @@
|
||||
quality,
|
||||
isPlaying = false,
|
||||
isFavorite = false,
|
||||
downloadStatus = 'none',
|
||||
downloadProgress = 0,
|
||||
onPlay,
|
||||
onDownload,
|
||||
onRemoveDownload,
|
||||
menuActions
|
||||
}: Props = $props();
|
||||
|
||||
@@ -93,6 +104,17 @@
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Download Indicator -->
|
||||
<div class="download-indicator" class:has-download={downloadStatus !== 'none'}>
|
||||
<DownloadButton
|
||||
status={downloadStatus}
|
||||
progress={downloadProgress}
|
||||
size={14}
|
||||
onDownload={onDownload}
|
||||
onRemove={onRemoveDownload}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="track-actions">
|
||||
<TrackMenu
|
||||
onPlayNow={playNowAction}
|
||||
@@ -246,6 +268,23 @@
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.download-indicator {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 28px;
|
||||
opacity: 0;
|
||||
transition: opacity 150ms ease;
|
||||
}
|
||||
|
||||
.download-indicator.has-download {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.track-row:hover .download-indicator {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.track-actions {
|
||||
margin-left: auto;
|
||||
display: flex;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { ArrowLeft, Play, Shuffle, Heart, Plus, MoreHorizontal } from 'lucide-svelte';
|
||||
import TrackRow from '../TrackRow.svelte';
|
||||
import { getDownloadState, type DownloadStatus } from '$lib/stores/downloadState';
|
||||
|
||||
interface Track {
|
||||
id: number;
|
||||
@@ -47,6 +48,9 @@
|
||||
onShuffleAll?: () => void;
|
||||
onAddToQueue?: () => void;
|
||||
onAddTrackToPlaylist?: (trackId: number) => void;
|
||||
onTrackDownload?: (track: Track) => void;
|
||||
onTrackRemoveDownload?: (trackId: number) => void;
|
||||
getTrackDownloadStatus?: (trackId: number) => { status: DownloadStatus; progress: number };
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -64,7 +68,10 @@
|
||||
onPlayAll,
|
||||
onShuffleAll,
|
||||
onAddToQueue,
|
||||
onAddTrackToPlaylist
|
||||
onAddTrackToPlaylist,
|
||||
onTrackDownload,
|
||||
onTrackRemoveDownload,
|
||||
getTrackDownloadStatus
|
||||
}: Props = $props();
|
||||
|
||||
let currentTrack = $state<number | null>(null);
|
||||
@@ -202,6 +209,7 @@
|
||||
<!-- Track Rows -->
|
||||
<div class="tracks">
|
||||
{#each album.tracks as track}
|
||||
{@const downloadInfo = getTrackDownloadStatus?.(track.id) ?? { status: 'none' as const, progress: 0 }}
|
||||
<TrackRow
|
||||
number={track.number}
|
||||
title={track.title}
|
||||
@@ -210,10 +218,14 @@
|
||||
quality={track.quality}
|
||||
isPlaying={currentTrack === track.id}
|
||||
isFavorite={favoriteTrackIds.has(track.id)}
|
||||
downloadStatus={downloadInfo.status}
|
||||
downloadProgress={downloadInfo.progress}
|
||||
onPlay={() => {
|
||||
currentTrack = track.id;
|
||||
onTrackPlay?.(track);
|
||||
}}
|
||||
onDownload={onTrackDownload ? () => onTrackDownload(track) : undefined}
|
||||
onRemoveDownload={onTrackRemoveDownload ? () => onTrackRemoveDownload(track.id) : undefined}
|
||||
menuActions={{
|
||||
onPlayNow: () => {
|
||||
currentTrack = track.id;
|
||||
|
||||
Reference in new issue
Block a user