GithubHelp home page GithubHelp logo

jammming's People

Contributors

pbscoots avatar

Watchers

 avatar

jammming's Issues

Feature Request Review

Giving the user the ability to preview tracks before adding them to the playlist will improve the efficiency of the app. The previews can be played in the current browser by adding a html audio element. We could then use (this.state.trackURI) for example as the players source. The design of the play and pause button is correct by creating the state isPlaying which would toggle to true or false. The technical design is practical and implementable. Great feature request.

Summary

The project ran well. No major errors were detected. I would suggest running and testing the functionalities of the app before publishing to github. Ensure that all the features are working correctly. Since the only error was in relation to state, here is a great document to cover;

https://reactjs.org/docs/faq-state.html

Reset playlistName

The reason why the playlistName does not reset when the 'save to spotify' button is clicked is because the value of the input that displays the name has a default value not set to this.props.playlistName like so;

<input defaultValue={'New Playlist'} onChange={this.handleNameChange}/>

It should be like this instead;

<input value={this.props.playlistName} onChange={this.handleNameChange}/>

in playList.js

savePlaylist()

savePlaylist(playlistName, trackURIs){

This seems to work, so good job on that!! It's a little convoluted, so just for reference here's our official solution for it:

  savePlaylist(name, trackUris) {
    if (!name || !trackUris.length) {
      return;
    }

    const accessToken = Spotify.getAccessToken();
    const headers = { Authorization: `Bearer ${accessToken}` };
    let userId;

    return fetch('https://api.spotify.com/v1/me', {headers: headers}
    ).then(response => response.json()
    ).then(jsonResponse => {
      userId = jsonResponse.id;
      return fetch(`https://api.spotify.com/v1/users/${userId}/playlists`, {
        headers: headers,
        method: 'POST',
        body: JSON.stringify({name: name})
      }).then(response => response.json()
      ).then(jsonResponse => {
        const playlistId = jsonResponse.id;
        return fetch(`https://api.spotify.com/v1/users/${userId}/playlists/${playlistId}/tracks`, {
          headers: headers,
          method: 'POST',
          body: JSON.stringify({uris: trackUris})
        });
      });
    });
  }

simple setState

removeTrack(track){
this.setState({
playlistTracks: this.state.playlistTracks.filter(function(check) {
return check.id !== track.id;
})
});
}

It's usually better when you avoid fitting so much logic into your setState. I'd suggest taking this and splitting it into two lines instead of one really long one and using a new variable. This will help you avoid silly mistakes and makes it a little easier to read! Something like this:

 removeTrack(track){
   const tracks = this.state.playlistTracks.filter(function(check) {
        return check.id !== track.id;
      })

    this.setState({ playlistTracks: tracks });
  }

Simplify starting state

this.state = {
searchResults: [{name: 'name',
artist: 'artist',
album: 'album',
id: '',
uri: ''}],
playlistName: '',
playlistTracks: [{name: 'name',
artist: 'artist',
album: 'album',
id: '',
uri: ''}],
}

You don't need to start with this in your state, you should just start out with an empty array for both searchResults and playlistTracks:

 this.state = {
       searchResults: [],
       playlistName: '',
       playlistTracks: []
     } 

good organized JSX

render() {
return (
<div>
<h1>Ja<span className="highlight">mmm</span>ing</h1>
<div className="App">
<SearchBar onSearch={this.search} />
<div className="App-playlist">
<SearchResults
onAdd={this.addTrack}
searchResults={this.state.searchResults} />
<Playlist
onSave={this.savePlaylist}
onNameChange={this.updatePlaylistName}
onRemove={this.removeTrack}
playlistName={this.state.playlistName}
playlistTracks={this.state.playlistTracks} />
</div>
</div>
</div>
);
}
}

Good job remembering to indent your JSX just like HTML! A lot of people just paste it in and forget to fix up the formatting

Add spaces between methods

this.savePlaylist = this.savePlaylist.bind(this);
this.search = this.search.bind(this);
}
addTrack(track){
if (-1 === this.state.playlistTracks.indexOf(track.id)) {
this.setState({ playlistTracks: this.state.playlistTracks.concat(track)});
}
}
removeTrack(track){
this.setState({
playlistTracks: this.state.playlistTracks.filter(function(check) {
return check.id !== track.id;
})
});
}
updatePlaylistName (name) {
this.setState({playlistName: name});

It helps keep your component organized and easy to read when you add a single line of blank space between each method! Like this:

   this.savePlaylist = this.savePlaylist.bind(this);
    this.search = this.search.bind(this);
  }

 addTrack(track){
   if (-1 === this.state.playlistTracks.indexOf(track.id)) {
     this.setState({ playlistTracks: this.state.playlistTracks.concat(track)});
   }
 }

 removeTrack(track){
   this.setState({
     playlistTracks: this.state.playlistTracks.filter(function(check) {
       return check.id !== track.id;
     })
   });
 }

 updatePlaylistName (name) {
   this.setState({playlistName: name});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.