FirstComponent.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import React, { Component } from 'react';
  2. import PropTypes from 'prop-types';
  3. import axios from 'axios';
  4. export default class FirstComponent extends Component {
  5. constructor(props) {
  6. super(props);
  7. this.state = {
  8. prioMatches: this.getMatchData(),
  9. DataIsLoaded: false,
  10. bank: '300.0'
  11. }
  12. this.handleBankChange = this.handleBankChange.bind(this)
  13. }
  14. handleBankChange(event) {
  15. this.setState({ bank: event.target.value })
  16. }
  17. render() {
  18. const { DataIsLoaded, prioMatches } = this.state;
  19. if (!DataIsLoaded) {
  20. return (
  21. <div>
  22. <h1> LOADING ... </h1>
  23. </div>
  24. )
  25. }
  26. const element = (<div>Test from Element</div>)
  27. return (<div className='comptext'>
  28. <h3>First Component</h3>
  29. {this.props.displaytext}
  30. {element}
  31. <label htmlFor='bank'>Bank:</label>
  32. <input id='bank' value={this.state.bank} type='text' onChange={this.handleBankChange}></input>
  33. <h2>Match data</h2>
  34. <table className='matchTable'>
  35. <tbody>
  36. <tr>{this.createMatchTableHeader()}</tr>
  37. {this.createMatchTable()}
  38. </tbody>
  39. </table>
  40. <p>Match data end</p>
  41. </div>)
  42. }
  43. getMatchData() {
  44. fetch('http://nordh.xyz:8666/?what=getPrioMatches')
  45. .then((res) => res.json())
  46. .then((json) => {
  47. this.setState({
  48. prioMatches: json,
  49. DataIsLoaded: true,
  50. })
  51. });
  52. }
  53. createMatchTableHeader() {
  54. let header = Object.keys(this.state.prioMatches[0])
  55. const handleSortChange = (accessor) => {
  56. // const sortOrder = accessor === sortField && order === "asc" ? "desc" : "asc";
  57. // setSortField(accessor);
  58. // setOrder(sortOrder);
  59. // handleSorting(accessor, sortOrder);
  60. };
  61. return header.map((key, index) => {
  62. return <th key={index} className='matchTableHeader' onClick={handleSortChange(index)}>{key.toUpperCase()}</th>
  63. })
  64. }
  65. createMatchTable() {
  66. return this.state.prioMatches.map((match, index) => {
  67. const { id, date, league, country, homeTeam, awayTeam, odds1, oddsX, odds2, analysisValue } = match
  68. return (<tr key={id} className='matchTableRow'>
  69. <td className='matchTableCell'>{id}</td>
  70. <td className='matchTableCell'>{date}</td>
  71. <td className='matchTableCell'>{country}</td>
  72. <td className='matchTableCell'>{league}</td>
  73. <td className='matchTableCell'>{homeTeam}</td>
  74. <td className='matchTableCell'>{awayTeam}</td>
  75. <td className='matchTableCell'>{odds1}</td>
  76. <td className='matchTableCell'>{oddsX}</td>
  77. <td className='matchTableCell'>{odds2}</td>
  78. <td className='matchTableCell'>{analysisValue}</td>
  79. </tr>)
  80. })
  81. }
  82. }
  83. FirstComponent.propTypes = {
  84. displaytext: PropTypes.string.isRequired
  85. };