Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add and Remove Track #4

Open
jlag34 opened this issue Jun 10, 2019 · 0 comments
Open

Add and Remove Track #4

jlag34 opened this issue Jun 10, 2019 · 0 comments

Comments

@jlag34
Copy link

jlag34 commented Jun 10, 2019

addTrack(track) {
if (this.state.playlistTracks.find(savedTrack => savedTrack.id === track.id)) {
return ;
} else {
const addedPlaylistTracks = this.state.playlistTracks;
addedPlaylistTracks.push(track);
this.setState({playlistTracks : addedPlaylistTracks});
}
}
removeTrack(track) {
const originPlaylistTracks = this.state.playlistTracks
const removedPlaylistTracks = originPlaylistTracks.filter(savedTrack => savedTrack.id !== track.id);
this.setState({playlistTracks : removedPlaylistTracks});
}

Great job on your add and remove track. Both are doing what they should. For your removeTrack, try doing something like this:

removeTrack(track) {
  const newPlaylist = this.state.playlistTracks.filter(savedTrack => savedTrack.id !== track.id);
  this.setState({playlistTracks : newPlaylist});
}

I basically got rid of the first line you had.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant