Created
September 12, 2018 17:57
-
-
Save gate5th/00eaf20e6a85b809439e0abe2d69bfb8 to your computer and use it in GitHub Desktop.
oldschoolshuffle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//App.js | |
import React, { Component } from 'react'; | |
import './App.css'; | |
import FeaturedPost from './FeaturedPost'; | |
import * as CosmicFunctions from '../cosmicFunctions'; | |
class App extends Component { | |
constructor(props){ | |
super(props); | |
this.state = { | |
dataReceived: false, | |
posts: [], | |
authors: [], | |
featuredPostIndex: 0, | |
otherPosts: [], | |
} | |
} | |
async componentDidMount(){ | |
try { | |
const {posts, authors} = await CosmicFunctions.getCosmicJsData(); | |
this.setState({dataReceived: true, posts: posts, authors: authors, otherPosts: posts.slice(1)}) | |
} | |
catch(err) { | |
console.error('Error: Problem retrieving Cosmic JS data'); | |
console.error(err); | |
console.error(err.stack); | |
this.setState({dataReceived: false}); | |
} | |
} | |
render() { | |
return ( | |
<div className="App"> | |
<header className="App-header"> | |
Old School Shuffle | |
</header> | |
<div className="featuredPost"> | |
{this.state.dataReceived ? <FeaturedPost post={this.state.posts[this.state.featuredPostIndex]}/> : ''} | |
</div> | |
<div className="spotifyPlayer"> | |
<p>Spotify player here</p> | |
</div> | |
<div className="otherPosts"> | |
<p>Other posts here</p> | |
</div> | |
<div className="footer"> | |
<p>Footer here</p> | |
</div> | |
</div> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment