Commit 70de99de authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Home: songs render as a list with album art, not a card grid; clearer section headers

"New Songs" (was "Newly added") now reuses HomeSongRow instead of the square
HomeSongCard grid, so songs and albums read as genuinely different content
types at a glance (list vs. grid) rather than two visually-identical card
grids. Every section header now carries an icon + one-line description
(New Songs / New Albums / Suggestions) instead of just a bare label, so
Suggestions doesn't get confused for New Songs despite sharing the same row
shape. HomeSongCard is now unused and removed.
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
parent 23de29b2
import { Music2, Pause, Play } from 'lucide-react'
import type { HomeSong } from '../api/home'
import { useHomeSongPlayback } from '../hooks/useHomeSongPlayback'
/** A grid tile for the Home feed's "Newly added" section - same square-art-plus-caption shape
* as Library's AlbumCard, but every tile here plays on tap (own songs directly, someone
* else's via claim-then-play - see useHomeSongPlayback) rather than navigating anywhere. */
export function HomeSongCard({ song }: { song: HomeSong }) {
const { isCurrent, isPlaying, streamLoading, claiming, error, handlePlay } = useHomeSongPlayback(song)
const busy = claiming === 'play'
return (
<div className="flex min-w-0 flex-col gap-2">
<button
onClick={handlePlay}
disabled={busy}
aria-label={isCurrent && isPlaying ? `Pause ${song.title}` : `Play ${song.title}`}
className="group relative aspect-square w-full overflow-hidden rounded-xl border border-transparent transition-colors hover:border-outline-variant focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed"
>
{song.coverart ? (
<img src={song.coverart} alt="" loading="lazy" decoding="async" className="h-full w-full object-cover" />
) : (
<div className="flex h-full w-full items-center justify-center bg-surface-container-high text-on-surface-variant">
<Music2 size={28} strokeWidth={1.5} />
</div>
)}
<span
className={`absolute inset-0 flex items-center justify-center bg-black/50 text-white transition-opacity duration-150 ${
isCurrent || busy ? 'opacity-100' : 'opacity-100 sm:opacity-0 sm:group-hover:opacity-100'
}`}
>
{busy || (isCurrent && streamLoading) ? (
<span className="h-4 w-4 animate-spin rounded-full border-2 border-white/40 border-t-white" />
) : isCurrent && isPlaying ? (
<Pause size={20} strokeWidth={2} fill="currentColor" />
) : (
<Play size={20} strokeWidth={2} fill="currentColor" className="ml-0.5" />
)}
</span>
</button>
<div className="min-w-0">
<p className="truncate text-sm font-medium text-on-surface">{song.title}</p>
<p className="truncate text-xs text-on-surface-variant">
{song.artist}
{song.username ? ` · ${song.username}` : ''}
</p>
{error && <p className="truncate text-xs text-error">{error}</p>}
</div>
</div>
)
}
...@@ -5,12 +5,12 @@ import { usePlayer, type PlayableSong } from '../context/PlayerContext' ...@@ -5,12 +5,12 @@ import { usePlayer, type PlayableSong } from '../context/PlayerContext'
import { useAuth } from '../context/AuthContext' import { useAuth } from '../context/AuthContext'
import type { HomeSong } from '../api/home' import type { HomeSong } from '../api/home'
/** Shared by HomeSongCard and HomeSongRow (the two places a Home-feed song can be tapped) so /** Shared by HomeSongRow and HomeAlbumCard's expanded track list (the places a Home-feed song
* the claim-then-play logic isn't duplicated between them. A Home-feed song the caller already * can be tapped) so the claim-then-play logic isn't duplicated between them. A Home-feed song
* owns (`user_id === userId`) plays directly via its real library id; everyone else's goes * the caller already owns (`user_id === userId`) plays directly via its real library id;
* through the same claim-then-play mechanism SharedSongRow already uses for Library's shared * everyone else's goes through the same claim-then-play mechanism SharedSongRow already uses
* search results, since that id belongs to someone else's library row and can't be streamed * for Library's shared search results, since that id belongs to someone else's library row and
* until the caller has their own copy. */ * can't be streamed until the caller has their own copy. */
export function useHomeSongPlayback(song: HomeSong) { export function useHomeSongPlayback(song: HomeSong) {
const { userId } = useAuth() const { userId } = useAuth()
const { currentSong, isPlaying, isLoading: streamLoading, toggle } = usePlayer() const { currentSong, isPlaying, isLoading: streamLoading, toggle } = usePlayer()
......
...@@ -126,9 +126,9 @@ describe('Home', () => { ...@@ -126,9 +126,9 @@ describe('Home', () => {
renderHome() renderHome()
expect(await screen.findByText('Newly added')).toBeInTheDocument() expect(await screen.findByText('New Songs')).toBeInTheDocument()
expect(screen.getByText('My Own Track')).toBeInTheDocument() expect(screen.getByText('My Own Track')).toBeInTheDocument()
expect(screen.getByText('New albums')).toBeInTheDocument() expect(screen.getByText('New Albums')).toBeInTheDocument()
expect(screen.getByText('My Album')).toBeInTheDocument() expect(screen.getByText('My Album')).toBeInTheDocument()
expect(screen.getByText('Suggestions')).toBeInTheDocument() expect(screen.getByText('Suggestions')).toBeInTheDocument()
expect(screen.getByText("Someone Else's Track")).toBeInTheDocument() expect(screen.getByText("Someone Else's Track")).toBeInTheDocument()
......
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { Globe } from 'lucide-react' import { Disc3, Globe, ListMusic, Sparkles, type LucideIcon } from 'lucide-react'
import { getHomeFeed, type HomeAlbum, type HomeSong } from '../api/home' import { getHomeFeed, type HomeAlbum, type HomeSong } from '../api/home'
import { ApiError } from '../api/client' import { ApiError } from '../api/client'
import { Layout } from '../components/Layout' import { Layout } from '../components/Layout'
import { AddToPlaylistModal } from '../components/AddToPlaylistModal' import { AddToPlaylistModal } from '../components/AddToPlaylistModal'
import { HomeSongCard } from '../components/HomeSongCard'
import { HomeAlbumCard } from '../components/HomeAlbumCard' import { HomeAlbumCard } from '../components/HomeAlbumCard'
import { HomeSongRow } from '../components/HomeSongRow' import { HomeSongRow } from '../components/HomeSongRow'
import { SkeletonRow } from '../components/ui/Skeleton' import { SkeletonRow } from '../components/ui/Skeleton'
import { EmptyState } from '../components/ui/EmptyState' import { EmptyState } from '../components/ui/EmptyState'
/** Each section needs to read as a distinct kind of content at a glance, not just a different
* label - Songs and Suggestions are both row lists (same shape), so the icon+caption pairing
* is what actually tells them apart, while Albums gets a genuinely different shape (a cover-art
* grid) rather than just another list. */
function SectionHeader({ icon: Icon, title, description }: { icon: LucideIcon; title: string; description: string }) {
return (
<div className="mb-3 flex items-start gap-2">
<Icon size={16} strokeWidth={2} className="mt-0.5 shrink-0 text-primary" />
<div className="min-w-0">
<h2 className="text-xs font-semibold uppercase tracking-[0.1em] text-primary">{title}</h2>
<p className="text-xs text-on-surface-variant">{description}</p>
</div>
</div>
)
}
/** The new default landing page - everything here is global (every user's uploads), unlike the /** The new default landing page - everything here is global (every user's uploads), unlike the
* per-user Library page. `suggestions` is explicitly a placeholder algorithm for now, not real * per-user Library page. `suggestions` is explicitly a placeholder algorithm for now, not real
* personalization yet (see the backend's own comment in home.py). */ * personalization yet (see the backend's own comment in home.py). */
...@@ -50,18 +65,18 @@ export function Home() { ...@@ -50,18 +65,18 @@ export function Home() {
<div className="animate-content-enter"> <div className="animate-content-enter">
{latestSongs.length > 0 && ( {latestSongs.length > 0 && (
<div className="mb-8"> <div className="mb-8">
<h2 className="mb-3 text-xs font-semibold uppercase tracking-[0.1em] text-primary">Newly added</h2> <SectionHeader icon={ListMusic} title="New Songs" description="The latest tracks added across Stax, newest first." />
<div className="grid grid-cols-2 gap-3 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5"> <ul className="space-y-1">
{latestSongs.map((song) => ( {latestSongs.map((song) => (
<HomeSongCard key={song.id} song={song} /> <HomeSongRow key={song.id} song={song} onAddToPlaylist={setAddingSong} />
))} ))}
</div> </ul>
</div> </div>
)} )}
{newAlbums.length > 0 && ( {newAlbums.length > 0 && (
<div className="mb-8"> <div className="mb-8">
<h2 className="mb-3 text-xs font-semibold uppercase tracking-[0.1em] text-primary">New albums</h2> <SectionHeader icon={Disc3} title="New Albums" description="Full albums recently uploaded by Stax users." />
<div className="grid grid-cols-2 gap-3 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5"> <div className="grid grid-cols-2 gap-3 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5">
{newAlbums.map((album) => ( {newAlbums.map((album) => (
<HomeAlbumCard <HomeAlbumCard
...@@ -76,7 +91,11 @@ export function Home() { ...@@ -76,7 +91,11 @@ export function Home() {
{suggestions.length > 0 && ( {suggestions.length > 0 && (
<div> <div>
<h2 className="mb-2 text-xs font-semibold uppercase tracking-[0.1em] text-primary">Suggestions</h2> <SectionHeader
icon={Sparkles}
title="Suggestions"
description="A starting point, not personalized yet - a real algorithm is coming later."
/>
<ul className="space-y-1"> <ul className="space-y-1">
{suggestions.map((song) => ( {suggestions.map((song) => (
<HomeSongRow key={song.id} song={song} onAddToPlaylist={setAddingSong} /> <HomeSongRow key={song.id} song={song} onAddToPlaylist={setAddingSong} />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment