Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import PropTypes from 'prop-types';
  3. import { Link } from 'react-router';
  4. import { FormControl } from 'react-bootstrap';
  5.  
  6. import api from '../../api';
  7.  
  8. class RecipeDetialEdit extends Component {
  9. constructor(props) {
  10. super(props);
  11.  
  12. this.state = {
  13. directionsEdit: '',
  14. title: '',
  15. };
  16. this.handleTextChange = this.handleTextChange.bind(this);
  17. }
  18.  
  19. componentDidUpdate(prevProps, prevState) {
  20. if (prevProps.recipeDetailData !== this.props.recipeDetailData) {
  21. this.setState({
  22. directionsEdit: this.props.recipeDetailData.directions,
  23. title: this.props.recipeDetailData.title,
  24. });
  25. //console.log(this.props.recipeDetailData.directions);
  26. }
  27. }
  28.  
  29. handleTextChange(event) {
  30. this.setState({
  31. directionsEdit: event.target.value,
  32. });
  33. }
  34.  
  35. handleTitleChange(event) {
  36. this.setState({
  37. title: event.target.value,
  38. });
  39. }
  40.  
  41. saveForm(directions, title, preparationTime, servingCount, slug, _id, sideDish) {
  42. console.log(_id);
  43. api
  44. .post('/recipes/5a8156f1abdff8001a01369e', {
  45. _id, //'5a8156f1abdff8001a01369e',
  46. directions,
  47. //'*) Hovězí maso omyjeme a naložíme do Hamé Halali zeleninové směsi, maso musí být ve směsi ponořené, pokud není, dolijeme studenou vodou (_naložené maso necháme v lednici 1 až 3 dny_)\n*) Poté maso vložíme i se směsí do pekáčku, přikryjeme a pečeme na 200 °C po dobu 2,5 - 3 hodiny\n*) Upečené maso vyjmeme z pekáčku, nakrájíme na plátky a necháme stranou\n*) Polovinu směsi rozmixujeme tyčovým mixérem a druhou polovinu propasírujeme\n*) Přivedeme k varu\n*) Ve smetaně a mléku mezitím rozmícháme cca 6 lžic hladké mouky a 3 lžíce cukru\n*) Pomalu přilijeme do omáčky, důkladně promícháme a necháme přejít varem\n*) Dochutíme cukrem a citronovou šťávou\n\n_Nesmí chybět brusinky!_',
  48. if(sideDish){sideDish},//: 'karlovarský knedlík',
  49. preparationTime,//: 180,
  50. servingCount,//: 10,
  51. title,//: 'Svíčková na smetaně',
  52. slug,//: 'svickova-na-smetane',
  53. //__v: 0,
  54. })
  55. //`/if(slug){window.location.href=`/recipe/${slug}`;}
  56. //.then(
  57. //response => {if(slug){console.log(slug)};}
  58. //);
  59. //if(slug){window.location.href=`/recipe/${slug}`}
  60. }
  61.  
  62. renderSideDish() {
  63. const { recipeDetailData } = this.props;
  64. const { sideDish } = recipeDetailData;
  65.  
  66. return (
  67. sideDish && (
  68. <span>
  69. <i className="fa fa-cutlery" /> Side Dish {sideDish}
  70. </span>
  71. )
  72. );
  73. }
  74.  
  75. render() {
  76. const { directionsEdit } = this.state;
  77. const { isLoading, recipeDetailData } = this.props;
  78. const { title, preparationTime, directions, servingCount, slug, _id, sideDish } =
  79. recipeDetailData || {};
  80.  
  81. if (isLoading) {
  82. return <div> Loading ...</div>;
  83. }
  84.  
  85. return (
  86. <div className="row">
  87. <input
  88. type="text"
  89. value={this.state.title}
  90. onChange={this.handleTitleChange}
  91. />
  92. <div>
  93. <span>
  94. <i className="fa fa-clock-o" />Preparation Time: {preparationTime}{' '}
  95. min
  96. </span>{' '}
  97. {this.renderSideDish()} {''}
  98. <span>
  99. <i className="fa fa-rocket" />Serving counts: {servingCount}
  100. </span>
  101. </div>
  102. <div>
  103. <FormControl
  104. componentClass="textarea"
  105. value={this.state.directionsEdit}
  106. onChange={this.handleTextChange}
  107. style={{ height: '250px' }}
  108. />
  109. </div>
  110. <button onClick={this.saveForm(directionsEdit, title, preparationTime, servingCount, slug, _id, sideDish)}>Save</button>
  111. </div>
  112. );
  113. }
  114. }
  115.  
  116. RecipeDetialEdit.propTypes = {
  117. isLoading: PropTypes.bool.isRequired,
  118. RecipeDetailData: PropTypes.object,
  119. };
  120.  
  121. export default RecipeDetialEdit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement