Guest User

Untitled

a guest
Oct 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. {
  2. "arrivals": [
  3. {
  4. "id": 118927,
  5. "time": "11:05",
  6. "date": "2018-10-20",
  7. "expected": "15:00",
  8. "airline": "Norwegian",
  9. "arriving_from": "Prague, Czechia - Vaclav Havel Airport Prague",
  10. "flight_no": "D83581",
  11. "gate": "A20",
  12. "terminal": "",
  13. "status": "Baggage"
  14. },
  15.  
  16. import React from 'react';
  17. import FilterableTable from 'react-filterable-table';
  18.  
  19. const FlightComponent = (props) => {
  20. const renderTime = (props) => {
  21. if (!props.value) {
  22. return null;
  23. }
  24. const date = new Date(props.value);
  25. const formatTime = ('0' + date.getUTCHours()).slice(-2) + ":" + ('0' + date.getUTCHours()).slice(-2);
  26.  
  27. return (
  28. <span>{formatTime}</span>
  29. );
  30. };
  31.  
  32. const fields = [
  33. { name: 'time', displayName: "Time", inputFilterable: true, sortable: true, render: renderTime },
  34. { name: 'airline', displayName: "Airline", inputFilterable: true, sortable: true },
  35. { name: 'destination', displayName: "Destination", inputFilterable: true},
  36. { name: 'status', displayName: "Status", inputFilterable: true}
  37. ];
  38. return (
  39. <FilterableTable
  40. namespace="Flights"
  41. data={props.flights}
  42. pagersVisible={false}
  43. fields={fields}
  44. noRecordsMessage="There are no flights to display"
  45. noFilteredRecordsMessage="No flights match your filters!"
  46. />
  47. )
  48. };
  49.  
  50. export default FlightComponent;
  51.  
  52. import React, { Component } from 'react';
  53. import { connect } from 'react-redux';
  54. import { TabContent, TabPane, Nav, NavItem, NavLink, Row, Col } from 'reactstrap';
  55. import classnames from 'classnames';
  56. import { loadFlights } from '../actions/action';
  57. import FlightsComponent from '../components/FlightsComponent';
  58.  
  59. class FlightsContainer extends Component {
  60. constructor(props) {
  61. super(props);
  62. this.state = {
  63. activeTab: '1'
  64. };
  65. this.props.loadFlights('departure');
  66. }
  67.  
  68. toggle(tab) {
  69. const filterType = tab === '1' ? 'departure' : 'arrival';
  70. if (this.state.activeTab !== tab) {
  71. this.setState({
  72. activeTab: tab
  73. });
  74. this.props.loadFlights(filterType);
  75. }
  76. }
  77.  
  78. render() {
  79. return(
  80. <div>
  81. <h2 className='App'>Copenhagen Airport's Flights</h2>
  82. <div sm="12" className="tab-section">
  83. <Nav tabs className="m-3">
  84. <NavItem>
  85. <NavLink
  86. className={classnames({ active: this.state.activeTab === '1' })}
  87. onClick={() => { this.toggle('1'); }}
  88. >
  89. Departures
  90. </NavLink>
  91. </NavItem>
  92. <NavItem>
  93. <NavLink
  94. className={classnames({ active: this.state.activeTab === '2' })}
  95. onClick={() => { this.toggle('2'); }}
  96. >
  97. Arrivals
  98. </NavLink>
  99. </NavItem>
  100. </Nav>
  101. <TabContent activeTab={this.state.activeTab}>
  102. <TabPane tabId="1">
  103. <Row>
  104. <Col sm="12">
  105. <FlightsComponent {...this.props}/>
  106. </Col>
  107. </Row>
  108. </TabPane>
  109. <TabPane tabId="2">
  110. <Row>
  111. <Col sm="12">
  112. <FlightsComponent {...this.props}/>
  113. </Col>
  114. </Row>
  115. </TabPane>
  116. </TabContent>
  117. </div>
  118. </div>
  119. )
  120. }
  121. }
  122. const mapDispatchToProps = {
  123. loadFlights
  124. };
  125. const mapStateToProps = (state) => {
  126. return {
  127. flights: state.flightReducer.flights
  128. }
  129. };
  130. export default connect(mapStateToProps, mapDispatchToProps)(FlightsContainer);
Add Comment
Please, Sign In to add comment