Created
April 27, 2019 12:23
-
-
Save Verthon/9928b8f680dd9bd344225cb16185415b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Reducer | |
const reducer = (state = initialState, action) => { | |
switch(action.type){ | |
case types.SEND_EVENT_DATA: | |
return Object.assign({}, state, { | |
event: state.event | |
}) | |
case types.ADD_EVENT_DATA: | |
return{ | |
events: state.events | |
} | |
default: | |
return state | |
} | |
} | |
//Event Item | |
class EventItem extends React.Component { | |
constructor(props){ | |
super(props); | |
this.state = { | |
event: { | |
title: this.props.title, | |
localization: this.props.localization, | |
day: this.props.day, | |
category: this.props.category, | |
hour: this.props.hour, | |
description: this.props.description | |
} | |
} | |
} | |
componentDidMount(props){ | |
} | |
render(props){ | |
//redux dispatch | |
const {title, localization, day} = this.state.event; | |
return ( | |
<React.Fragment> | |
<div className="event-item"> | |
<Link to={`/events/${formatLink(title)}`} onClick={this.props.updateEvent}> | |
<h2 className="event-item__title">{title}</h2> | |
<p>{localization}</p> | |
<time>{day}</time> | |
</Link> | |
{/*<button className="btn">Learn more</button>*/} | |
</div> | |
</React.Fragment> | |
) | |
} | |
} | |
EventItem.propTypes = { | |
title: PropTypes.string.isRequired, | |
localization: PropTypes.string.isRequired, | |
day: PropTypes.string.isRequired, | |
hour: PropTypes.string.isRequired, | |
} | |
const mapStateToProps = state => { | |
return { | |
event: state.event | |
} | |
} | |
const mapDispatchToProps = dispatch => { | |
return { | |
updateEvent: () => { | |
const action = {type: SEND_EVENT_DATA} | |
dispatch(action); | |
} | |
} | |
}; | |
export default connect(mapStateToProps, mapDispatchToProps)(EventItem); | |
//Event | |
import React from "react"; | |
import Navbar from './Navbar'; | |
import {connect} from 'react-redux'; | |
const Event = (props) => { | |
console.log(props.event); | |
return ( | |
<React.Fragment> | |
<Navbar/> | |
<div className="event"> | |
<h1 className="event__title">Event title</h1> | |
<p className="event__description">A wonderful serenity has taken possession of my entire soul, | |
like these sweet mornings of spring which I enjoy with my whole heart. | |
I am alone, and feel the charm of existence in this spot, which was created for the bliss of souls like mine.</p> | |
<div className="row"> | |
<div className="event__col"> | |
<i className="fas fa-map-marker-alt"></i> | |
<p className="event__location">Seattle, Washington</p> | |
</div> | |
<div className="event__col"> | |
<i className="far fa-clock"></i> | |
<p className="event__time">13:00 - 15:00</p> | |
</div> | |
</div> | |
</div> | |
</React.Fragment> | |
); | |
}; | |
const mapStateToProps = (state) => { | |
return { | |
event: state.event | |
}; | |
} | |
export default connect(mapStateToProps)(Event); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment