Created
January 12, 2018 16:12
-
-
Save wongni/ab4f96d3c3a83843c4f509db89856594 to your computer and use it in GitHub Desktop.
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
import React, { Component } from 'react' | |
import ViewerTemplate from './components/ViewerTemplate' | |
import SpaceNavigator from './components/SpaceNavigator' | |
import Viewer from './components/Viewer' | |
import * as api from './lib/api' | |
class App extends Component { | |
state = { | |
loading: false, | |
maxDate: null, | |
date: null, | |
url: null, | |
mediaType: null | |
} | |
getAPOD = async (date) => { | |
if (this.state.loading) return | |
this.setState({ | |
loading: true | |
}) | |
try { | |
const response = await api.getAPOD(date) | |
const { date: retrievedDate, url, media_type: mediaType } = response.data | |
if (!this.state.maxDate) { | |
this.setState({ | |
maxDate: retrievedDate | |
}) | |
} | |
this.setState({ | |
date: retrievedDate, | |
url, | |
mediaType | |
}) | |
} catch (e) { | |
console.log(e) | |
} | |
this.setState({ | |
loading: false | |
}) | |
} | |
componentDidMount () { | |
this.getAPOD() | |
} | |
render() { | |
const { url, mediaType, loading } = this.state | |
return ( | |
<div> | |
<ViewerTemplate | |
spaceNavigator={<SpaceNavigator />} | |
viewer={( | |
<Viewer | |
url={url} | |
mediaType={mediaType} | |
loading={loading} /> | |
)} /> | |
</div> | |
) | |
} | |
} | |
export default App |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment