1- import React , { FC , useEffect , useRef , useState } from "react" ;
1+ import React , { FC , useState } from "react" ;
22import { Album } from "../../interfaces/Album" ;
33import PlaylistIcon from "../../components/PlaylistIcon" ;
44import { RotatingBorderBox } from "../../components/RotatingBorderBox" ;
5- import Modal from "../../components/Modal" ;
6- import { Playlist } from "../../interfaces/Playlist" ;
7- import { addAlbumToPlaylist , startPlayback } from "../../api" ;
8- import { useModal } from "../../hooks/useModal" ;
9- import Button from "../../components/Button" ;
105
116interface AlbumContainerProps {
127 album : Album ;
13- contextPlaylist : Playlist
14- associatedPlaylists : Playlist [ ] ;
8+ onClick : ( album : Album ) => void ;
159 active ?: boolean ;
1610}
1711
1812export const AlbumContainer : FC < AlbumContainerProps > = ( {
1913 album,
20- contextPlaylist,
21- associatedPlaylists,
14+ onClick,
2215 active,
2316} ) => {
24- const ref = useRef < HTMLDivElement > ( null ) ;
25- useEffect ( ( ) => {
26- if ( active && ref . current ) {
27- ref . current . scrollIntoView ( { behavior : "smooth" , block : "center" } ) ;
28- }
29- } , [ active ] ) ;
3017 const [ showMoreInfo , setShowMoreInfo ] = useState ( false ) ;
31- const { isModalOpen, openModal, closeModal } = useModal ( ) ;
3218 return (
33- < >
34- < Modal isModalOpen = { isModalOpen } closeModal = { closeModal } >
35- < AlbumActionsModalContent
36- contextPlaylist = { contextPlaylist }
37- associatedPlaylists = { associatedPlaylists }
38- album = { album }
39- closeModal = { closeModal }
40- />
41- </ Modal >
4219 < div
43- className = { `group max-h-80 max-w-80 [perspective:1000px]` }
20+ className = { `group max-h-40 max-w-40 [perspective:1000px]` }
4421 onClick = { ( ) => {
4522 setShowMoreInfo ( ( current ) => ! current ) ;
23+ onClick ( album )
4624 } }
4725 >
4826 < RotatingBorderBox active = { active } >
4927 < div
50- ref = { ref }
5128 className = { `m-1 relative transition-all duration-500 [transform-style:preserve-3d] ${
5229 showMoreInfo && "[transform:rotateY(180deg)]"
5330 } `}
@@ -57,85 +34,12 @@ export const AlbumContainer: FC<AlbumContainerProps> = ({
5734 < div className = "absolute top-0 [transform:rotateY(180deg)] [backface-visibility:hidden]" >
5835 < div className = "flex flex-col space-y-2 m-2" >
5936 < div > { album . name } </ div >
60- < div >
61- { album . artists . map ( ( artist ) => artist . name ) . join ( ", " ) }
62- </ div >
63- < div > { album . genres } </ div >
64- < div > { album . label } </ div >
65- < div > { album . popularity } </ div >
66- < button
67- onClick = { ( e ) => {
68- e . stopPropagation ( ) ;
69- openModal ( ) ;
70- } }
71- >
72- Actions
73- </ button >
7437 </ div >
7538 </ div >
7639 ) }
7740 </ div >
7841 </ RotatingBorderBox >
7942 </ div >
80- </ >
81- ) ;
82- } ;
83-
84- interface AlbumActionsModalContentProps {
85- album : Album ;
86- contextPlaylist : Playlist
87- associatedPlaylists : Playlist [ ] ;
88- closeModal : ( ) => void ;
89- }
90- const AlbumActionsModalContent : FC < AlbumActionsModalContentProps > = ( {
91- album,
92- contextPlaylist,
93- associatedPlaylists,
94- closeModal,
95- } ) => {
96- const addAlbumToAssociatedPlaylist = ( targetPlaylist : Playlist ) : void => {
97- addAlbumToPlaylist ( targetPlaylist . id , album . id ) ;
98- closeModal ( ) ;
99- } ;
100- return (
101- < div >
102- < div className = "flex flex-row justify-between" >
103- < h2 className = "my-auto text-m" > Actions:</ h2 >
104- < button onClick = { closeModal } > X</ button >
105- </ div >
106- < div className = "flex flex-col my-2 space-y-2" >
107- { associatedPlaylists . map ( ( associatedPlaylist ) => (
108- < Button
109- onClick = { ( ) => addAlbumToAssociatedPlaylist ( associatedPlaylist ) }
110- key = { associatedPlaylist . id }
111- >
112- Add to { associatedPlaylist . name }
113- </ Button >
114- ) ) }
115- < Button
116- onClick = { ( ) => ( startPlayback ( { context_uri : contextPlaylist . uri , offset : { album_id : album . id } } ) ) }
117- >
118- Play Album
119- </ Button >
120- </ div >
121- </ div >
122- ) ;
123- } ;
124-
125- export const AlbumInfo : FC < AlbumContainerProps > = ( { album } ) => {
126- return (
127- < div className = "relative" >
128- < AlbumCover album = { album } blur />
129- < div className = "absolute top-0" >
130- < div className = "flex flex-col space-y-2 m-2" >
131- < div > { album . name } </ div >
132- < div > { album . artists . map ( ( artist ) => artist . name ) . join ( ", " ) } </ div >
133- < div > { album . genres } </ div >
134- < div > { album . label } </ div >
135- < div > { album . popularity } </ div >
136- </ div >
137- </ div >
138- </ div >
13943 ) ;
14044} ;
14145
0 commit comments