diff --git a/src/App.jsx b/src/App.jsx index ac2b351..16e4b10 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,8 +1,8 @@ import { useSelector } from 'react-redux'; import { Route, Routes } from 'react-router-dom'; -import { Searchbar, Sidebar, SongPlay, TopPlay } from './components'; -import { ArtistDetails, AroundYou, Discover, Search, SongDetails, TopCharts, TopArtists } from './pages'; +import { Searchbar, Sidebar, MusicPlayer, TopPlay } from './components'; +import { ArtistDetails, TopArtists, AroundYou, Discover, Search, SongDetails, TopCharts } from './pages'; const App = () => { const { activeSong } = useSelector((state) => state.player); @@ -20,7 +20,6 @@ const App = () => { } /> } /> } /> - } /> } /> } /> @@ -30,13 +29,12 @@ const App = () => { - {activeSong?.title && ( -
- -
+
+ +
)} ); diff --git a/src/assets/constants.js b/src/assets/constants.js new file mode 100644 index 0000000..8f645ae --- /dev/null +++ b/src/assets/constants.js @@ -0,0 +1,16 @@ +export const genres = [ + { title: 'Pop', value: 'POP' }, + { title: 'Hip-Hop', value: 'HIP_HOP_RAP' }, + { title: 'Dance', value: 'DANCE' }, + { title: 'Electronic', value: 'ELECTRONIC' }, + { title: 'Soul', value: 'SOUL_RNB' }, + { title: 'Alternative', value: 'ALTERNATIVE' }, + { title: 'Rock', value: 'ROCK' }, + { title: 'Latin', value: 'LATIN' }, + { title: 'Film', value: 'FILM_TV' }, + { title: 'Country', value: 'COUNTRY' }, + { title: 'Worldwide', value: 'WORLDWIDE' }, + { title: 'Reggae', value: 'REGGAE_DANCE_HALL' }, + { title: 'House', value: 'HOUSE' }, + { title: 'K-Pop', value: 'K_POP' }, +]; diff --git a/src/components/DetailsHeader.jsx b/src/components/DetailsHeader.jsx index 37cb97e..66b17e9 100644 --- a/src/components/DetailsHeader.jsx +++ b/src/components/DetailsHeader.jsx @@ -9,12 +9,11 @@ const DetailsHeader = ({ artistId, artistData, songData }) => ( profile diff --git a/src/components/songplay/Controls.jsx b/src/components/MusicPlayer/Controls.jsx similarity index 100% rename from src/components/songplay/Controls.jsx rename to src/components/MusicPlayer/Controls.jsx diff --git a/src/components/songplay/Player.jsx b/src/components/MusicPlayer/Player.jsx similarity index 100% rename from src/components/songplay/Player.jsx rename to src/components/MusicPlayer/Player.jsx diff --git a/src/components/songplay/Seekbar.jsx b/src/components/MusicPlayer/Seekbar.jsx similarity index 100% rename from src/components/songplay/Seekbar.jsx rename to src/components/MusicPlayer/Seekbar.jsx diff --git a/src/components/songplay/Track.jsx b/src/components/MusicPlayer/Track.jsx similarity index 100% rename from src/components/songplay/Track.jsx rename to src/components/MusicPlayer/Track.jsx diff --git a/src/components/songplay/VolumeBar.jsx b/src/components/MusicPlayer/VolumeBar.jsx similarity index 100% rename from src/components/songplay/VolumeBar.jsx rename to src/components/MusicPlayer/VolumeBar.jsx diff --git a/src/components/songplay/index.jsx b/src/components/MusicPlayer/index.jsx similarity index 84% rename from src/components/songplay/index.jsx rename to src/components/MusicPlayer/index.jsx index 94172ba..157d577 100644 --- a/src/components/songplay/index.jsx +++ b/src/components/MusicPlayer/index.jsx @@ -1,4 +1,3 @@ -/* eslint-disable jsx-a11y/media-has-caption */ import React, { useState, useEffect } from 'react'; import { useSelector, useDispatch } from 'react-redux'; @@ -9,10 +8,10 @@ import Seekbar from './Seekbar'; import Track from './Track'; import VolumeBar from './VolumeBar'; -const SongPlay = () => { +const MusicPlayer = () => { const { activeSong, currentSongs, currentIndex, isActive, isPlaying } = useSelector((state) => state.player); const [duration, setDuration] = useState(0); - const [seekTime, setSeekTime] = useState(0); // forces player to update its time + const [seekTime, setSeekTime] = useState(0); const [appTime, setAppTime] = useState(0); const [volume, setVolume] = useState(0.3); const [repeat, setRepeat] = useState(false); @@ -34,12 +33,11 @@ const SongPlay = () => { }; const handleNextSong = () => { - // pause the song first before starting the next song to prevent error play() request interrupted by new load request dispatch(playPause(false)); + if (!shuffle) { dispatch(nextSong((currentIndex + 1) % currentSongs.length)); } else { - // picks a random index if shuffle is true dispatch(nextSong(Math.floor(Math.random() * currentSongs.length))); } }; @@ -57,7 +55,6 @@ const SongPlay = () => { return (
-
{ handlePrevSong={handlePrevSong} handleNextSong={handleNextSong} /> - { setSeekTime={setSeekTime} appTime={appTime} /> - { onLoadedData={(event) => setDuration(event.target.duration)} />
- - setVolume(event.target.value)} - setVolume={setVolume} - /> + setVolume(event.target.value)} setVolume={setVolume} />
); }; -export default SongPlay; +export default MusicPlayer; diff --git a/src/components/Searchbar.jsx b/src/components/Searchbar.jsx index 3bbb5e5..6fc8a10 100644 --- a/src/components/Searchbar.jsx +++ b/src/components/Searchbar.jsx @@ -22,6 +22,7 @@ const Searchbar = () => {