Skip to content

Instantly share code, notes, and snippets.

@gate5th
Last active September 12, 2018 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gate5th/69bbfea0859d9b257bfe9e33ac48b549 to your computer and use it in GitHub Desktop.
Save gate5th/69bbfea0859d9b257bfe9e33ac48b549 to your computer and use it in GitHub Desktop.
//SpotifyContainer.js
import React, { Component } from 'react';
import './SpotifyContainer.css';
import Paper from '@material-ui/core/Paper';
import ConnectSpotify from './ConnectSpotify';
import * as SpotifyFunctions from '../spotifyFunctions.js'
class SpotifyContainer extends Component {
constructor(props) {
super(props)
this.state = {
loggedInToSpotify: false,
accessToken: null
}
}
componentDidMount(){
//will check URL for accessToken hash. If it's not there, it will show the connect-spotify-button as a link
//which will then redirect back to your site with the hash. If there is a hash, then we will jump right into the player
const accessToken = SpotifyFunctions.checkUrlForSpotifyAccessToken();
accessToken ? this.setState({loggedInToSpotify: true, accessToken: accessToken}) : this.setState({loggedInToSpotify: false, accessToken: null});
}
render() {
return (
<div className="SpotifyContainer">
<Paper>
<p>Spotify Controls</p>
{!this.state.loggedInToSpotify ? <ConnectSpotify /> : <p>{`We're in! Access Token is ${this.state.accessToken}`}</p> }
</Paper>
</div>
);
}
}
export default SpotifyContainer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment