Guest User

Untitled

a guest
Feb 17th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. import React from 'react';
  2.  
  3. import Title from './EventSubComponents/Title';
  4. import SessionInfo from './EventSubComponents/SessionInfo';
  5. import SessionTime from './EventSubComponents/SessionTime';
  6. import Location from './EventSubComponents/Location';
  7. import Subscribers from './EventSubComponents/Subscribers';
  8.  
  9. class EventNode extends React.Component {
  10.  
  11. constructor(props) {
  12. super(props);
  13. this.state = {
  14. 'event': [],
  15. }
  16. }
  17.  
  18. componentDidMount() {
  19. this.getEvent(this.props.location.selectedEventId);
  20. }
  21.  
  22. getEvent(eventId) {
  23. fetch('/api/v.1.0/event/' + eventId, {mode: 'no-cors'})
  24. .then(function(response) {
  25. if(!response.ok) {
  26. console.log('Failed to get single event.');
  27. return;
  28. }
  29. return response.json();
  30. })
  31. .then((data) => {
  32. if (!data) {
  33. return;
  34. }
  35. this.setState({
  36. 'event': data
  37. })
  38. });
  39. }
  40.  
  41. render() {
  42. return(
  43. <div className="event-wrapper">
  44. <Title
  45. title = { this.state.event.title }
  46. date = { this.state.event.start }
  47. />
  48. <SessionInfo
  49. distance = { this.state.event.distance }
  50. type = { this.state.event.type }
  51. />
  52. <SessionTime
  53. start = { this.state.event.start }
  54. end = { this.state.event.end }
  55. />
  56. <Location location = { this.state.event.start_location }/>
  57. <Subscribers
  58. subscribers = { this.state.event.subscribers }
  59. eventId = { this.state.event._id }
  60. />
  61. </div>
  62. );
  63. }
  64. }
  65.  
  66. export default EventNode;
  67.  
  68. import React from 'react';
  69. import moment from 'moment';
  70.  
  71. class Title extends React.Component {
  72. constructor(props) {
  73. super(props);
  74. this.state = {
  75. 'title': '',
  76. 'date': '',
  77. }
  78. }
  79.  
  80. componentDidMount() {
  81. console.log(this.props.title);
  82. console.log(this.props.date);
  83. // undefined both props.
  84. this.convertToTitleDate(this.props.date);
  85. this.setState({
  86. 'title': this.props.title
  87. })
  88. }
  89.  
  90. convertToTitleDate(date) {
  91. var newDate = moment(date).format('dddd, Do MMMM')
  92. this.setState({
  93. 'date': newDate,
  94. });
  95. }
  96.  
  97. render() {
  98. return (
  99. <div className="event-title-wrapper">
  100. <h1> { this.state.title } </h1>
  101. <div className="event-title-date"> { this.state.date } </div>
  102. </div>
  103. );
  104. }
  105. }
  106.  
  107. export default Title;
Add Comment
Please, Sign In to add comment