feat(credits): redesign Single Track Modal per Figma specs (Phase 5)
- Glass effect modal (560px, blur(20px), rgba border) - Header with track title + album subtitle - 3-column metadata grid: Duration, Quality, ISRC - 2-column credits grid grouped by role - Role ordering: Composer/Lyricist first, MainArtist last - CamelCase to UPPERCASE label conversion - Multiple performers per role joined with comma - Copyright section at bottom - ESC key closes modal - Animations: fade-in overlay, scale-up modal
This commit is contained in:
1 parent
9194164418
commit
f7161bafe1
1 file changed
+278
-186
@@ -1,7 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import Modal from './Modal.svelte';
|
||||
import { Clock, Disc3, Music2, User, Users, Copyright, Loader2 } from 'lucide-svelte';
|
||||
import { X, Loader2 } from 'lucide-svelte';
|
||||
import type { TrackInfo, Performer } from '$lib/types';
|
||||
|
||||
interface Props {
|
||||
@@ -16,22 +15,13 @@
|
||||
let error = $state<string | null>(null);
|
||||
let trackInfo = $state<TrackInfo | null>(null);
|
||||
|
||||
// Format duration from seconds to MM:SS
|
||||
// Format duration from seconds to M:SS
|
||||
function formatDuration(seconds: number): string {
|
||||
const mins = Math.floor(seconds / 60);
|
||||
const secs = seconds % 60;
|
||||
return `${mins}:${secs.toString().padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
// Format sample rate for display
|
||||
function formatSampleRate(rate?: number): string {
|
||||
if (!rate) return '';
|
||||
if (rate >= 1000) {
|
||||
return `${(rate / 1000).toFixed(1)}kHz`.replace('.0kHz', 'kHz');
|
||||
}
|
||||
return `${rate}Hz`;
|
||||
}
|
||||
|
||||
// Format quality string
|
||||
function formatQuality(track: TrackInfo['track']): string {
|
||||
const parts: string[] = [];
|
||||
@@ -39,7 +29,7 @@
|
||||
parts.push(`${track.maximum_bit_depth}-bit`);
|
||||
}
|
||||
if (track.maximum_sampling_rate) {
|
||||
parts.push(formatSampleRate(track.maximum_sampling_rate * 1000));
|
||||
parts.push(`${track.maximum_sampling_rate}kHz`);
|
||||
}
|
||||
if (parts.length === 0) {
|
||||
return track.hires_streamable ? 'Hi-Res' : 'Lossless';
|
||||
@@ -47,6 +37,56 @@
|
||||
return parts.join(' / ');
|
||||
}
|
||||
|
||||
// Convert CamelCase role to display format
|
||||
function formatRole(role: string): string {
|
||||
return role.replace(/([A-Z])/g, ' $1').trim().toUpperCase();
|
||||
}
|
||||
|
||||
// Group performers by role and return ordered entries
|
||||
function getGroupedCredits(performers: Performer[]): { role: string; names: string[] }[] {
|
||||
const grouped: Record<string, string[]> = {};
|
||||
|
||||
performers.forEach(performer => {
|
||||
performer.roles.forEach(role => {
|
||||
if (!grouped[role]) {
|
||||
grouped[role] = [];
|
||||
}
|
||||
if (!grouped[role].includes(performer.name)) {
|
||||
grouped[role].push(performer.name);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Define priority roles
|
||||
const priorityFirst = ['Composer', 'Lyricist'];
|
||||
const priorityLast = ['MainArtist', 'Main Artist'];
|
||||
|
||||
const entries = Object.entries(grouped);
|
||||
|
||||
// Sort: Composer/Lyricist first, MainArtist last, others alphabetically
|
||||
entries.sort(([a], [b]) => {
|
||||
const aIsFirst = priorityFirst.some(p => a.toLowerCase() === p.toLowerCase());
|
||||
const bIsFirst = priorityFirst.some(p => b.toLowerCase() === p.toLowerCase());
|
||||
const aIsLast = priorityLast.some(p => a.toLowerCase() === p.toLowerCase());
|
||||
const bIsLast = priorityLast.some(p => b.toLowerCase() === p.toLowerCase());
|
||||
|
||||
if (aIsFirst && !bIsFirst) return -1;
|
||||
if (!aIsFirst && bIsFirst) return 1;
|
||||
if (aIsLast && !bIsLast) return 1;
|
||||
if (!aIsLast && bIsLast) return -1;
|
||||
|
||||
// Within priority first, Composer before Lyricist
|
||||
if (aIsFirst && bIsFirst) {
|
||||
if (a.toLowerCase() === 'composer') return -1;
|
||||
if (b.toLowerCase() === 'composer') return 1;
|
||||
}
|
||||
|
||||
return a.localeCompare(b);
|
||||
});
|
||||
|
||||
return entries.map(([role, names]) => ({ role, names }));
|
||||
}
|
||||
|
||||
// Load track info when modal opens
|
||||
$effect(() => {
|
||||
if (isOpen && trackId) {
|
||||
@@ -69,114 +109,142 @@
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleKeydown(e: KeyboardEvent) {
|
||||
if (e.key === 'Escape') {
|
||||
onClose();
|
||||
}
|
||||
}
|
||||
|
||||
// Derived: grouped credits
|
||||
const groupedCredits = $derived(
|
||||
trackInfo?.performers ? getGroupedCredits(trackInfo.performers) : []
|
||||
);
|
||||
</script>
|
||||
|
||||
<Modal {isOpen} {onClose} title="Track Info" maxWidth="520px">
|
||||
{#snippet children()}
|
||||
{#if loading}
|
||||
<div class="loading-state">
|
||||
<Loader2 size={32} class="spinner" />
|
||||
<span>Loading track info...</span>
|
||||
</div>
|
||||
{:else if error}
|
||||
<div class="error-state">
|
||||
<p>Failed to load track info</p>
|
||||
<span class="error-message">{error}</span>
|
||||
</div>
|
||||
{:else if trackInfo}
|
||||
<div class="track-info">
|
||||
<!-- Track Details Section -->
|
||||
<section class="info-section">
|
||||
<div class="info-row">
|
||||
<Music2 size={16} class="info-icon" />
|
||||
<span class="info-label">Title</span>
|
||||
<span class="info-value">{trackInfo.track.title}</span>
|
||||
<svelte:window on:keydown={handleKeydown} />
|
||||
|
||||
{#if isOpen}
|
||||
<div class="modal-overlay" onclick={onClose} role="dialog" aria-modal="true">
|
||||
<div class="track-modal" onclick={(e) => e.stopPropagation()}>
|
||||
{#if loading}
|
||||
<div class="loading-state">
|
||||
<Loader2 size={32} class="spinner" />
|
||||
<span>Loading track info...</span>
|
||||
</div>
|
||||
{:else if error}
|
||||
<div class="error-state">
|
||||
<p>Failed to load track info</p>
|
||||
<span class="error-message">{error}</span>
|
||||
</div>
|
||||
{:else if trackInfo}
|
||||
<!-- Header -->
|
||||
<div class="modal-header">
|
||||
<div class="header-titles">
|
||||
<h2 class="track-title">{trackInfo.track.title}</h2>
|
||||
{#if trackInfo.track.album?.title}
|
||||
<span class="album-title">{trackInfo.track.album.title}</span>
|
||||
{/if}
|
||||
</div>
|
||||
<button class="close-btn" onclick={onClose} aria-label="Close">
|
||||
<X size={18} />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Content -->
|
||||
<div class="modal-content">
|
||||
<!-- Metadata Grid (3 columns) -->
|
||||
<div class="metadata-grid">
|
||||
<div class="metadata-item">
|
||||
<span class="metadata-label">DURATION</span>
|
||||
<span class="metadata-value">{formatDuration(trackInfo.track.duration)}</span>
|
||||
</div>
|
||||
<div class="metadata-item">
|
||||
<span class="metadata-label">QUALITY</span>
|
||||
<span class="metadata-value">{formatQuality(trackInfo.track)}</span>
|
||||
</div>
|
||||
{#if trackInfo.track.isrc}
|
||||
<div class="metadata-item">
|
||||
<span class="metadata-label">ISRC</span>
|
||||
<span class="metadata-value mono">{trackInfo.track.isrc}</span>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if trackInfo.track.performer?.name}
|
||||
<div class="info-row">
|
||||
<User size={16} class="info-icon" />
|
||||
<span class="info-label">Artist</span>
|
||||
<span class="info-value">{trackInfo.track.performer.name}</span>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if trackInfo.track.album?.title}
|
||||
<div class="info-row">
|
||||
<Disc3 size={16} class="info-icon" />
|
||||
<span class="info-label">Album</span>
|
||||
<span class="info-value">{trackInfo.track.album.title}</span>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="info-row">
|
||||
<Clock size={16} class="info-icon" />
|
||||
<span class="info-label">Duration</span>
|
||||
<span class="info-value">{formatDuration(trackInfo.track.duration)}</span>
|
||||
</div>
|
||||
|
||||
<div class="info-row">
|
||||
<span class="info-label quality-label">Quality</span>
|
||||
<span class="info-value quality-value">{formatQuality(trackInfo.track)}</span>
|
||||
</div>
|
||||
|
||||
{#if trackInfo.track.isrc}
|
||||
<div class="info-row">
|
||||
<span class="info-label">ISRC</span>
|
||||
<span class="info-value mono">{trackInfo.track.isrc}</span>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if trackInfo.track.composer?.name}
|
||||
<div class="info-row">
|
||||
<span class="info-label">Composer</span>
|
||||
<span class="info-value">{trackInfo.track.composer.name}</span>
|
||||
</div>
|
||||
{/if}
|
||||
</section>
|
||||
|
||||
<!-- Credits Section -->
|
||||
{#if trackInfo.performers.length > 0}
|
||||
<section class="credits-section">
|
||||
<h3 class="section-title">
|
||||
<Users size={16} />
|
||||
Credits
|
||||
</h3>
|
||||
<div class="performers-list">
|
||||
{#each trackInfo.performers as performer}
|
||||
<div class="performer">
|
||||
<span class="performer-name">{performer.name}</span>
|
||||
{#if performer.roles.length > 0}
|
||||
<span class="performer-roles">{performer.roles.join(', ')}</span>
|
||||
{/if}
|
||||
<!-- Credits Grid (2 columns) -->
|
||||
{#if groupedCredits.length > 0}
|
||||
<div class="divider"></div>
|
||||
<div class="credits-grid">
|
||||
{#each groupedCredits as { role, names }}
|
||||
<div class="credit-item">
|
||||
<span class="credit-label">{formatRole(role)}</span>
|
||||
<span class="credit-value">{names.join(', ')}</span>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</section>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
<!-- Copyright Section -->
|
||||
{#if trackInfo.track.copyright}
|
||||
<section class="copyright-section">
|
||||
<div class="copyright">
|
||||
<Copyright size={14} />
|
||||
<span>{trackInfo.track.copyright}</span>
|
||||
</div>
|
||||
</section>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{/snippet}
|
||||
</Modal>
|
||||
<!-- Copyright -->
|
||||
{#if trackInfo.track.copyright}
|
||||
<div class="divider"></div>
|
||||
<div class="copyright">{trackInfo.track.copyright}</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.modal-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.75);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 1000;
|
||||
animation: fade-in 200ms ease-out;
|
||||
}
|
||||
|
||||
@keyframes fade-in {
|
||||
from { opacity: 0; }
|
||||
to { opacity: 1; }
|
||||
}
|
||||
|
||||
.track-modal {
|
||||
background: rgba(26, 26, 26, 0.95);
|
||||
backdrop-filter: blur(20px);
|
||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||
border-radius: 12px;
|
||||
width: 100%;
|
||||
max-width: 560px;
|
||||
max-height: 80vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
box-shadow: 0 24px 48px rgba(0, 0, 0, 0.6);
|
||||
animation: slide-up 200ms ease-out;
|
||||
margin: 20px;
|
||||
}
|
||||
|
||||
@keyframes slide-up {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: scale(0.95);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
.loading-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
padding: 40px 20px;
|
||||
padding: 60px 20px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
@@ -191,7 +259,7 @@
|
||||
|
||||
.error-state {
|
||||
text-align: center;
|
||||
padding: 40px 20px;
|
||||
padding: 60px 20px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
@@ -202,107 +270,131 @@
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.track-info {
|
||||
/* Header */
|
||||
.modal-header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
padding: 16px 24px;
|
||||
min-height: 72px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.header-titles {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
gap: 4px;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
padding-right: 16px;
|
||||
}
|
||||
|
||||
.info-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.info-row {
|
||||
display: grid;
|
||||
grid-template-columns: 20px 80px 1fr;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.info-row :global(.info-icon) {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.info-label {
|
||||
font-size: 13px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.quality-label {
|
||||
grid-column: 1 / 3;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
font-size: 14px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.info-value.mono {
|
||||
font-family: monospace;
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.quality-value {
|
||||
background: var(--bg-tertiary);
|
||||
padding: 2px 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
width: fit-content;
|
||||
}
|
||||
|
||||
.credits-section {
|
||||
border-top: 1px solid var(--bg-tertiary);
|
||||
padding-top: 16px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 14px;
|
||||
.track-title {
|
||||
margin: 0;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
margin: 0 0 12px 0;
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
.performers-list {
|
||||
.album-title {
|
||||
font-size: 13px;
|
||||
color: var(--text-tertiary, #888888);
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
background: transparent;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
color: var(--text-muted);
|
||||
cursor: pointer;
|
||||
flex-shrink: 0;
|
||||
transition: background 200ms ease, color 200ms ease;
|
||||
}
|
||||
|
||||
.performer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
padding: 8px 12px;
|
||||
background: var(--bg-secondary);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.performer-name {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
.close-btn:hover {
|
||||
background: var(--bg-tertiary);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.performer-roles {
|
||||
font-size: 12px;
|
||||
/* Content */
|
||||
.modal-content {
|
||||
padding: 0 24px 24px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
/* Metadata Grid */
|
||||
.metadata-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
.metadata-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.metadata-label {
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.05em;
|
||||
text-transform: uppercase;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.copyright-section {
|
||||
border-top: 1px solid var(--bg-tertiary);
|
||||
padding-top: 16px;
|
||||
.metadata-value {
|
||||
font-size: 14px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.copyright {
|
||||
.metadata-value.mono {
|
||||
font-family: monospace;
|
||||
font-size: 13px;
|
||||
color: var(--text-tertiary, #888888);
|
||||
}
|
||||
|
||||
/* Divider */
|
||||
.divider {
|
||||
height: 1px;
|
||||
background: var(--bg-tertiary);
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
/* Credits Grid */
|
||||
.credits-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: 16px 24px;
|
||||
}
|
||||
|
||||
.credit-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.credit-label {
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.05em;
|
||||
text-transform: uppercase;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.credit-value {
|
||||
font-size: 14px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
/* Copyright */
|
||||
.copyright {
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user