You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Zettel.jsx 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import * as React from 'react';
  2. import * as PropTypes from 'prop-types';
  3. import update from 'immutability-helper';
  4. import axios from 'axios';
  5. import './Zettel.css';
  6. import Besorgung from './Besorgung';
  7. import Zeile from './Zeile';
  8. export default class Zettel extends React.Component {
  9. state = {
  10. selectedLine: '',
  11. liste: [],
  12. };
  13. getSelectHandler()
  14. {
  15. return line =>
  16. this.setState((state) =>
  17. update(state, {selectedLine: {$set: line}}),
  18. );
  19. }
  20. async componentDidMount(){
  21. const {data} = await axios.get('http://localhost:3001/zeile');
  22. const liste = [];
  23. data.forEach(zeile => {
  24. const besorgung = new Besorgung(zeile.nummer, zeile.name, zeile.menge, zeile.einheit, zeile.kommentar);
  25. liste.push(besorgung);
  26. });
  27. this.setState(state =>
  28. update(state,{
  29. liste: {$set: liste},
  30. }),
  31. );
  32. }
  33. render(){
  34. return(
  35. <div className="zettel">
  36. <h1>Einkaufszettel</h1>
  37. <p>Artikel in der Einkaufsliste = {this.state.liste.length}</p>
  38. <table>
  39. <thead>
  40. <tr>
  41. {Object.keys(Besorgung.properties).map(property =>{
  42. const besorgungsprop = Besorgung.properties[property];
  43. return(
  44. <th>{besorgungsprop.label}</th>
  45. );
  46. })}
  47. </tr>
  48. </thead>
  49. <tbody>
  50. {
  51. this.state.liste.map(zeile => {
  52. return(
  53. <Zeile
  54. besorgung={zeile}
  55. selectedLine={this.state.selectedLine}
  56. onSelect={this.getSelectHandler()}
  57. />
  58. );
  59. })
  60. }
  61. </tbody>
  62. </table>
  63. </div>
  64. );
  65. }
  66. }