Skip to content

Commit

Permalink
songDetails related songs
Browse files Browse the repository at this point in the history
  • Loading branch information
TidbitsJS committed Sep 15, 2022
1 parent 849a13a commit 8b24dc7
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 22 deletions.
26 changes: 26 additions & 0 deletions src/components/RelatedSongs.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';

import SongBar from './SongBar';

const RelatedSongs = ({ data, artistId, isPlaying, activeSong, handlePauseClick, handlePlayClick }) => (
<div className="flex flex-col">
<h1 className="font-bold text-3xl text-white">Related Songs:</h1>

<div className="mt-6 w-full flex flex-col">
{data.map((song, i) => (
<SongBar
key={song.key}
song={song}
i={i}
artistId={artistId}
isPlaying={isPlaying}
activeSong={activeSong}
handlePauseClick={handlePauseClick}
handlePlayClick={handlePlayClick}
/>
))}
</div>
</div>
);

export default RelatedSongs;
2 changes: 2 additions & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import TopPlay from './TopPlay';
import ArtistCard from './ArtistCard';
import DetailsHeader from './DetailsHeader';
import SongBar from './SongBar';
import RelatedSongs from './RelatedSongs';

export {
TopPlay,
Expand All @@ -14,4 +15,5 @@ export {
ArtistCard,
DetailsHeader,
SongBar,
RelatedSongs,
};
31 changes: 10 additions & 21 deletions src/pages/ArtistDetails.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import { useParams } from 'react-router-dom';
import { useSelector, useDispatch } from 'react-redux';
import { DetailsHeader, SongBar } from '../components';
import { DetailsHeader, RelatedSongs } from '../components';

import { useFetchArtistDetailsQuery, useGetSongDetailsQuery } from '../redux/services/shazamCore';
import { setActiveSong, playPause } from '../redux/features/playerSlice';

const ArtistDetails = () => {
const { songid, id: artistId } = useParams();
const dispatch = useDispatch();
const { songid, id: artistId } = useParams();
const { activeSong, isPlaying } = useSelector((state) => state.player);
const { data: songData, isFetching: isFetchinSongDetails } = useGetSongDetailsQuery({ songid });
const {
Expand Down Expand Up @@ -44,25 +44,14 @@ const ArtistDetails = () => {
songData={songData}
/>

<div className="flex flex-col">
<h1 className="font-bold text-3xl text-white">Related Songs:</h1>

<div className="mt-6 w-full flex flex-col">
{artistData
&& Object.values(artistData?.songs).map((song, i) => (
<SongBar
key={song.key}
song={song}
i={i}
artistId={artistId}
isPlaying={isPlaying}
activeSong={activeSong}
handlePauseClick={handlePauseClick}
handlePlayClick={handlePlayClick}
/>
))}
</div>
</div>
<RelatedSongs
data={Object.values(artistData?.songs)}
artistId={artistId}
isPlaying={isPlaying}
activeSong={activeSong}
handlePauseClick={handlePauseClick}
handlePlayClick={handlePlayClick}
/>
</div>
);
};
Expand Down
25 changes: 24 additions & 1 deletion src/pages/SongDetails.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import React from 'react';
import { useParams } from 'react-router-dom';
import { DetailsHeader } from '../components';
import { useSelector, useDispatch } from 'react-redux';
import { DetailsHeader, RelatedSongs } from '../components';

import { setActiveSong, playPause } from '../redux/features/playerSlice';
import { useFetchArtistDetailsQuery, useGetSongDetailsQuery } from '../redux/services/shazamCore';

const SongDetails = () => {
const dispatch = useDispatch();
const { songid, id: artistId } = useParams();
const { activeSong, isPlaying } = useSelector((state) => state.player);
const { data: songData, isFetching: isFetchinSongDetails } = useGetSongDetailsQuery({ songid });
const {
data: artistData,
Expand All @@ -23,6 +27,15 @@ const SongDetails = () => {

if (error) return 'Something went wrong...';

const handlePauseClick = () => {
dispatch(playPause(false));
};

const handlePlayClick = (song, i) => {
dispatch(setActiveSong({ song, songData, i }));
dispatch(playPause(true));
};

return (
<div className="flex flex-col">
<DetailsHeader
Expand All @@ -34,6 +47,16 @@ const SongDetails = () => {
<div className="flex flex-col">
<h1 className="font-bold text-3xl text-white">Related Songs:</h1>
</div>

<RelatedSongs
data={songData}
artistId={artistId}
isPlaying={isPlaying}
activeSong={activeSong}
handlePauseClick={handlePauseClick}
handlePlayClick={handlePlayClick}
/>

</div>
);
};
Expand Down

0 comments on commit 8b24dc7

Please sign in to comment.