mirror of
https://github.com/markuryy/shark.git
synced 2025-12-15 12:41:02 +00:00
feat(layout): playlist cover art, album UI
This commit is contained in:
263
src/routes/albums/[artist]/[album]/+page.svelte
Normal file
263
src/routes/albums/[artist]/[album]/+page.svelte
Normal file
@@ -0,0 +1,263 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { page } from '$app/stores';
|
||||
import { convertFileSrc } from '@tauri-apps/api/core';
|
||||
import { settings, loadSettings } from '$lib/stores/settings';
|
||||
import { loadAlbumTracks, findAlbumArt } from '$lib/library/album';
|
||||
import type { Track } from '$lib/types/track';
|
||||
|
||||
let tracks = $state<Track[]>([]);
|
||||
let coverArtPath = $state<string | undefined>(undefined);
|
||||
let loading = $state(true);
|
||||
let error = $state<string | null>(null);
|
||||
let selectedTrackIndex = $state<number | null>(null);
|
||||
|
||||
let artistName = $derived(decodeURIComponent($page.params.artist ?? ''));
|
||||
let albumName = $derived(decodeURIComponent($page.params.album ?? ''));
|
||||
|
||||
onMount(async () => {
|
||||
await loadSettings();
|
||||
await loadAlbum();
|
||||
});
|
||||
|
||||
async function loadAlbum() {
|
||||
loading = true;
|
||||
error = null;
|
||||
|
||||
if (!$settings.musicFolder) {
|
||||
error = 'Music folder not configured. Please set it in Settings.';
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const albumPath = `${$settings.musicFolder}/${artistName}/${albumName}`;
|
||||
|
||||
const [tracksData, coverPath] = await Promise.all([
|
||||
loadAlbumTracks(albumPath),
|
||||
findAlbumArt(albumPath)
|
||||
]);
|
||||
|
||||
tracks = tracksData;
|
||||
coverArtPath = coverPath;
|
||||
|
||||
if (tracks.length === 0) {
|
||||
error = 'No tracks found in this album.';
|
||||
}
|
||||
|
||||
loading = false;
|
||||
} catch (e) {
|
||||
error = 'Error loading album: ' + (e as Error).message;
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
function getThumbnailUrl(coverPath?: string): string {
|
||||
if (!coverPath) {
|
||||
return '';
|
||||
}
|
||||
return convertFileSrc(coverPath);
|
||||
}
|
||||
|
||||
function handleTrackClick(index: number) {
|
||||
selectedTrackIndex = index;
|
||||
}
|
||||
|
||||
function getAlbumYear(): string {
|
||||
const year = tracks.find(t => t.metadata.year)?.metadata.year;
|
||||
return year ? year.toString() : '—';
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="album-wrapper">
|
||||
{#if loading}
|
||||
<p style="padding: 8px;">Loading album...</p>
|
||||
{:else if error}
|
||||
<p class="error" style="padding: 8px;">{error}</p>
|
||||
{:else}
|
||||
<!-- Album Header -->
|
||||
<div class="album-header">
|
||||
{#if coverArtPath}
|
||||
<img
|
||||
src={getThumbnailUrl(coverArtPath)}
|
||||
alt="{albumName} cover"
|
||||
class="album-cover"
|
||||
/>
|
||||
{:else}
|
||||
<div class="album-cover-placeholder"></div>
|
||||
{/if}
|
||||
<div class="album-info">
|
||||
<h2>{albumName}</h2>
|
||||
<p class="album-artist">{artistName}</p>
|
||||
<p class="album-meta">
|
||||
{getAlbumYear()} • {tracks.length} track{tracks.length !== 1 ? 's' : ''}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<section class="album-content">
|
||||
<!-- Tabs (single tab for tracks) -->
|
||||
<menu role="tablist">
|
||||
<li role="tab" aria-selected={true}>
|
||||
<button>Tracks</button>
|
||||
</li>
|
||||
</menu>
|
||||
|
||||
<!-- Track Listing -->
|
||||
<div class="window tab-content" role="tabpanel">
|
||||
<div class="window-body">
|
||||
<div class="sunken-panel table-container">
|
||||
<table class="interactive">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 50px;">#</th>
|
||||
<th>Title</th>
|
||||
<th>Duration</th>
|
||||
<th>Format</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each tracks as track, i}
|
||||
<tr
|
||||
class:highlighted={selectedTrackIndex === i}
|
||||
onclick={() => handleTrackClick(i)}
|
||||
>
|
||||
<td class="track-number">
|
||||
{track.metadata.trackNumber ?? i + 1}
|
||||
</td>
|
||||
<td>{track.metadata.title || track.filename}</td>
|
||||
<td class="duration">
|
||||
{#if track.metadata.duration}
|
||||
{Math.floor(track.metadata.duration / 60)}:{String(Math.floor(track.metadata.duration % 60)).padStart(2, '0')}
|
||||
{:else}
|
||||
—
|
||||
{/if}
|
||||
</td>
|
||||
<td class="format">{track.format.toUpperCase()}</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.album-wrapper {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: #ff6b6b;
|
||||
}
|
||||
|
||||
.album-header {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
padding: 8px 8px 0 8px;
|
||||
margin-bottom: 8px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.album-cover {
|
||||
width: 160px;
|
||||
height: 160px;
|
||||
object-fit: cover;
|
||||
image-rendering: auto;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.album-cover-placeholder {
|
||||
width: 160px;
|
||||
height: 160px;
|
||||
background: linear-gradient(135deg, #c0c0c0 25%, #808080 25%, #808080 50%, #c0c0c0 50%, #c0c0c0 75%, #808080 75%);
|
||||
background-size: 8px 8px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.album-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin: 0 0 4px 0;
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
.album-artist {
|
||||
margin: 0 0 8px 0;
|
||||
font-size: 1.1em;
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.album-meta {
|
||||
margin: 0;
|
||||
opacity: 0.6;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.album-content {
|
||||
margin: 0;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.tab-content {
|
||||
margin-top: -2px;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.window-body {
|
||||
padding: 0;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.table-container {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
th {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.track-number {
|
||||
text-align: center;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.duration {
|
||||
font-family: monospace;
|
||||
font-size: 0.9em;
|
||||
text-align: center;
|
||||
width: 80px;
|
||||
}
|
||||
|
||||
.format {
|
||||
font-family: monospace;
|
||||
font-size: 0.85em;
|
||||
text-transform: uppercase;
|
||||
text-align: center;
|
||||
width: 80px;
|
||||
}
|
||||
</style>
|
||||
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
import { convertFileSrc } from '@tauri-apps/api/core';
|
||||
import { settings, loadSettings } from '$lib/stores/settings';
|
||||
import { scanArtistsWithAlbums, scanAlbums } from '$lib/library/scanner';
|
||||
@@ -56,8 +57,11 @@
|
||||
selectedArtistIndex = index;
|
||||
}
|
||||
|
||||
function handleAlbumClick(index: number) {
|
||||
function handleAlbumClick(album: Album, index: number) {
|
||||
selectedAlbumIndex = index;
|
||||
const artistEncoded = encodeURIComponent(album.artist);
|
||||
const albumEncoded = encodeURIComponent(album.title);
|
||||
goto(`/albums/${artistEncoded}/${albumEncoded}`);
|
||||
}
|
||||
|
||||
function getTotalTracks(artist: ArtistWithAlbums): number {
|
||||
@@ -143,7 +147,7 @@
|
||||
{#each albums as album, i}
|
||||
<tr
|
||||
class:highlighted={selectedAlbumIndex === i}
|
||||
onclick={() => handleAlbumClick(i)}
|
||||
onclick={() => handleAlbumClick(album, i)}
|
||||
>
|
||||
<td class="cover-cell">
|
||||
{#if album.coverArtPath}
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { page } from '$app/stores';
|
||||
import { convertFileSrc } from '@tauri-apps/api/core';
|
||||
import { settings, loadSettings } from '$lib/stores/settings';
|
||||
import { scanPlaylists } from '$lib/library/scanner';
|
||||
import { loadPlaylistTracks } from '$lib/library/playlist';
|
||||
import { loadPlaylistTracks, findPlaylistArt } from '$lib/library/playlist';
|
||||
import type { Track, PlaylistWithTracks } from '$lib/types/track';
|
||||
|
||||
let playlistData = $state<PlaylistWithTracks | null>(null);
|
||||
let coverArtPath = $state<string | undefined>(undefined);
|
||||
let loading = $state(true);
|
||||
let error = $state<string | null>(null);
|
||||
let selectedTrackIndex = $state<number | null>(null);
|
||||
|
||||
let playlistName = $derived(decodeURIComponent($page.params.name ?? ''));
|
||||
|
||||
@@ -38,12 +41,14 @@
|
||||
return;
|
||||
}
|
||||
|
||||
// Load tracks from the playlist file
|
||||
playlistData = await loadPlaylistTracks(
|
||||
playlist.path,
|
||||
playlist.name,
|
||||
$settings.musicFolder
|
||||
);
|
||||
// Load tracks and cover art in parallel
|
||||
const [tracksData, coverPath] = await Promise.all([
|
||||
loadPlaylistTracks(playlist.path, playlist.name, $settings.musicFolder),
|
||||
findPlaylistArt(playlist.path)
|
||||
]);
|
||||
|
||||
playlistData = tracksData;
|
||||
coverArtPath = coverPath;
|
||||
|
||||
loading = false;
|
||||
} catch (e) {
|
||||
@@ -51,91 +56,198 @@
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
function getThumbnailUrl(coverPath?: string): string {
|
||||
if (!coverPath) {
|
||||
return '';
|
||||
}
|
||||
return convertFileSrc(coverPath);
|
||||
}
|
||||
|
||||
function handleTrackClick(index: number) {
|
||||
selectedTrackIndex = index;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<h2>{playlistName}</h2>
|
||||
|
||||
<div class="playlist-wrapper">
|
||||
{#if loading}
|
||||
<p>Loading playlist...</p>
|
||||
<p style="padding: 8px;">Loading playlist...</p>
|
||||
{:else if error}
|
||||
<p class="error">{error}</p>
|
||||
<p class="error" style="padding: 8px;">{error}</p>
|
||||
{:else if playlistData && playlistData.tracks.length === 0}
|
||||
<p>No tracks in this playlist.</p>
|
||||
<p style="padding: 8px;">No tracks in this playlist.</p>
|
||||
{:else if playlistData}
|
||||
<section class="playlist-content">
|
||||
<p class="track-count">{playlistData.tracks.length} track{playlistData.tracks.length !== 1 ? 's' : ''}</p>
|
||||
<!-- Playlist Header -->
|
||||
<div class="playlist-header">
|
||||
{#if coverArtPath}
|
||||
<img
|
||||
src={getThumbnailUrl(coverArtPath)}
|
||||
alt="{playlistName} cover"
|
||||
class="playlist-cover"
|
||||
/>
|
||||
{:else}
|
||||
<div class="playlist-cover-placeholder"></div>
|
||||
{/if}
|
||||
<div class="playlist-info">
|
||||
<h2>{playlistName}</h2>
|
||||
<p class="playlist-meta">
|
||||
{playlistData.tracks.length} track{playlistData.tracks.length !== 1 ? 's' : ''}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 40px;">#</th>
|
||||
<th>Title</th>
|
||||
<th>Artist</th>
|
||||
<th>Album</th>
|
||||
<th>Duration</th>
|
||||
<th>Format</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each playlistData.tracks as track, index}
|
||||
<tr>
|
||||
<td class="track-number">{index + 1}</td>
|
||||
<td>{track.metadata.title || track.filename}</td>
|
||||
<td>{track.metadata.artist || '—'}</td>
|
||||
<td class="album">{track.metadata.album || '—'}</td>
|
||||
<td class="duration">
|
||||
{#if track.metadata.duration}
|
||||
{Math.floor(track.metadata.duration / 60)}:{String(Math.floor(track.metadata.duration % 60)).padStart(2, '0')}
|
||||
{:else}
|
||||
—
|
||||
{/if}
|
||||
</td>
|
||||
<td class="format">{track.format.toUpperCase()}</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
<section class="playlist-content">
|
||||
<!-- Tabs (single tab for tracks) -->
|
||||
<menu role="tablist">
|
||||
<li role="tab" aria-selected={true}>
|
||||
<button>Tracks</button>
|
||||
</li>
|
||||
</menu>
|
||||
|
||||
<!-- Track Listing -->
|
||||
<div class="window tab-content" role="tabpanel">
|
||||
<div class="window-body">
|
||||
<div class="sunken-panel table-container">
|
||||
<table class="interactive">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 50px;">#</th>
|
||||
<th>Title</th>
|
||||
<th>Artist</th>
|
||||
<th>Album</th>
|
||||
<th>Duration</th>
|
||||
<th>Format</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each playlistData.tracks as track, index}
|
||||
<tr
|
||||
class:highlighted={selectedTrackIndex === index}
|
||||
onclick={() => handleTrackClick(index)}
|
||||
>
|
||||
<td class="track-number">{index + 1}</td>
|
||||
<td>{track.metadata.title || track.filename}</td>
|
||||
<td>{track.metadata.artist || '—'}</td>
|
||||
<td>{track.metadata.album || '—'}</td>
|
||||
<td class="duration">
|
||||
{#if track.metadata.duration}
|
||||
{Math.floor(track.metadata.duration / 60)}:{String(Math.floor(track.metadata.duration % 60)).padStart(2, '0')}
|
||||
{:else}
|
||||
—
|
||||
{/if}
|
||||
</td>
|
||||
<td class="format">{track.format.toUpperCase()}</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
h2 {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.playlist-content {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.track-count {
|
||||
margin-bottom: 12px;
|
||||
opacity: 0.7;
|
||||
font-size: 0.9em;
|
||||
.playlist-wrapper {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: #ff6b6b;
|
||||
}
|
||||
|
||||
.playlist-header {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
padding: 8px 8px 0 8px;
|
||||
margin-bottom: 8px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.playlist-cover {
|
||||
width: 160px;
|
||||
height: 160px;
|
||||
object-fit: cover;
|
||||
image-rendering: auto;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.playlist-cover-placeholder {
|
||||
width: 160px;
|
||||
height: 160px;
|
||||
background: linear-gradient(135deg, #c0c0c0 25%, #808080 25%, #808080 50%, #c0c0c0 50%, #c0c0c0 75%, #808080 75%);
|
||||
background-size: 8px 8px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.playlist-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin: 0 0 8px 0;
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
.playlist-meta {
|
||||
margin: 0;
|
||||
opacity: 0.6;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.playlist-content {
|
||||
margin: 0;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.tab-content {
|
||||
margin-top: -2px;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.window-body {
|
||||
padding: 0;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.table-container {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
th {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.track-number {
|
||||
text-align: center;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.album {
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.duration {
|
||||
font-family: monospace;
|
||||
font-size: 0.9em;
|
||||
text-align: center;
|
||||
width: 80px;
|
||||
}
|
||||
|
||||
.format {
|
||||
@@ -143,5 +255,6 @@
|
||||
font-size: 0.85em;
|
||||
text-transform: uppercase;
|
||||
text-align: center;
|
||||
width: 80px;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user