{"size": 1207, "ext": "js", "max_stars_repo_path": "src/Callback.js", "max_stars_repo_name": "Sapphire-Snail/Democrify", "max_stars_repo_stars_event_min_datetime": "2020-05-26T00:25:26.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-28T16:49:59.000Z", "max_issues_repo_path": "src/Callback.js", "max_issues_repo_name": "Sapphire-Snail/Democrify", "max_issues_repo_issues_event_min_datetime": "2020-04-10T01:51:17.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-29T09:50:27.000Z", "max_forks_repo_path": "src/Callback.js", "max_forks_repo_name": "Sapphire-Snail/Democrify", "max_forks_repo_forks_event_min_datetime": "2020-03-27T08:41:03.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-10T01:42:57.000Z"}
{"max_stars_count": 2, "max_issues_count": 47, "max_forks_count": 4, "avg_line_length": 23.6666666667, "max_line_length": 87, "alphanum_fraction": 0.6512013256}
import React, { Component } from 'react';
import { Redirect } from 'react-router-dom';
import Loader from 'react-loader-spinner';
import { connect } from 'react-redux';
import { login } from './redux/actions/thunk';
import * as spotify from './SpotifyFunctions.js'

// Class that's instantiated when Spotify login screen is closed (redirects us to here)
class Callback extends Component {

  componentDidMount() {
    var token = spotify.checkUrlForAccessToken();
    if(token) {
      this.props.login(token);
    } else {
      console.log("COULD NOT LOG IN");
    }
  }

  render() {
    const { error } = this.props.userData;
    if(error) {
      return <p>
               Error {error}
             </p>
    }

    if (this.props.loggedIn) {
      return <Redirect to="/me" />;
    }

    return <Loader type="ThreeDots" color="#1ECD97" height={100} width={100} />;
  }
}

// State is entire state tree
function mapStateToProps(state) {
  return {
    userData: state.user,
    loggedIn: state.user.loggedIn,
  };
}

// Map necessary dispatch functions to props
const mapDispatchToProps = {
  login,
};

// Connect to redux store
export default connect(mapStateToProps, mapDispatchToProps)(Callback);
