@@ -35,105 +35,65 @@ export default function TopItemList<T extends Item>({ data, separators, type, cl
3535
3636function ItemCard ( { item, type } : { item : Item ; type : "album" | "track" | "artist" } ) {
3737
38- const itemClasses = `flex items-center gap-2 hover:text-(--color-fg-secondary)`
39-
40- const navigate = useNavigate ( ) ;
41-
42- const handleItemClick = ( type : string , id : number ) => {
43- navigate ( `/${ type . toLowerCase ( ) } /${ id } ` ) ;
44- } ;
45-
46- const handleArtistClick = ( event : React . MouseEvent ) => {
47- // Stop the click from navigating to the album page
48- event . stopPropagation ( ) ;
49- } ;
50-
51- // Also stop keyboard events on the inner links from bubbling up
52- const handleArtistKeyDown = ( event : React . KeyboardEvent ) => {
53- event . stopPropagation ( ) ;
54- }
38+ const itemClasses = `flex items-center gap-2`
5539
5640 switch ( type ) {
5741 case "album" : {
5842 const album = item as Album ;
5943
60- const handleKeyDown = ( event : React . KeyboardEvent ) => {
61- if ( event . key === 'Enter' ) {
62- handleItemClick ( "album" , album . id ) ;
63- }
64- } ;
65-
6644 return (
67- < div style = { { fontSize : 12 } } >
68- < div
69- className = { itemClasses }
70- onClick = { ( ) => handleItemClick ( "album" , album . id ) }
71- onKeyDown = { handleKeyDown }
72- role = "link"
73- tabIndex = { 0 }
74- aria-label = { `View album: ${ album . title } ` }
75- style = { { cursor : 'pointer' } }
76- >
77- < img src = { imageUrl ( album . image , "small" ) } alt = { album . title } />
78- < div >
45+ < div style = { { fontSize : 12 } } className = { itemClasses } >
46+ < Link to = { `/album/${ album . id } ` } >
47+ < img loading = "lazy" src = { imageUrl ( album . image , "small" ) } alt = { album . title } className = "min-w-[48px]" />
48+ </ Link >
49+ < div >
50+ < Link to = { `/album/${ album . id } ` } className = "hover:text-(--color-fg-secondary)" >
7951 < span style = { { fontSize : 14 } } > { album . title } </ span >
80- < br />
81- { album . is_various_artists ?
82- < span className = "color-fg-secondary" > Various Artists</ span >
83- :
84- < div onClick = { handleArtistClick } onKeyDown = { handleArtistKeyDown } >
85- < ArtistLinks artists = { album . artists ? [ album . artists [ 0 ] ] : [ { id : 0 , name : 'Unknown Artist' } ] } />
86- </ div >
87- }
88- < div className = "color-fg-secondary" > { album . listen_count } plays</ div >
52+ </ Link >
53+ < br />
54+ { album . is_various_artists ?
55+ < span className = "color-fg-secondary" > Various Artists</ span >
56+ :
57+ < div >
58+ < ArtistLinks artists = { album . artists ? [ album . artists [ 0 ] ] : [ { id : 0 , name : 'Unknown Artist' } ] } />
8959 </ div >
60+ }
61+ < div className = "color-fg-secondary" > { album . listen_count } plays</ div >
9062 </ div >
9163 </ div >
9264 ) ;
9365 }
9466 case "track" : {
9567 const track = item as Track ;
96-
97- const handleKeyDown = ( event : React . KeyboardEvent ) => {
98- if ( event . key === 'Enter' ) {
99- handleItemClick ( "track" , track . id ) ;
100- }
101- } ;
10268
10369 return (
104- < div style = { { fontSize : 12 } } >
105- < div
106- className = { itemClasses }
107- onClick = { ( ) => handleItemClick ( "track" , track . id ) }
108- onKeyDown = { handleKeyDown }
109- role = "link"
110- tabIndex = { 0 }
111- aria-label = { `View track: ${ track . title } ` }
112- style = { { cursor : 'pointer' } }
113- >
114- < img src = { imageUrl ( track . image , "small" ) } alt = { track . title } />
70+ < div style = { { fontSize : 12 } } className = { itemClasses } >
71+ < Link to = { `/track/${ track . id } ` } >
72+ < img loading = "lazy" src = { imageUrl ( track . image , "small" ) } alt = { track . title } className = "min-w-[48px]" />
73+ </ Link >
11574 < div >
116- < span style = { { fontSize : 14 } } > { track . title } </ span >
75+ < Link to = { `/track/${ track . id } ` } className = "hover:text-(--color-fg-secondary)" >
76+ < span style = { { fontSize : 14 } } > { track . title } </ span >
77+ </ Link >
11778 < br />
118- < div onClick = { handleArtistClick } onKeyDown = { handleArtistKeyDown } >
79+ < div >
11980 < ArtistLinks artists = { track . artists || [ { id : 0 , Name : 'Unknown Artist' } ] } />
12081 </ div >
12182 < div className = "color-fg-secondary" > { track . listen_count } plays</ div >
12283 </ div >
123- </ div >
12484 </ div >
12585 ) ;
12686 }
12787 case "artist" : {
12888 const artist = item as Artist ;
12989 return (
13090 < div style = { { fontSize : 12 } } >
131- < Link className = { itemClasses + ' mt-1 mb-[6px]' } to = { `/artist/${ artist . id } ` } >
132- < img src = { imageUrl ( artist . image , "small" ) } alt = { artist . name } />
133- < div >
134- < span style = { { fontSize : 14 } } > { artist . name } </ span >
135- < div className = "color-fg-secondary" > { artist . listen_count } plays</ div >
136- </ div >
91+ < Link className = { itemClasses + ' mt-1 mb-[6px] hover:text-(--color-fg-secondary) ' } to = { `/artist/${ artist . id } ` } >
92+ < img loading = "lazy" src = { imageUrl ( artist . image , "small" ) } alt = { artist . name } className = "min-w-[48px]" />
93+ < div >
94+ < span style = { { fontSize : 14 } } > { artist . name } </ span >
95+ < div className = "color-fg-secondary" > { artist . listen_count } plays</ div >
96+ </ div >
13797 </ Link >
13898 </ div >
13999 ) ;
0 commit comments