feat: Convert Figma React UI to Svelte 5
- Add lucide-svelte for icons - Create app.css with theme CSS variables (Dark, Light, OLED, Warm) - Convert all React components to Svelte 5 using runes ($state, $derived, $effect, $props) - Implement core components: Sidebar, NowPlayingBar, NavigationItem, UserCard, AlbumCard, HorizontalScrollRow, HeroSection, TrackRow, Toggle, Dropdown, Tooltip, VolumeSlider - Implement view components: HomeView, SettingsView, AlbumDetailView - Implement overlay components: QueuePanel, FullScreenNowPlaying, FocusMode, Toast - Create main +page.svelte with routing, state management and keyboard shortcuts - All components use Svelte 5 snippets for component children patterns
This commit is contained in:
1 parent
ef92897d43
commit
cdfd3263de
23 files changed
+4512
-141
No files matched your search
+376
-139
@@ -1,156 +1,393 @@
|
||||
<script lang="ts">
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
let name = $state("");
|
||||
let greetMsg = $state("");
|
||||
// Components
|
||||
import Sidebar from '$lib/components/Sidebar.svelte';
|
||||
import NowPlayingBar from '$lib/components/NowPlayingBar.svelte';
|
||||
import Toast from '$lib/components/Toast.svelte';
|
||||
|
||||
async function greet(event: Event) {
|
||||
event.preventDefault();
|
||||
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
||||
greetMsg = await invoke("greet", { name });
|
||||
// Views
|
||||
import HomeView from '$lib/components/views/HomeView.svelte';
|
||||
import SettingsView from '$lib/components/views/SettingsView.svelte';
|
||||
import AlbumDetailView from '$lib/components/views/AlbumDetailView.svelte';
|
||||
|
||||
// Overlays
|
||||
import QueuePanel from '$lib/components/QueuePanel.svelte';
|
||||
import FullScreenNowPlaying from '$lib/components/FullScreenNowPlaying.svelte';
|
||||
import FocusMode from '$lib/components/FocusMode.svelte';
|
||||
|
||||
// Types
|
||||
interface Album {
|
||||
id: string;
|
||||
artwork: string;
|
||||
title: string;
|
||||
artist: string;
|
||||
}
|
||||
|
||||
interface Track {
|
||||
number: number;
|
||||
title: string;
|
||||
artist?: string;
|
||||
duration: string;
|
||||
quality?: string;
|
||||
}
|
||||
|
||||
interface AlbumDetail {
|
||||
artwork: string;
|
||||
title: string;
|
||||
artist: string;
|
||||
year: string;
|
||||
label: string;
|
||||
genre: string;
|
||||
quality: string;
|
||||
trackCount: number;
|
||||
duration: string;
|
||||
tracks: Track[];
|
||||
}
|
||||
|
||||
interface QueueTrack {
|
||||
id: string;
|
||||
artwork: string;
|
||||
title: string;
|
||||
artist: string;
|
||||
duration: string;
|
||||
}
|
||||
|
||||
// View State
|
||||
let activeView = $state<'home' | 'search' | 'library' | 'settings' | 'album'>('home');
|
||||
let viewHistory = $state<string[]>(['home']);
|
||||
let selectedAlbum = $state<AlbumDetail | null>(null);
|
||||
|
||||
// Overlay States
|
||||
let isQueueOpen = $state(false);
|
||||
let isFullScreenOpen = $state(false);
|
||||
let isFocusModeOpen = $state(false);
|
||||
|
||||
// Playback State
|
||||
let isPlaying = $state(false);
|
||||
let currentTime = $state(73);
|
||||
let duration = $state(245);
|
||||
let volume = $state(75);
|
||||
let isShuffle = $state(false);
|
||||
let repeatMode = $state<'off' | 'all' | 'one'>('off');
|
||||
let isFavorite = $state(false);
|
||||
|
||||
// Toast State
|
||||
let toast = $state<{ message: string; type: 'success' | 'error' | 'info' } | null>(null);
|
||||
|
||||
// Mock Data
|
||||
const mockAlbums: Album[] = [
|
||||
{ id: '1', artwork: 'https://picsum.photos/seed/album1/300/300', title: 'Midnight Dreams', artist: 'Luna Nova' },
|
||||
{ id: '2', artwork: 'https://picsum.photos/seed/album2/300/300', title: 'Electric Soul', artist: 'The Voltage' },
|
||||
{ id: '3', artwork: 'https://picsum.photos/seed/album3/300/300', title: 'Cosmic Journey', artist: 'Stellar Wind' },
|
||||
{ id: '4', artwork: 'https://picsum.photos/seed/album4/300/300', title: 'Urban Echoes', artist: 'City Lights' },
|
||||
{ id: '5', artwork: 'https://picsum.photos/seed/album5/300/300', title: 'Ocean Waves', artist: 'Deep Blue' },
|
||||
{ id: '6', artwork: 'https://picsum.photos/seed/album6/300/300', title: 'Mountain High', artist: 'Peak Sound' },
|
||||
{ id: '7', artwork: 'https://picsum.photos/seed/album7/300/300', title: 'Desert Storm', artist: 'Sand Dunes' },
|
||||
{ id: '8', artwork: 'https://picsum.photos/seed/album8/300/300', title: 'Forest Tales', artist: 'Green Echo' },
|
||||
];
|
||||
|
||||
const mockAlbumDetail: AlbumDetail = {
|
||||
artwork: 'https://picsum.photos/seed/album1/500/500',
|
||||
title: 'Midnight Dreams',
|
||||
artist: 'Luna Nova',
|
||||
year: '2024',
|
||||
label: 'Stellar Records',
|
||||
genre: 'Electronic',
|
||||
quality: '24-Bit / 96 kHz',
|
||||
trackCount: 12,
|
||||
duration: '48:32',
|
||||
tracks: [
|
||||
{ number: 1, title: 'Moonrise', duration: '4:23', quality: 'Hi-Res' },
|
||||
{ number: 2, title: 'Starlight Serenade', duration: '3:45', quality: 'Hi-Res' },
|
||||
{ number: 3, title: 'Night Sky', duration: '5:12', quality: 'Hi-Res' },
|
||||
{ number: 4, title: 'Celestial Dance', duration: '4:01', quality: 'Hi-Res' },
|
||||
{ number: 5, title: 'Lunar Eclipse', duration: '3:56', quality: 'Hi-Res' },
|
||||
{ number: 6, title: 'Cosmic Dust', duration: '4:33', quality: 'Hi-Res' },
|
||||
{ number: 7, title: 'Nebula Dreams', duration: '5:08', quality: 'Hi-Res' },
|
||||
{ number: 8, title: 'Aurora', duration: '3:42', quality: 'Hi-Res' },
|
||||
{ number: 9, title: 'Twilight Zone', duration: '4:15', quality: 'Hi-Res' },
|
||||
{ number: 10, title: 'Midnight Hour', duration: '3:58', quality: 'Hi-Res' },
|
||||
{ number: 11, title: 'Dream Sequence', duration: '4:47', quality: 'Hi-Res' },
|
||||
{ number: 12, title: 'Dawn Breaking', duration: '4:12', quality: 'Hi-Res' },
|
||||
],
|
||||
};
|
||||
|
||||
const currentTrack: QueueTrack = {
|
||||
id: 'current',
|
||||
artwork: 'https://picsum.photos/seed/album1/300/300',
|
||||
title: 'Moonrise',
|
||||
artist: 'Luna Nova',
|
||||
duration: '4:23',
|
||||
};
|
||||
|
||||
const upcomingTracks: QueueTrack[] = [
|
||||
{ id: '2', artwork: 'https://picsum.photos/seed/album1/300/300', title: 'Starlight Serenade', artist: 'Luna Nova', duration: '3:45' },
|
||||
{ id: '3', artwork: 'https://picsum.photos/seed/album1/300/300', title: 'Night Sky', artist: 'Luna Nova', duration: '5:12' },
|
||||
{ id: '4', artwork: 'https://picsum.photos/seed/album1/300/300', title: 'Celestial Dance', artist: 'Luna Nova', duration: '4:01' },
|
||||
];
|
||||
|
||||
// View Types
|
||||
type ViewType = 'home' | 'search' | 'library' | 'settings' | 'album';
|
||||
|
||||
// Navigation Functions
|
||||
function navigateTo(view: string) {
|
||||
const typedView = view as ViewType;
|
||||
if (typedView !== activeView) {
|
||||
viewHistory = [...viewHistory, typedView];
|
||||
activeView = typedView;
|
||||
}
|
||||
}
|
||||
|
||||
function goBack() {
|
||||
if (viewHistory.length > 1) {
|
||||
viewHistory = viewHistory.slice(0, -1);
|
||||
activeView = viewHistory[viewHistory.length - 1] as typeof activeView;
|
||||
if (activeView !== 'album') {
|
||||
selectedAlbum = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleAlbumClick(albumId: string) {
|
||||
selectedAlbum = mockAlbumDetail;
|
||||
navigateTo('album');
|
||||
}
|
||||
|
||||
// Playback Functions
|
||||
function togglePlay() {
|
||||
isPlaying = !isPlaying;
|
||||
}
|
||||
|
||||
function handleSeek(time: number) {
|
||||
currentTime = Math.max(0, Math.min(duration, time));
|
||||
}
|
||||
|
||||
function handleVolumeChange(newVolume: number) {
|
||||
volume = Math.max(0, Math.min(100, newVolume));
|
||||
}
|
||||
|
||||
function toggleShuffle() {
|
||||
isShuffle = !isShuffle;
|
||||
showToast(isShuffle ? 'Shuffle enabled' : 'Shuffle disabled', 'info');
|
||||
}
|
||||
|
||||
function toggleRepeat() {
|
||||
if (repeatMode === 'off') repeatMode = 'all';
|
||||
else if (repeatMode === 'all') repeatMode = 'one';
|
||||
else repeatMode = 'off';
|
||||
|
||||
const messages = { off: 'Repeat off', all: 'Repeat all', one: 'Repeat one' };
|
||||
showToast(messages[repeatMode], 'info');
|
||||
}
|
||||
|
||||
function toggleFavorite() {
|
||||
isFavorite = !isFavorite;
|
||||
showToast(isFavorite ? 'Added to favorites' : 'Removed from favorites', 'success');
|
||||
}
|
||||
|
||||
// Toast Function
|
||||
function showToast(message: string, type: 'success' | 'error' | 'info' = 'info') {
|
||||
toast = { message, type };
|
||||
}
|
||||
|
||||
function hideToast() {
|
||||
toast = null;
|
||||
}
|
||||
|
||||
// Keyboard Shortcuts
|
||||
function handleKeydown(e: KeyboardEvent) {
|
||||
// Don't trigger shortcuts when typing in inputs
|
||||
if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (e.key) {
|
||||
case ' ':
|
||||
e.preventDefault();
|
||||
togglePlay();
|
||||
break;
|
||||
case 'f':
|
||||
if (!e.ctrlKey && !e.metaKey) {
|
||||
isFocusModeOpen = !isFocusModeOpen;
|
||||
}
|
||||
break;
|
||||
case 'q':
|
||||
isQueueOpen = !isQueueOpen;
|
||||
break;
|
||||
case 'Escape':
|
||||
if (isFocusModeOpen) isFocusModeOpen = false;
|
||||
else if (isFullScreenOpen) isFullScreenOpen = false;
|
||||
else if (isQueueOpen) isQueueOpen = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
document.addEventListener('keydown', handleKeydown);
|
||||
return () => document.removeEventListener('keydown', handleKeydown);
|
||||
});
|
||||
</script>
|
||||
|
||||
<main class="container">
|
||||
<h1>Welcome to Tauri + Svelte</h1>
|
||||
<div class="app">
|
||||
<!-- Sidebar -->
|
||||
<Sidebar
|
||||
{activeView}
|
||||
onNavigate={navigateTo}
|
||||
onSettingsClick={() => navigateTo('settings')}
|
||||
/>
|
||||
|
||||
<div class="row">
|
||||
<a href="https://vite.dev" target="_blank">
|
||||
<img src="/vite.svg" class="logo vite" alt="Vite Logo" />
|
||||
</a>
|
||||
<a href="https://tauri.app" target="_blank">
|
||||
<img src="/tauri.svg" class="logo tauri" alt="Tauri Logo" />
|
||||
</a>
|
||||
<a href="https://svelte.dev" target="_blank">
|
||||
<img src="/svelte.svg" class="logo svelte-kit" alt="SvelteKit Logo" />
|
||||
</a>
|
||||
</div>
|
||||
<p>Click on the Tauri, Vite, and SvelteKit logos to learn more.</p>
|
||||
<!-- Main Content -->
|
||||
<main class="main-content">
|
||||
{#if activeView === 'home'}
|
||||
<HomeView
|
||||
recentAlbums={mockAlbums}
|
||||
recommendedAlbums={mockAlbums.slice().reverse()}
|
||||
newReleases={mockAlbums.slice(2, 6)}
|
||||
onAlbumClick={handleAlbumClick}
|
||||
/>
|
||||
{:else if activeView === 'settings'}
|
||||
<SettingsView />
|
||||
{:else if activeView === 'album' && selectedAlbum}
|
||||
<AlbumDetailView
|
||||
album={selectedAlbum}
|
||||
onBack={goBack}
|
||||
/>
|
||||
{:else if activeView === 'search'}
|
||||
<div class="placeholder-view">
|
||||
<h1>Search</h1>
|
||||
<p>Search functionality coming soon...</p>
|
||||
</div>
|
||||
{:else if activeView === 'library'}
|
||||
<div class="placeholder-view">
|
||||
<h1>Library</h1>
|
||||
<p>Your library will appear here...</p>
|
||||
</div>
|
||||
{/if}
|
||||
</main>
|
||||
|
||||
<form class="row" onsubmit={greet}>
|
||||
<input id="greet-input" placeholder="Enter a name..." bind:value={name} />
|
||||
<button type="submit">Greet</button>
|
||||
</form>
|
||||
<p>{greetMsg}</p>
|
||||
</main>
|
||||
<!-- Now Playing Bar -->
|
||||
<NowPlayingBar
|
||||
artwork={currentTrack.artwork}
|
||||
trackTitle={currentTrack.title}
|
||||
artist={currentTrack.artist}
|
||||
{isPlaying}
|
||||
onTogglePlay={togglePlay}
|
||||
{currentTime}
|
||||
{duration}
|
||||
onSeek={handleSeek}
|
||||
{volume}
|
||||
onVolumeChange={handleVolumeChange}
|
||||
{isShuffle}
|
||||
onToggleShuffle={toggleShuffle}
|
||||
{repeatMode}
|
||||
onToggleRepeat={toggleRepeat}
|
||||
{isFavorite}
|
||||
onToggleFavorite={toggleFavorite}
|
||||
onOpenQueue={() => (isQueueOpen = true)}
|
||||
onOpenFullScreen={() => (isFullScreenOpen = true)}
|
||||
/>
|
||||
|
||||
<!-- Queue Panel -->
|
||||
<QueuePanel
|
||||
isOpen={isQueueOpen}
|
||||
onClose={() => (isQueueOpen = false)}
|
||||
{currentTrack}
|
||||
{upcomingTracks}
|
||||
onClearQueue={() => showToast('Queue cleared', 'info')}
|
||||
onSaveAsPlaylist={() => showToast('Saved as playlist', 'success')}
|
||||
/>
|
||||
|
||||
<!-- Full Screen Now Playing -->
|
||||
<FullScreenNowPlaying
|
||||
isOpen={isFullScreenOpen}
|
||||
onClose={() => (isFullScreenOpen = false)}
|
||||
artwork={currentTrack.artwork}
|
||||
trackTitle={currentTrack.title}
|
||||
artist={currentTrack.artist}
|
||||
album="Midnight Dreams"
|
||||
quality="24-Bit / 96 kHz"
|
||||
qualityLevel={4}
|
||||
{isPlaying}
|
||||
onTogglePlay={togglePlay}
|
||||
{currentTime}
|
||||
{duration}
|
||||
onSeek={handleSeek}
|
||||
{volume}
|
||||
onVolumeChange={handleVolumeChange}
|
||||
{isShuffle}
|
||||
onToggleShuffle={toggleShuffle}
|
||||
{repeatMode}
|
||||
onToggleRepeat={toggleRepeat}
|
||||
{isFavorite}
|
||||
onToggleFavorite={toggleFavorite}
|
||||
onOpenQueue={() => {
|
||||
isFullScreenOpen = false;
|
||||
isQueueOpen = true;
|
||||
}}
|
||||
onOpenFocusMode={() => {
|
||||
isFullScreenOpen = false;
|
||||
isFocusModeOpen = true;
|
||||
}}
|
||||
/>
|
||||
|
||||
<!-- Focus Mode -->
|
||||
<FocusMode
|
||||
isOpen={isFocusModeOpen}
|
||||
onClose={() => (isFocusModeOpen = false)}
|
||||
artwork={currentTrack.artwork}
|
||||
trackTitle={currentTrack.title}
|
||||
artist={currentTrack.artist}
|
||||
{isPlaying}
|
||||
onTogglePlay={togglePlay}
|
||||
{currentTime}
|
||||
{duration}
|
||||
onSeek={handleSeek}
|
||||
/>
|
||||
|
||||
<!-- Toast -->
|
||||
{#if toast}
|
||||
<Toast
|
||||
message={toast.message}
|
||||
type={toast.type}
|
||||
onClose={hideToast}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.logo.vite:hover {
|
||||
filter: drop-shadow(0 0 2em #747bff);
|
||||
}
|
||||
|
||||
.logo.svelte-kit:hover {
|
||||
filter: drop-shadow(0 0 2em #ff3e00);
|
||||
}
|
||||
|
||||
:root {
|
||||
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
font-weight: 400;
|
||||
|
||||
color: #0f0f0f;
|
||||
background-color: #f6f6f6;
|
||||
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
}
|
||||
|
||||
.container {
|
||||
margin: 0;
|
||||
padding-top: 10vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 6em;
|
||||
padding: 1.5em;
|
||||
will-change: filter;
|
||||
transition: 0.75s;
|
||||
}
|
||||
|
||||
.logo.tauri:hover {
|
||||
filter: drop-shadow(0 0 2em #24c8db);
|
||||
}
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: 500;
|
||||
color: #646cff;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #535bf2;
|
||||
}
|
||||
|
||||
h1 {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
input,
|
||||
button {
|
||||
border-radius: 8px;
|
||||
border: 1px solid transparent;
|
||||
padding: 0.6em 1.2em;
|
||||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
font-family: inherit;
|
||||
color: #0f0f0f;
|
||||
background-color: #ffffff;
|
||||
transition: border-color 0.25s;
|
||||
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
button {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
border-color: #396cd8;
|
||||
}
|
||||
button:active {
|
||||
border-color: #396cd8;
|
||||
background-color: #e8e8e8;
|
||||
}
|
||||
|
||||
input,
|
||||
button {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
#greet-input {
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
color: #f6f6f6;
|
||||
background-color: #2f2f2f;
|
||||
.app {
|
||||
display: flex;
|
||||
height: 100vh;
|
||||
overflow: hidden;
|
||||
background-color: var(--bg-primary);
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #24c8db;
|
||||
.main-content {
|
||||
flex: 1;
|
||||
margin-left: 240px;
|
||||
margin-bottom: 80px;
|
||||
overflow-y: auto;
|
||||
padding: 24px 32px;
|
||||
}
|
||||
|
||||
input,
|
||||
button {
|
||||
color: #ffffff;
|
||||
background-color: #0f0f0f98;
|
||||
.placeholder-view {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
button:active {
|
||||
background-color: #0f0f0f69;
|
||||
}
|
||||
}
|
||||
|
||||
.placeholder-view h1 {
|
||||
font-size: 32px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.placeholder-view p {
|
||||
font-size: 16px;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user