diff --git a/.eslintrc.js b/.eslintrc.js index 19aae86..6959af7 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -57,5 +57,6 @@ module.exports = { 'comma-dangle': 0, 'no-confusing-arrow': 0, 'import/no-unresolved': 0, + 'operator-linebreak': 0, }, }; diff --git a/src/components/DetailsHeader.jsx b/src/components/DetailsHeader.jsx index e3aeff4..5874fd5 100644 --- a/src/components/DetailsHeader.jsx +++ b/src/components/DetailsHeader.jsx @@ -1,5 +1,44 @@ -const DetailsHeader = () => ( -
DetailsHeader
-); +import { Link } from 'react-router-dom'; + +const DetailsHeader = ({ artistId, artistData, songData }) => { + const artist = artistData?.artists[artistId].attributes; + + return ( +
+
+ +
+ art + +
+

+ {artistId ? artist.name : songData?.title} +

+ {!artistId && ( + +

+ {songData?.subtitle} +

+ + )} + +

+ {artistId ? artist?.genreNames[0] : songData?.genres?.primary} +

+
+
+ +
+
+ ); +}; export default DetailsHeader; diff --git a/src/components/RelatedSongs.jsx b/src/components/RelatedSongs.jsx index ff68ef5..b8d4892 100644 --- a/src/components/RelatedSongs.jsx +++ b/src/components/RelatedSongs.jsx @@ -1,5 +1,30 @@ -const RelatedSongs = () => ( -
Loader
+import SongBar from './SongBar'; + +const RelatedSongs = ({ + isPlaying, + activeSong, + data, + handlePlay, + handlePause, + artistId, +}) => ( +
+

Related Songs:

+
+ {data.map((song, i) => ( + + ))} +
+
); export default RelatedSongs; diff --git a/src/pages/SongDetails.jsx b/src/pages/SongDetails.jsx index 7eab91f..f565f59 100644 --- a/src/pages/SongDetails.jsx +++ b/src/pages/SongDetails.jsx @@ -1,3 +1,71 @@ -const SongDetails = () =>
SongDetails
; +import { useParams } from 'react-router-dom'; +import { useSelector, useDispatch } from 'react-redux'; + +import { DetailsHeader, Error, Loader, RelatedSongs } from '../components'; +import { setActiveSong, playPause } from '../redux/features/playerSlice'; +import { + useGetSongDetailsQuery, + useGetSongRelatedQuery, +} from '../redux/services/shazamCore'; + +const SongDetails = () => { + const dispatch = useDispatch(); + const { activeSong, isPlaying } = useSelector((state) => state.player); + const { songid } = useParams(); + const { data: songData, isFetching: isFetchingSongDetails } = + useGetSongDetailsQuery({ songid }); + const { + data: relatedSongs, + isFetch: isFetchingRelatedSongs, + error, + } = useGetSongRelatedQuery({ songid }); + + const handlePause = () => { + dispatch(playPause(false)); + }; + + const handlePlay = (song, i) => { + dispatch(setActiveSong({ song, data: relatedSongs, i })); + dispatch(playPause(true)); + }; + + if (isFetchingSongDetails || isFetchingRelatedSongs) { + return ; + } + + if (error) { + return ; + } + + return ( +
+ +
+

Lyrics:

+
+ {songData?.sections[1].type === 'LYRICS' ? ( + songData?.sections[1].text.map((line, i) => ( +

+ {line} +

+ )) + ) : ( +

+ Sorry, no lyrics found! +

+ )} +
+
+ + +
+ ); +}; export default SongDetails; diff --git a/src/redux/services/shazamCore.js b/src/redux/services/shazamCore.js index 607d8f4..4907eea 100644 --- a/src/redux/services/shazamCore.js +++ b/src/redux/services/shazamCore.js @@ -15,7 +15,17 @@ export const shazamCoreApi = createApi({ }), endpoints: (builder) => ({ getTopCharts: builder.query({ query: () => '/charts/world' }), + getSongDetails: builder.query({ + query: ({ songid }) => `/tracks/details?track_id=${songid}`, + }), + getSongRelated: builder.query({ + query: ({ songid }) => `/tracks/related?track_id=${songid}`, + }), }), }); -export const { useGetTopChartsQuery } = shazamCoreApi; +export const { + useGetTopChartsQuery, + useGetSongDetailsQuery, + useGetSongRelatedQuery, +} = shazamCoreApi;