Guest User

Untitled

a guest
Mar 20th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. class App extends Component {
  2. //api call for latest space launch
  3. constructor(props) {
  4. super(props);
  5. this.state = {
  6. selectedLaunch: "",
  7. launchData: "",
  8. videoURL: null,
  9. allPastLaunches: [],
  10. showVideo: false
  11. };
  12. }
  13.  
  14. componentWillMount() {
  15. this.getLaunchData()
  16. }
  17.  
  18. switchLaunch(launch) {
  19. debugger
  20. }
  21.  
  22.  
  23. getLaunchData() {
  24. // getting latest launch
  25. fetch('https://api.spalta.launch/launch')
  26. .then(response => {
  27. return response.json();
  28. })
  29. .then(json => {
  30. this.setState({
  31. launchData: json,
  32. videoURL: json.links["video_link"],
  33. missionPatch: json.links["mission_patch"]
  34. });
  35. });
  36.  
  37. //getting all previous launches
  38. fetch('https://api.spalta.launch/prevLaunches')
  39. .then(response => {
  40. return response.json();
  41. })
  42. .then(json => {
  43. this.setState({
  44. allPastLaunches: json,
  45. });
  46. });
  47.  
  48. }
  49. render() {
  50. let dataReady = this.state.videoURL;
  51.  
  52. if (this.state.launchData != null) {
  53. return (
  54. <div className="App">
  55. {this.state.allPastLaunches ?
  56. <Header
  57. key="header"
  58. missionPatch = {this.state.missionPatch}
  59. allPastLaunches = {this.state.allPastLaunches}
  60. switchLaunch = {this.switchLaunch}
  61. />
  62. :
  63. <div>Loading...</div>
  64. }
  65.  
  66. class Header extends Component {
  67.  
  68. componentDidMount() {
  69. }
  70.  
  71.  
  72. render() {
  73.  
  74. var launches = this.props.allPastLaunches;
  75.  
  76. var imgClass = classNames({
  77. 'img-container': true,
  78. 'animated': true,
  79. 'fadeInDownBig': true
  80. });
  81.  
  82. return (
  83. <div key = "container" className="header-container">
  84. <div key = "img-container">
  85. {launches.map((launch, index) =>
  86. <span key = {index} onClick= {() => { this.props.switchLaunch(index) }} >
  87. {launch["rocket"].rocket_id}
  88. </span>
  89.  
  90. )}
Add Comment
Please, Sign In to add comment