refactor: use track instead of song

This commit is contained in:
2024-11-26 22:10:21 +01:00
parent 9fefdf721a
commit 31f31ec2d9
9 changed files with 27 additions and 32 deletions

View File

@@ -27,14 +27,14 @@
<Sidebar.GroupLabel>Library</Sidebar.GroupLabel> <Sidebar.GroupLabel>Library</Sidebar.GroupLabel>
<Sidebar.Menu> <Sidebar.Menu>
<Sidebar.MenuItem> <Sidebar.MenuItem>
<Sidebar.MenuButton isActive={$page.url.pathname === '/songs'} class="transition-all"> <Sidebar.MenuButton isActive={$page.url.pathname === '/tracks'} class="transition-all">
{#snippet tooltipContent()} {#snippet tooltipContent()}
Songs Tracks
{/snippet} {/snippet}
{#snippet child({ props })} {#snippet child({ props })}
<a href="/songs" {...props}> <a href="/tracks" {...props}>
<Music2 /> <Music2 />
<span>Songs</span> <span>Tracks</span>
</a> </a>
{/snippet} {/snippet}
</Sidebar.MenuButton> </Sidebar.MenuButton>

View File

@@ -149,7 +149,7 @@
<Separator class="my-1" /> <Separator class="my-1" />
<div class="flex h-full flex-col gap-1 overflow-y-auto pr-3"> <div class="flex h-full flex-col gap-1 overflow-y-auto pr-3">
{#each [] as _song, i} {#each [] as _track, i}
<button <button
class="flex flex-row items-center gap-2 rounded-lg px-3 py-2 transition-all hover:bg-secondary" class="flex flex-row items-center gap-2 rounded-lg px-3 py-2 transition-all hover:bg-secondary"
onclick={() => skipToQueueIndex(i)} onclick={() => skipToQueueIndex(i)}
@@ -165,12 +165,12 @@
<p <p
class="w-full self-start overflow-hidden text-ellipsis text-nowrap text-left text-sm text-foreground/80" class="w-full self-start overflow-hidden text-ellipsis text-nowrap text-left text-sm text-foreground/80"
> >
Song name Track name
</p> </p>
<p <p
class="w-full self-start overflow-hidden text-left text-xs text-muted-foreground" class="w-full self-start overflow-hidden text-left text-xs text-muted-foreground"
> >
Song artist Track artist
</p> </p>
</div> </div>
</button> </button>

View File

@@ -4,19 +4,19 @@
import { getPlayerState } from '$lib/player.svelte'; import { getPlayerState } from '$lib/player.svelte';
// import { AudioLines } from 'lucide-svelte'; // import { AudioLines } from 'lucide-svelte';
import type { Song } from '$lib/song';
import { AudioLines } from 'lucide-svelte'; import { AudioLines } from 'lucide-svelte';
import type { SubmitFunction } from '../../../routes/songs/[hash]/$types'; import type { SubmitFunction } from '../../../routes/tracks/[hash]/$types';
import type { Track } from '$lib/proto/library';
interface Props { interface Props {
song: Song; track: Track;
} }
let { song }: Props = $props(); let { track }: Props = $props();
const player = getPlayerState(); const player = getPlayerState();
const submitPlaySong: SubmitFunction = async () => { const submitPlayTrack: SubmitFunction = async () => {
return async ({ update, result }) => { return async ({ update, result }) => {
await update({ await update({
invalidateAll: false invalidateAll: false
@@ -34,27 +34,27 @@
<form <form
class="flex flex-col gap-3" class="flex flex-col gap-3"
method="POST" method="POST"
action="/songs/{song.hash}?/play" action="/tracks/{track.hash}?/play"
use:enhance={submitPlaySong} use:enhance={submitPlayTrack}
> >
<div class="relative"> <div class="relative">
<button type="submit" class="relative overflow-hidden rounded-lg"> <button type="submit" class="relative overflow-hidden rounded-lg">
<img <img
class="aspect-square w-auto transition-all duration-150 hover:scale-105 hover:saturate-150" class="aspect-square w-auto transition-all duration-150 hover:scale-105 hover:saturate-150"
src={getCoverUrl(song.hash)} src={getCoverUrl(track.hash)}
alt={song.name} alt={track.name}
/> />
</button> </button>
<div <div
class="absolute bottom-6 left-2 size-4 animate-pulse" class="absolute bottom-6 left-2 size-4 animate-pulse"
class:hidden={player.currentlyPlaying?.hash !== song.hash} class:hidden={player.currentlyPlaying?.hash !== track.hash}
> >
<AudioLines class="text-primary" /> <AudioLines class="text-primary" />
</div> </div>
</div> </div>
<div class="relative space-y-1 text-sm"> <div class="relative space-y-1 text-sm">
<h3 class="font-medium leading-none">{song.name}</h3> <h3 class="font-medium leading-none">{track.name}</h3>
<p class="text-xs text-muted-foreground">{song.artistName}</p> <p class="text-xs text-muted-foreground">{track.artistName}</p>
</div> </div>
</form> </form>

View File

@@ -1,3 +1,3 @@
export function getCoverUrl(songHash: string) { export function getCoverUrl(trackHash: string) {
return `http://localhost:39994/${songHash}.webp`; return `http://localhost:39994/${trackHash}.webp`;
} }

View File

@@ -1,6 +0,0 @@
export type Song = {
hash: string;
name: string;
artistName: string;
artistId: bigint;
};

View File

@@ -2,5 +2,5 @@ import type { LayoutServerLoad } from './$types';
export const load: LayoutServerLoad = async () => { export const load: LayoutServerLoad = async () => {
// const client = new PlayerClient(protoTransport); // const client = new PlayerClient(protoTransport);
// TODO: Get current song // TODO: Get current track
}; };

View File

@@ -1,3 +1,4 @@
import type { Track } from '$lib/proto/library';
import { LibraryClient } from '$lib/proto/library.client'; import { LibraryClient } from '$lib/proto/library.client';
import { protoTransport } from '../../hooks.server'; import { protoTransport } from '../../hooks.server';
import type { PageServerLoad } from './$types'; import type { PageServerLoad } from './$types';
@@ -15,6 +16,6 @@ export const load: PageServerLoad = async () => {
})); }));
return { return {
songs: tracks tracks: tracks as Track[]
}; };
}; };

View File

@@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
import SongListing from '$lib/components/groove/SongListing.svelte'; import TrackListing from '$lib/components/groove/TrackListing.svelte';
import type { PageServerData } from './$types'; import type { PageServerData } from './$types';
interface Props { interface Props {
@@ -12,7 +12,7 @@
<div <div
class="grid grid-cols-2 gap-4 sm:grid-cols-4 md:grid-cols-5 lg:grid-cols-6 xl:grid-cols-7 2xl:grid-cols-8" class="grid grid-cols-2 gap-4 sm:grid-cols-4 md:grid-cols-5 lg:grid-cols-6 xl:grid-cols-7 2xl:grid-cols-8"
> >
{#each data.songs as song} {#each data.tracks as track}
<SongListing {song} /> <TrackListing {track} />
{/each} {/each}
</div> </div>