diff --git a/src/lib/components/Header.svelte b/src/lib/components/Header.svelte index 20ed9a1..78e70a1 100644 --- a/src/lib/components/Header.svelte +++ b/src/lib/components/Header.svelte @@ -2,6 +2,9 @@ import Avatar from './Avatar.svelte' import SegmentedController from './SegmentedController.svelte' import NavDropdown from './NavDropdown.svelte' + import { albumStream } from '$lib/stores/album-stream' + import { nowPlayingStream } from '$lib/stores/now-playing-stream' + import type { Album } from '$lib/types/lastfm' let scrollY = $state(0) // Smooth gradient opacity from 0 to 1 over the first 100px of scroll @@ -9,6 +12,36 @@ // Padding transition happens more quickly let paddingProgress = $derived(Math.min(scrollY / 50, 1)) + // Now playing state + let isHoveringAvatar = $state(false) + let currentlyPlayingAlbum = $state(null) + let isPlayingMusic = $state(false) + + // Subscribe to album updates + $effect(() => { + const unsubscribe = albumStream.subscribe((state) => { + const nowPlaying = state.albums.find((album) => album.isNowPlaying) + currentlyPlayingAlbum = nowPlaying || null + isPlayingMusic = !!nowPlaying + }) + + return unsubscribe + }) + + // Also check now playing stream for updates + $effect(() => { + const unsubscribe = nowPlayingStream.subscribe((state) => { + const hasNowPlaying = Array.from(state.updates.values()).some((update) => update.isNowPlaying) + if (!hasNowPlaying && currentlyPlayingAlbum) { + // Music stopped + currentlyPlayingAlbum = null + isPlayingMusic = false + } + }) + + return unsubscribe + }) + $effect(() => { let ticking = false @@ -30,6 +63,18 @@ window.addEventListener('scroll', handleScroll, { passive: true }) return () => window.removeEventListener('scroll', handleScroll) }) + + // Get the best available album artwork + function getAlbumArtwork(album: Album): string { + if (album.appleMusicData?.highResArtwork) { + // Use smaller size for the header + return album.appleMusicData.highResArtwork.replace('3000x3000', '100x100') + } + if (album.images.itunes) { + return album.images.itunes.replace('3000x3000', '100x100') + } + return album.images.large || album.images.medium || '' + }
- + isHoveringAvatar = true} + onmouseleave={() => isHoveringAvatar = false} + >