Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import Card from './card';
  3.  
  4. import { shuffledDeckURL } from '../constants/constants';
  5. import DealerDeck from '../images/deck.png';
  6.  
  7. class Deck extends Component {
  8. constructor(props) {
  9. super(props);
  10.  
  11. this.state = {
  12. success: false,
  13. deck_id: '',
  14. shuffled: false,
  15. remaining: 0
  16. };
  17. }
  18.  
  19. fetchShuffledDeck() {
  20. fetch(shuffledDeckURL)
  21. .then(response => response.json())
  22. .then(response => {
  23. //console.log(response)
  24. this.setState({
  25. ...this.state,
  26. success: response.success,
  27. deck_id: response.deck_id,
  28. shuffled: response.shuffled,
  29. remainingCards: response.remaining,
  30. });
  31. });
  32. }
  33.  
  34. componentWillMount() {
  35. this.fetchShuffledDeck();
  36. }
  37.  
  38. render() {
  39. const { success, remainingCards, deck_id } = this.state;
  40. return (
  41. <>
  42. <div className="comp-cards">
  43. <div className="row">
  44. <div className="col-8 col-lg-6">
  45. <div className="row">
  46. {success && (
  47. <Card deck_id={deck_id} />
  48. )}</div></div>
  49. <div className='deck col-4 col-lg-2 offset-lg-2'>
  50. <img className='deck__card' src={DealerDeck} alt='Dealer deck'/>
  51. <div className='deck__remainingCards'>
  52. Cards: {remainingCards}
  53. </div>
  54. </div>
  55. </div>
  56. </div>
  57. <div className="row">
  58. <div className="col-10 col-lg-8">
  59. <div className="row">
  60. {success && (
  61. <Card deck_id={deck_id} />
  62. )}
  63. </div>
  64. </div>
  65. </div>
  66. </>
  67. )
  68. }
  69. }
  70.  
  71. export default Deck;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement