diff --git a/src/App.js b/src/App.js index 0218b3b..5f198db 100644 --- a/src/App.js +++ b/src/App.js @@ -1,3 +1,5 @@ + + import React, { Component } from 'react'; import './App.css'; diff --git a/src/components/Playlist.js b/src/components/Playlist.js index 46b997c..c9ac4c1 100644 --- a/src/components/Playlist.js +++ b/src/components/Playlist.js @@ -23,18 +23,28 @@ const calculatePlayTime = (tracks) => { minutes = ("" + minutes).padStart(2, "0"); return `${hours}:${minutes}:${seconds}`; -} +}; + + const Playlist = (props) => { const tracks = props.tracks; const trackCount = tracks.length; const playtime = calculatePlayTime(tracks); + + + const trackElements = tracks.map((track, i) => { - // We use "spread syntax" here to pass in all the properties of + // We use "spread syntax" here to pass in all the properties of // the variable 'track' as props. Go look it up! + return ( props.topCallback(i)} + listSwitchCallback ={() => props.radioSwitchCallback(i)} + listFavoriteCallback ={() => props.radioFavoriteCallback(i)} {...track} /> ); @@ -50,7 +60,7 @@ const Playlist = (props) => { {trackElements} - ); + ) } Playlist.propTypes = { diff --git a/src/components/RadioSet.js b/src/components/RadioSet.js index 4796d9c..f431570 100644 --- a/src/components/RadioSet.js +++ b/src/components/RadioSet.js @@ -1,28 +1,122 @@ -import React from 'react'; + + +import React, { Component } from 'react'; + import "./styles/RadioSet.css"; +import PropTypes from 'prop-types' import Playlist from './Playlist'; -const RadioSet = (props) => { - console.log(`Radio set for ${props.tracks.length} tracks`); - const playlists = { - morningTracks: props.tracks.slice(0, props.tracks.length / 2), - eveningTracks: props.tracks.slice(props.tracks.length / 2, props.tracks.length) + +class RadioSet extends Component { + constructor(props) { + super(); + + this.state = { + morningTracks: props.tracks.slice(0, props.tracks.length / 2), + eveningTracks: props.tracks.slice(props.tracks.length / 2, props.tracks.length) + } + + } + + + radioTopLeft =(index)=>{ + let updatedMorningTracks = this.state.morningTracks; + let temp = updatedMorningTracks.splice(index,1)[0]; + + updatedMorningTracks.unshift(temp); + + this.setState({morningTracks: updatedMorningTracks}); + + }; + + radioTopRight =(index)=>{ + let updatedEveningTracks = this.state.eveningTracks; + let temp = updatedEveningTracks.splice(index,1)[0]; + updatedEveningTracks.unshift(temp); + this.setState({eveningTracks: updatedEveningTracks}); + + }; + + + radioSwitchRight =(index)=>{ + let updatedMorningTracks = this.state.morningTracks; + let updatedEveningTracks = this.state.eveningTracks; + + let temp = updatedMorningTracks.splice(index,1)[0]; + + updatedEveningTracks.unshift(temp); + + this.setState({morningTracks: updatedMorningTracks, eveningTracks: updatedEveningTracks}); + }; - return ( -
-
- - -
-
- ); + + radioSwitchLeft =(index)=>{ + let updatedMorningTracks = this.state.morningTracks; + let updatedEveningTracks = this.state.eveningTracks; + + let temp = updatedEveningTracks.splice(index,1)[0]; + + updatedMorningTracks.unshift(temp); + + this.setState({morningTracks: updatedMorningTracks, eveningTracks: updatedEveningTracks}); + + }; + + radioFavoriteLeft =(index)=>{ + const newState = {...this.state}; + const playlistTracks = [...newState["morningTracks"]]; + const track = {...playlistTracks[index]}; + + track.favorite = !track.favorite; + + playlistTracks[index] = track; + newState["morningTracks"] = playlistTracks; + this.setState(newState); + + }; + + radioFavoriteRight =(index)=>{ + const newState = {...this.state}; + const playlistTracks = [...newState["eveningTracks"]]; + const track = {...playlistTracks[index]}; + + track.favorite = !track.favorite; + + playlistTracks[index] = track; + newState["eveningTracks"] = playlistTracks; + this.setState(newState); + + }; + + + render() { + return ( +
+
+ + +
+
+ ); + } }; -export default RadioSet; \ No newline at end of file +RadioSet.propTypes = { + tracks: PropTypes.array, + +} + +export default RadioSet; diff --git a/src/components/Track.js b/src/components/Track.js index 39103c9..71aecd5 100644 --- a/src/components/Track.js +++ b/src/components/Track.js @@ -5,7 +5,11 @@ import "./styles/Track.css"; // Here we use destructuring to extract the props into separate variables // See https://wesbos.com/destructuring-objects/ -const Track = ({title, artist, playtime, albumart, favorite}) => { + + + +const Track = ({title, artist, playtime, albumart, favorite, index, id,toTopCallback,listSwitchCallback, listFavoriteCallback}) => { + return (
  • {`album @@ -13,17 +17,22 @@ const Track = ({title, artist, playtime, albumart, favorite}) => {

    {artist}

    {playtime}