fix: add missing CSS import and fix UI issues
- Add app.css import to +layout.svelte (fixes broken/light UI) - Add logging for audio debugging - Add image fallbacks for album and track artwork - Fix sidebar/main-content layout (flex-shrink, min-width) - Remove placeholder data from HomeView - Add LoginView and SearchView components - Update window title and branding to QBZ
This commit is contained in:
1 parent
cdfd3263de
commit
3a0e3f26d5
22 files changed
+1950
-298
No files matched your search
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { Play } from 'lucide-svelte';
|
||||
import { Play, Disc3 } from 'lucide-svelte';
|
||||
|
||||
interface Props {
|
||||
artwork: string;
|
||||
@@ -13,7 +13,12 @@
|
||||
let { artwork, title, artist, quality, size = 'standard', onclick }: Props = $props();
|
||||
|
||||
let isHovered = $state(false);
|
||||
let imageError = $state(false);
|
||||
const cardSize = $derived(size === 'large' ? 200 : 180);
|
||||
|
||||
function handleImageError() {
|
||||
imageError = true;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div
|
||||
@@ -31,7 +36,13 @@
|
||||
class="artwork-container"
|
||||
style="width: {cardSize}px; height: {cardSize}px; transform: scale({isHovered ? 1.02 : 1})"
|
||||
>
|
||||
<img src={artwork} alt={title} />
|
||||
{#if imageError || !artwork}
|
||||
<div class="artwork-placeholder">
|
||||
<Disc3 size={48} />
|
||||
</div>
|
||||
{:else}
|
||||
<img src={artwork} alt={title} onerror={handleImageError} />
|
||||
{/if}
|
||||
|
||||
<!-- Quality Indicator -->
|
||||
{#if quality}
|
||||
@@ -76,6 +87,16 @@
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.artwork-placeholder {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: linear-gradient(135deg, var(--bg-tertiary) 0%, var(--bg-secondary) 100%);
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.quality-badge {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { Search, Home, Radio, Clock, Music, Disc3, Mic2, Plus, MoreVertical, ChevronDown } from 'lucide-svelte';
|
||||
import { Search, Home, Radio, Clock, Music, Disc3, Mic2, Plus, MoreVertical, ChevronDown, Heart } from 'lucide-svelte';
|
||||
import NavigationItem from './NavigationItem.svelte';
|
||||
import UserCard from './UserCard.svelte';
|
||||
|
||||
@@ -7,11 +7,15 @@
|
||||
activeView: string;
|
||||
onNavigate: (view: string) => void;
|
||||
onSettingsClick?: () => void;
|
||||
onLogout?: () => void;
|
||||
userName?: string;
|
||||
subscription?: string;
|
||||
}
|
||||
|
||||
let { activeView, onNavigate, onSettingsClick }: Props = $props();
|
||||
let { activeView, onNavigate, onSettingsClick, onLogout, userName = 'User', subscription = 'Qobuz' }: Props = $props();
|
||||
|
||||
function handleViewChange(view: string) {
|
||||
console.log('Sidebar: navigating to', view);
|
||||
onNavigate(view);
|
||||
}
|
||||
</script>
|
||||
@@ -20,14 +24,10 @@
|
||||
<!-- Scrollable Content Area -->
|
||||
<div class="content">
|
||||
<!-- Search Bar -->
|
||||
<div class="search-container">
|
||||
<button class="search-container" onclick={() => handleViewChange('search')}>
|
||||
<Search class="search-icon" size={16} />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search"
|
||||
class="search-input"
|
||||
/>
|
||||
</div>
|
||||
<span class="search-placeholder">Search</span>
|
||||
</button>
|
||||
|
||||
<!-- Navigation Section -->
|
||||
<nav class="nav-section">
|
||||
@@ -140,9 +140,10 @@
|
||||
<!-- Fixed User Profile at Bottom -->
|
||||
<div class="user-section">
|
||||
<UserCard
|
||||
username="Username"
|
||||
subscription="Studio Premier"
|
||||
username={userName}
|
||||
{subscription}
|
||||
onSettingsClick={onSettingsClick ?? (() => handleViewChange('settings'))}
|
||||
{onLogout}
|
||||
/>
|
||||
</div>
|
||||
</aside>
|
||||
@@ -150,6 +151,8 @@
|
||||
<style>
|
||||
.sidebar {
|
||||
width: 240px;
|
||||
min-width: 240px;
|
||||
flex-shrink: 0;
|
||||
background-color: var(--bg-secondary);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -167,31 +170,30 @@
|
||||
}
|
||||
|
||||
.search-container {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.search-container :global(.search-icon) {
|
||||
position: absolute;
|
||||
left: 12px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.search-input {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
width: 100%;
|
||||
height: 36px;
|
||||
background-color: var(--bg-tertiary);
|
||||
border-radius: 8px;
|
||||
padding-left: 40px;
|
||||
padding-right: 12px;
|
||||
font-size: 14px;
|
||||
color: var(--text-primary);
|
||||
padding: 0 12px;
|
||||
border: none;
|
||||
outline: none;
|
||||
cursor: pointer;
|
||||
transition: background-color 150ms ease;
|
||||
}
|
||||
|
||||
.search-input::placeholder {
|
||||
.search-container:hover {
|
||||
background-color: var(--bg-hover);
|
||||
}
|
||||
|
||||
.search-container :global(.search-icon) {
|
||||
color: var(--text-muted);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.search-placeholder {
|
||||
font-size: 14px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
<script lang="ts">
|
||||
import { Settings } from 'lucide-svelte';
|
||||
import { Settings, LogOut } from 'lucide-svelte';
|
||||
|
||||
interface Props {
|
||||
username: string;
|
||||
subscription: string;
|
||||
avatarUrl?: string;
|
||||
onSettingsClick: () => void;
|
||||
onLogout?: () => void;
|
||||
}
|
||||
|
||||
let { username, subscription, avatarUrl, onSettingsClick }: Props = $props();
|
||||
let { username, subscription, avatarUrl, onSettingsClick, onLogout }: Props = $props();
|
||||
</script>
|
||||
|
||||
<div class="user-card">
|
||||
@@ -27,16 +28,31 @@
|
||||
<div class="subscription">{subscription}</div>
|
||||
</div>
|
||||
|
||||
<!-- Settings Button -->
|
||||
<button
|
||||
class="settings-btn"
|
||||
onclick={(e) => {
|
||||
e.stopPropagation();
|
||||
onSettingsClick();
|
||||
}}
|
||||
>
|
||||
<Settings size={20} />
|
||||
</button>
|
||||
<!-- Action Buttons -->
|
||||
<div class="action-buttons">
|
||||
<button
|
||||
class="action-btn"
|
||||
onclick={(e) => {
|
||||
e.stopPropagation();
|
||||
onSettingsClick();
|
||||
}}
|
||||
title="Settings"
|
||||
>
|
||||
<Settings size={18} />
|
||||
</button>
|
||||
{#if onLogout}
|
||||
<button
|
||||
class="action-btn logout-btn"
|
||||
onclick={(e) => {
|
||||
e.stopPropagation();
|
||||
onLogout();
|
||||
}}
|
||||
title="Logout"
|
||||
>
|
||||
<LogOut size={18} />
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
@@ -97,21 +113,33 @@
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.settings-btn {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: none;
|
||||
border: none;
|
||||
color: #666666;
|
||||
color: var(--text-muted);
|
||||
cursor: pointer;
|
||||
flex-shrink: 0;
|
||||
transition: color 150ms ease;
|
||||
border-radius: 6px;
|
||||
transition: all 150ms ease;
|
||||
}
|
||||
|
||||
.settings-btn:hover {
|
||||
color: var(--text-muted);
|
||||
.action-btn:hover {
|
||||
color: var(--text-primary);
|
||||
background-color: var(--bg-tertiary);
|
||||
}
|
||||
|
||||
.logout-btn:hover {
|
||||
color: #ff6b6b;
|
||||
}
|
||||
</style>
|
||||
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { Music } from 'lucide-svelte';
|
||||
import HeroSection from '../HeroSection.svelte';
|
||||
import HorizontalScrollRow from '../HorizontalScrollRow.svelte';
|
||||
import AlbumCard from '../AlbumCard.svelte';
|
||||
@@ -26,32 +27,32 @@
|
||||
|
||||
let { featuredAlbum, recentAlbums = [], recommendedAlbums = [], newReleases = [], onAlbumClick }: Props = $props();
|
||||
|
||||
const defaultFeatured = {
|
||||
artwork: 'https://picsum.photos/seed/featured/800/400',
|
||||
title: 'Featured Album',
|
||||
artist: 'Featured Artist',
|
||||
year: '2024'
|
||||
};
|
||||
|
||||
const featured = featuredAlbum ?? (recentAlbums[0] ? {
|
||||
// Only show featured if we have actual data
|
||||
const hasFeatured = $derived(featuredAlbum || recentAlbums.length > 0);
|
||||
const featured = $derived(featuredAlbum ?? (recentAlbums[0] ? {
|
||||
artwork: recentAlbums[0].artwork,
|
||||
title: recentAlbums[0].title,
|
||||
artist: recentAlbums[0].artist,
|
||||
year: '2024'
|
||||
} : defaultFeatured);
|
||||
} : null));
|
||||
|
||||
const hasContent = $derived(recentAlbums.length > 0 || recommendedAlbums.length > 0 || newReleases.length > 0);
|
||||
</script>
|
||||
|
||||
<div class="home-view">
|
||||
<!-- Hero/Featured Section -->
|
||||
<HeroSection
|
||||
artwork={featured.artwork}
|
||||
title={featured.title}
|
||||
artist={featured.artist}
|
||||
year={featured.year}
|
||||
/>
|
||||
{#if hasContent}
|
||||
<!-- Hero/Featured Section -->
|
||||
{#if featured}
|
||||
<HeroSection
|
||||
artwork={featured.artwork}
|
||||
title={featured.title}
|
||||
artist={featured.artist}
|
||||
year={featured.year}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<!-- Recently Played -->
|
||||
{#if recentAlbums.length > 0}
|
||||
<!-- Recently Played -->
|
||||
{#if recentAlbums.length > 0}
|
||||
<HorizontalScrollRow title="Escuchado recientemente">
|
||||
{#snippet children()}
|
||||
{#each recentAlbums as album}
|
||||
@@ -104,15 +105,47 @@
|
||||
{/snippet}
|
||||
</HorizontalScrollRow>
|
||||
{/if}
|
||||
{:else}
|
||||
<!-- Welcome/Empty State -->
|
||||
<div class="welcome-state">
|
||||
<Music size={64} />
|
||||
<h1>Welcome to QBZ</h1>
|
||||
<p>Use the search to discover music on Qobuz</p>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.home-view {
|
||||
width: 100%;
|
||||
min-height: calc(100vh - 160px);
|
||||
}
|
||||
|
||||
.spacer {
|
||||
width: 60px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.welcome-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: calc(100vh - 200px);
|
||||
color: var(--text-muted);
|
||||
text-align: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.welcome-state h1 {
|
||||
font-size: 28px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.welcome-state p {
|
||||
font-size: 16px;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,355 @@
|
||||
<script lang="ts">
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { Music } from 'lucide-svelte';
|
||||
|
||||
interface UserInfo {
|
||||
userName: string;
|
||||
subscription: string;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
onLoginSuccess: (userInfo: UserInfo) => void;
|
||||
}
|
||||
|
||||
let { onLoginSuccess }: Props = $props();
|
||||
|
||||
let email = $state('');
|
||||
let password = $state('');
|
||||
let isLoading = $state(false);
|
||||
let isInitializing = $state(true);
|
||||
let error = $state<string | null>(null);
|
||||
let initError = $state<string | null>(null);
|
||||
|
||||
// Initialize the Qobuz client on mount
|
||||
$effect(() => {
|
||||
initializeClient();
|
||||
});
|
||||
|
||||
async function initializeClient() {
|
||||
try {
|
||||
isInitializing = true;
|
||||
initError = null;
|
||||
const result = await invoke<boolean>('init_client');
|
||||
console.log('Client initialized:', result);
|
||||
|
||||
// Check if already logged in
|
||||
const loggedIn = await invoke<boolean>('is_logged_in');
|
||||
if (loggedIn) {
|
||||
// Get user info from stored session
|
||||
const userInfo = await invoke<{ user_name: string; subscription: string } | null>('get_user_info');
|
||||
if (userInfo) {
|
||||
onLoginSuccess({ userName: userInfo.user_name, subscription: userInfo.subscription });
|
||||
} else {
|
||||
onLoginSuccess({ userName: 'Qobuz User', subscription: 'Active' });
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to initialize client:', err);
|
||||
initError = String(err);
|
||||
} finally {
|
||||
isInitializing = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleLogin(e: Event) {
|
||||
e.preventDefault();
|
||||
|
||||
if (!email || !password) {
|
||||
error = 'Please enter email and password';
|
||||
return;
|
||||
}
|
||||
|
||||
isLoading = true;
|
||||
error = null;
|
||||
|
||||
try {
|
||||
const response = await invoke<{
|
||||
success: boolean;
|
||||
user_name?: string;
|
||||
subscription?: string;
|
||||
error?: string;
|
||||
}>('login', { email, password });
|
||||
|
||||
console.log('Login response:', response);
|
||||
|
||||
if (response.success) {
|
||||
onLoginSuccess({
|
||||
userName: response.user_name || 'Qobuz User',
|
||||
subscription: response.subscription || 'Active'
|
||||
});
|
||||
} else {
|
||||
error = response.error || 'Login failed';
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Login error:', err);
|
||||
error = String(err);
|
||||
} finally {
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="login-view">
|
||||
<div class="login-card">
|
||||
<!-- Logo -->
|
||||
<div class="logo">
|
||||
<Music size={48} />
|
||||
<h1>QBZ</h1>
|
||||
<p class="subtitle">Native Qobuz Client for Linux</p>
|
||||
</div>
|
||||
|
||||
{#if isInitializing}
|
||||
<div class="initializing">
|
||||
<div class="spinner"></div>
|
||||
<p>Connecting to Qobuz...</p>
|
||||
</div>
|
||||
{:else if initError}
|
||||
<div class="error-box">
|
||||
<p>Failed to connect to Qobuz</p>
|
||||
<p class="error-detail">{initError}</p>
|
||||
<button class="retry-btn" onclick={initializeClient}>Retry</button>
|
||||
</div>
|
||||
{:else}
|
||||
<form onsubmit={handleLogin}>
|
||||
<div class="input-group">
|
||||
<label for="email">Email</label>
|
||||
<input
|
||||
id="email"
|
||||
type="email"
|
||||
bind:value={email}
|
||||
placeholder="your@email.com"
|
||||
disabled={isLoading}
|
||||
autocomplete="email"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="password">Password</label>
|
||||
<input
|
||||
id="password"
|
||||
type="password"
|
||||
bind:value={password}
|
||||
placeholder="Password"
|
||||
disabled={isLoading}
|
||||
autocomplete="current-password"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{#if error}
|
||||
<div class="error-message">{error}</div>
|
||||
{/if}
|
||||
|
||||
<button type="submit" class="login-btn" disabled={isLoading}>
|
||||
{#if isLoading}
|
||||
<div class="spinner small"></div>
|
||||
<span>Signing in...</span>
|
||||
{:else}
|
||||
<span>Sign in with Qobuz</span>
|
||||
{/if}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<p class="disclaimer">
|
||||
QBZ requires an active Qobuz subscription.
|
||||
Your credentials are sent directly to Qobuz and never stored on external servers.
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.login-view {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background-color: var(--bg-primary);
|
||||
}
|
||||
|
||||
.login-card {
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
padding: 48px;
|
||||
background-color: var(--bg-secondary);
|
||||
border-radius: 16px;
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.logo {
|
||||
text-align: center;
|
||||
margin-bottom: 32px;
|
||||
color: var(--accent-primary);
|
||||
}
|
||||
|
||||
.logo h1 {
|
||||
font-size: 32px;
|
||||
font-weight: 700;
|
||||
color: var(--text-primary);
|
||||
margin-top: 16px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
font-size: 14px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.initializing {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 32px 0;
|
||||
}
|
||||
|
||||
.initializing p {
|
||||
margin-top: 16px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.error-box {
|
||||
text-align: center;
|
||||
padding: 24px;
|
||||
background-color: rgba(255, 107, 107, 0.1);
|
||||
border-radius: 8px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.error-box p {
|
||||
color: #ff6b6b;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.error-detail {
|
||||
font-size: 12px;
|
||||
color: var(--text-muted) !important;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.retry-btn {
|
||||
margin-top: 16px;
|
||||
padding: 8px 24px;
|
||||
background-color: var(--accent-primary);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
transition: background-color 150ms ease;
|
||||
}
|
||||
|
||||
.retry-btn:hover {
|
||||
background-color: var(--accent-hover);
|
||||
}
|
||||
|
||||
form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.input-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.input-group label {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.input-group input {
|
||||
height: 48px;
|
||||
padding: 0 16px;
|
||||
background-color: var(--bg-tertiary);
|
||||
border: 1px solid transparent;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
color: var(--text-primary);
|
||||
outline: none;
|
||||
transition: border-color 150ms ease;
|
||||
}
|
||||
|
||||
.input-group input:focus {
|
||||
border-color: var(--accent-primary);
|
||||
}
|
||||
|
||||
.input-group input::placeholder {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.input-group input:disabled {
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
padding: 12px 16px;
|
||||
background-color: rgba(255, 107, 107, 0.1);
|
||||
border-radius: 8px;
|
||||
color: #ff6b6b;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.login-btn {
|
||||
height: 48px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
background-color: var(--accent-primary);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: background-color 150ms ease;
|
||||
}
|
||||
|
||||
.login-btn:hover:not(:disabled) {
|
||||
background-color: var(--accent-hover);
|
||||
}
|
||||
|
||||
.login-btn:disabled {
|
||||
opacity: 0.7;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.disclaimer {
|
||||
margin-top: 24px;
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
text-align: center;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border: 3px solid var(--bg-tertiary);
|
||||
border-top-color: var(--accent-primary);
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
.spinner.small {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border-width: 2px;
|
||||
border-color: rgba(255, 255, 255, 0.3);
|
||||
border-top-color: white;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,565 @@
|
||||
<script lang="ts">
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { Search, Disc3, Music, Mic2, User } from 'lucide-svelte';
|
||||
import AlbumCard from '../AlbumCard.svelte';
|
||||
|
||||
// Track which images have failed to load
|
||||
let failedTrackImages = $state<Set<number>>(new Set());
|
||||
let failedArtistImages = $state<Set<number>>(new Set());
|
||||
|
||||
function handleTrackImageError(trackId: number) {
|
||||
failedTrackImages = new Set([...failedTrackImages, trackId]);
|
||||
}
|
||||
|
||||
function handleArtistImageError(artistId: number) {
|
||||
failedArtistImages = new Set([...failedArtistImages, artistId]);
|
||||
}
|
||||
|
||||
interface Props {
|
||||
onAlbumClick?: (albumId: string) => void;
|
||||
onTrackPlay?: (track: Track) => void;
|
||||
}
|
||||
|
||||
let { onAlbumClick, onTrackPlay }: Props = $props();
|
||||
|
||||
interface Album {
|
||||
id: string;
|
||||
title: string;
|
||||
artist: { name: string };
|
||||
image: { small?: string; thumbnail?: string; large?: string };
|
||||
release_date_original?: string;
|
||||
hires_streamable?: boolean;
|
||||
maximum_bit_depth?: number;
|
||||
maximum_sampling_rate?: number;
|
||||
}
|
||||
|
||||
interface Track {
|
||||
id: number;
|
||||
title: string;
|
||||
duration: number;
|
||||
album?: {
|
||||
title: string;
|
||||
image?: { small?: string; thumbnail?: string; large?: string };
|
||||
};
|
||||
performer?: { name: string };
|
||||
hires_streamable?: boolean;
|
||||
maximum_bit_depth?: number;
|
||||
maximum_sampling_rate?: number;
|
||||
}
|
||||
|
||||
interface Artist {
|
||||
id: number;
|
||||
name: string;
|
||||
image?: { small?: string; thumbnail?: string; large?: string };
|
||||
albums_count?: number;
|
||||
}
|
||||
|
||||
interface SearchResults<T> {
|
||||
items: T[];
|
||||
total: number;
|
||||
offset: number;
|
||||
limit: number;
|
||||
}
|
||||
|
||||
let query = $state('');
|
||||
let activeTab = $state<'albums' | 'tracks' | 'artists'>('albums');
|
||||
let isSearching = $state(false);
|
||||
let searchError = $state<string | null>(null);
|
||||
|
||||
let albumResults = $state<SearchResults<Album> | null>(null);
|
||||
let trackResults = $state<SearchResults<Track> | null>(null);
|
||||
let artistResults = $state<SearchResults<Artist> | null>(null);
|
||||
|
||||
let searchTimeout: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
function debounceSearch() {
|
||||
if (searchTimeout) clearTimeout(searchTimeout);
|
||||
if (query.trim().length < 2) {
|
||||
albumResults = null;
|
||||
trackResults = null;
|
||||
artistResults = null;
|
||||
return;
|
||||
}
|
||||
searchTimeout = setTimeout(() => performSearch(), 300);
|
||||
}
|
||||
|
||||
async function performSearch() {
|
||||
if (!query.trim()) return;
|
||||
|
||||
isSearching = true;
|
||||
searchError = null;
|
||||
|
||||
try {
|
||||
// Search based on active tab
|
||||
if (activeTab === 'albums') {
|
||||
albumResults = await invoke<SearchResults<Album>>('search_albums', {
|
||||
query: query.trim(),
|
||||
limit: 20
|
||||
});
|
||||
console.log('Album results:', albumResults);
|
||||
} else if (activeTab === 'tracks') {
|
||||
trackResults = await invoke<SearchResults<Track>>('search_tracks', {
|
||||
query: query.trim(),
|
||||
limit: 20
|
||||
});
|
||||
console.log('Track results:', trackResults);
|
||||
} else if (activeTab === 'artists') {
|
||||
artistResults = await invoke<SearchResults<Artist>>('search_artists', {
|
||||
query: query.trim(),
|
||||
limit: 20
|
||||
});
|
||||
console.log('Artist results:', artistResults);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Search error:', err);
|
||||
searchError = String(err);
|
||||
} finally {
|
||||
isSearching = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleTabChange(tab: typeof activeTab) {
|
||||
activeTab = tab;
|
||||
if (query.trim().length >= 2) {
|
||||
performSearch();
|
||||
}
|
||||
}
|
||||
|
||||
function formatDuration(seconds: number): string {
|
||||
const mins = Math.floor(seconds / 60);
|
||||
const secs = Math.floor(seconds % 60);
|
||||
return `${mins}:${secs.toString().padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
function getQualityLabel(track: Track | Album): string {
|
||||
if (track.hires_streamable && track.maximum_bit_depth && track.maximum_sampling_rate) {
|
||||
return `${track.maximum_bit_depth}bit/${track.maximum_sampling_rate}kHz`;
|
||||
}
|
||||
return 'CD Quality';
|
||||
}
|
||||
|
||||
function getAlbumArtwork(album: Album): string {
|
||||
return album.image?.large || album.image?.thumbnail || album.image?.small || '';
|
||||
}
|
||||
|
||||
function getTrackArtwork(track: Track): string {
|
||||
return track.album?.image?.large || track.album?.image?.thumbnail || track.album?.image?.small || '';
|
||||
}
|
||||
|
||||
function getArtistImage(artist: Artist): string {
|
||||
return artist.image?.large || artist.image?.thumbnail || artist.image?.small || '';
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="search-view">
|
||||
<!-- Search Header -->
|
||||
<div class="search-header">
|
||||
<h1>Search</h1>
|
||||
<div class="search-input-container">
|
||||
<Search size={20} class="search-icon" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search for albums, tracks, or artists..."
|
||||
bind:value={query}
|
||||
oninput={debounceSearch}
|
||||
class="search-input"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tabs -->
|
||||
<div class="tabs">
|
||||
<button
|
||||
class="tab"
|
||||
class:active={activeTab === 'albums'}
|
||||
onclick={() => handleTabChange('albums')}
|
||||
>
|
||||
<Disc3 size={18} />
|
||||
<span>Albums</span>
|
||||
{#if albumResults}
|
||||
<span class="count">{albumResults.total}</span>
|
||||
{/if}
|
||||
</button>
|
||||
<button
|
||||
class="tab"
|
||||
class:active={activeTab === 'tracks'}
|
||||
onclick={() => handleTabChange('tracks')}
|
||||
>
|
||||
<Music size={18} />
|
||||
<span>Tracks</span>
|
||||
{#if trackResults}
|
||||
<span class="count">{trackResults.total}</span>
|
||||
{/if}
|
||||
</button>
|
||||
<button
|
||||
class="tab"
|
||||
class:active={activeTab === 'artists'}
|
||||
onclick={() => handleTabChange('artists')}
|
||||
>
|
||||
<Mic2 size={18} />
|
||||
<span>Artists</span>
|
||||
{#if artistResults}
|
||||
<span class="count">{artistResults.total}</span>
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Results -->
|
||||
<div class="results">
|
||||
{#if isSearching}
|
||||
<div class="loading">
|
||||
<div class="spinner"></div>
|
||||
<p>Searching...</p>
|
||||
</div>
|
||||
{:else if searchError}
|
||||
<div class="error">
|
||||
<p>Search failed</p>
|
||||
<p class="error-detail">{searchError}</p>
|
||||
</div>
|
||||
{:else if !query.trim()}
|
||||
<div class="empty-state">
|
||||
<Search size={48} />
|
||||
<p>Start typing to search Qobuz</p>
|
||||
</div>
|
||||
{:else if activeTab === 'albums' && albumResults}
|
||||
{#if albumResults.items.length === 0}
|
||||
<div class="no-results">No albums found for "{query}"</div>
|
||||
{:else}
|
||||
<div class="albums-grid">
|
||||
{#each albumResults.items as album}
|
||||
<AlbumCard
|
||||
artwork={getAlbumArtwork(album)}
|
||||
title={album.title}
|
||||
artist={album.artist?.name || 'Unknown Artist'}
|
||||
quality={getQualityLabel(album)}
|
||||
onclick={() => onAlbumClick?.(album.id)}
|
||||
/>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
{:else if activeTab === 'tracks' && trackResults}
|
||||
{#if trackResults.items.length === 0}
|
||||
<div class="no-results">No tracks found for "{query}"</div>
|
||||
{:else}
|
||||
<div class="tracks-list">
|
||||
{#each trackResults.items as track, index}
|
||||
<button
|
||||
class="track-row"
|
||||
onclick={() => onTrackPlay?.(track)}
|
||||
>
|
||||
<div class="track-number">{index + 1}</div>
|
||||
{#if failedTrackImages.has(track.id) || !getTrackArtwork(track)}
|
||||
<div class="track-artwork-placeholder">
|
||||
<Music size={20} />
|
||||
</div>
|
||||
{:else}
|
||||
<img src={getTrackArtwork(track)} alt={track.title} class="track-artwork" onerror={() => handleTrackImageError(track.id)} />
|
||||
{/if}
|
||||
<div class="track-info">
|
||||
<div class="track-title">{track.title}</div>
|
||||
<div class="track-artist">{track.performer?.name || 'Unknown Artist'}</div>
|
||||
</div>
|
||||
<div class="track-quality">{getQualityLabel(track)}</div>
|
||||
<div class="track-duration">{formatDuration(track.duration)}</div>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
{:else if activeTab === 'artists' && artistResults}
|
||||
{#if artistResults.items.length === 0}
|
||||
<div class="no-results">No artists found for "{query}"</div>
|
||||
{:else}
|
||||
<div class="artists-grid">
|
||||
{#each artistResults.items as artist}
|
||||
<div class="artist-card">
|
||||
{#if failedArtistImages.has(artist.id) || !getArtistImage(artist)}
|
||||
<div class="artist-image-placeholder">
|
||||
<User size={40} />
|
||||
</div>
|
||||
{:else}
|
||||
<img src={getArtistImage(artist)} alt={artist.name} class="artist-image" onerror={() => handleArtistImageError(artist.id)} />
|
||||
{/if}
|
||||
<div class="artist-name">{artist.name}</div>
|
||||
{#if artist.albums_count}
|
||||
<div class="artist-albums">{artist.albums_count} albums</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.search-view {
|
||||
width: 100%;
|
||||
padding-bottom: 24px;
|
||||
}
|
||||
|
||||
.search-header {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.search-header h1 {
|
||||
font-size: 32px;
|
||||
font-weight: 700;
|
||||
color: var(--text-primary);
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.search-input-container {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.search-input-container :global(.search-icon) {
|
||||
position: absolute;
|
||||
left: 16px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.search-input {
|
||||
width: 100%;
|
||||
height: 52px;
|
||||
padding: 0 16px 0 48px;
|
||||
background-color: var(--bg-secondary);
|
||||
border: 1px solid var(--bg-tertiary);
|
||||
border-radius: 12px;
|
||||
font-size: 16px;
|
||||
color: var(--text-primary);
|
||||
outline: none;
|
||||
transition: border-color 150ms ease;
|
||||
}
|
||||
|
||||
.search-input:focus {
|
||||
border-color: var(--accent-primary);
|
||||
}
|
||||
|
||||
.search-input::placeholder {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.tabs {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-bottom: 24px;
|
||||
border-bottom: 1px solid var(--bg-tertiary);
|
||||
padding-bottom: 16px;
|
||||
}
|
||||
|
||||
.tab {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 10px 16px;
|
||||
background: none;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
color: var(--text-muted);
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all 150ms ease;
|
||||
}
|
||||
|
||||
.tab:hover {
|
||||
color: var(--text-primary);
|
||||
background-color: var(--bg-tertiary);
|
||||
}
|
||||
|
||||
.tab.active {
|
||||
color: var(--text-primary);
|
||||
background-color: var(--accent-primary);
|
||||
}
|
||||
|
||||
.tab .count {
|
||||
padding: 2px 8px;
|
||||
background-color: rgba(255, 255, 255, 0.2);
|
||||
border-radius: 12px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.results {
|
||||
min-height: 300px;
|
||||
}
|
||||
|
||||
.loading, .empty-state, .error, .no-results {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 64px 0;
|
||||
color: var(--text-muted);
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: #ff6b6b;
|
||||
}
|
||||
|
||||
.error-detail {
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border: 3px solid var(--bg-tertiary);
|
||||
border-top-color: var(--accent-primary);
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.albums-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
.tracks-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.track-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
padding: 12px 16px;
|
||||
background: none;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: background-color 150ms ease;
|
||||
width: 100%;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.track-row:hover {
|
||||
background-color: var(--bg-tertiary);
|
||||
}
|
||||
|
||||
.track-number {
|
||||
width: 32px;
|
||||
font-size: 14px;
|
||||
color: var(--text-muted);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.track-artwork {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 4px;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.track-artwork-placeholder {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 4px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: linear-gradient(135deg, var(--bg-tertiary) 0%, var(--bg-secondary) 100%);
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.track-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.track-title {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--text-primary);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.track-artist {
|
||||
font-size: 13px;
|
||||
color: var(--text-muted);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.track-quality {
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
padding: 4px 8px;
|
||||
background-color: var(--bg-tertiary);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.track-duration {
|
||||
font-size: 13px;
|
||||
color: var(--text-muted);
|
||||
font-family: var(--font-mono);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.artists-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
.artist-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
padding: 16px;
|
||||
background-color: var(--bg-secondary);
|
||||
border-radius: 12px;
|
||||
cursor: pointer;
|
||||
transition: background-color 150ms ease;
|
||||
}
|
||||
|
||||
.artist-card:hover {
|
||||
background-color: var(--bg-tertiary);
|
||||
}
|
||||
|
||||
.artist-image {
|
||||
width: 120px;
|
||||
height: 120px;
|
||||
border-radius: 50%;
|
||||
object-fit: cover;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.artist-image-placeholder {
|
||||
width: 120px;
|
||||
height: 120px;
|
||||
border-radius: 50%;
|
||||
margin-bottom: 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: linear-gradient(135deg, var(--bg-tertiary) 0%, var(--bg-secondary) 100%);
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.artist-name {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--text-primary);
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.artist-albums {
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
</style>
|
||||
@@ -84,7 +84,7 @@
|
||||
<div class="setting-row">
|
||||
<div class="label-with-tooltip">
|
||||
<span class="setting-label">Exclusive Mode</span>
|
||||
<Tooltip text="Locks the audio device for exclusive use by QBZ-NIX for better quality" />
|
||||
<Tooltip text="Locks the audio device for exclusive use by QBZ for better quality" />
|
||||
</div>
|
||||
<Toggle enabled={exclusiveMode} onchange={(v) => (exclusiveMode = v)} />
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user