| 
									
										
										
										
											2017-12-15 13:53:32 -08:00
										 |  |  | import React, { PureComponent } from 'react'; | 
					
						
							| 
									
										
										
										
											2017-11-09 17:10:30 -08:00
										 |  |  | import PropTypes from 'prop-types'; | 
					
						
							| 
									
										
										
										
											2016-05-10 21:25:12 -07:00
										 |  |  | import { connect } from 'react-redux'; | 
					
						
							| 
									
										
										
										
											2016-06-22 14:55:35 -07:00
										 |  |  | import { createSelector } from 'reselect'; | 
					
						
							| 
									
										
										
										
											2016-03-22 22:13:05 -07:00
										 |  |  | import FA from 'react-fontawesome'; | 
					
						
							|  |  |  | import { Panel } from 'react-bootstrap'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-31 20:04:01 -07:00
										 |  |  | import ns from './ns.json'; | 
					
						
							| 
									
										
										
										
											2018-01-06 17:09:28 -08:00
										 |  |  | import Challenges from './Challenges.jsx'; | 
					
						
							| 
									
										
										
										
											2016-07-14 17:13:48 -07:00
										 |  |  | import { | 
					
						
							| 
									
										
										
										
											2017-07-31 20:04:01 -07:00
										 |  |  |   toggleThisPanel, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-02 17:11:27 -08:00
										 |  |  |   makePanelOpenSelector | 
					
						
							| 
									
										
										
										
											2017-07-31 20:04:01 -07:00
										 |  |  | } from './redux'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { makeBlockSelector } from '../entities'; | 
					
						
							| 
									
										
										
										
											2016-03-22 22:13:05 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-22 14:55:35 -07:00
										 |  |  | const dispatchActions = { toggleThisPanel }; | 
					
						
							| 
									
										
										
										
											2017-07-31 20:04:01 -07:00
										 |  |  | function makeMapStateToProps(_, { dashedName }) { | 
					
						
							|  |  |  |   return createSelector( | 
					
						
							|  |  |  |     makeBlockSelector(dashedName), | 
					
						
							|  |  |  |     makePanelOpenSelector(dashedName), | 
					
						
							| 
									
										
										
										
											2018-01-02 17:11:27 -08:00
										 |  |  |     (block, isOpen) => { | 
					
						
							| 
									
										
										
										
											2017-07-31 20:04:01 -07:00
										 |  |  |       return { | 
					
						
							|  |  |  |         isOpen, | 
					
						
							|  |  |  |         dashedName, | 
					
						
							|  |  |  |         title: block.title, | 
					
						
							|  |  |  |         time: block.time, | 
					
						
							| 
									
										
										
										
											2018-01-06 17:09:28 -08:00
										 |  |  |         challenges: block.challenges || [] | 
					
						
							| 
									
										
										
										
											2017-07-31 20:04:01 -07:00
										 |  |  |       }; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-01-12 06:54:43 +00:00
										 |  |  | const propTypes = { | 
					
						
							|  |  |  |   challenges: PropTypes.array, | 
					
						
							|  |  |  |   dashedName: PropTypes.string, | 
					
						
							|  |  |  |   isOpen: PropTypes.bool, | 
					
						
							|  |  |  |   time: PropTypes.string, | 
					
						
							|  |  |  |   title: PropTypes.string, | 
					
						
							|  |  |  |   toggleThisPanel: PropTypes.func | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-10 21:25:12 -07:00
										 |  |  | export class Block extends PureComponent { | 
					
						
							| 
									
										
										
										
											2016-06-22 14:55:35 -07:00
										 |  |  |   constructor(...props) { | 
					
						
							|  |  |  |     super(...props); | 
					
						
							|  |  |  |     this.handleSelect = this.handleSelect.bind(this); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   handleSelect(eventKey, e) { | 
					
						
							|  |  |  |     e.preventDefault(); | 
					
						
							|  |  |  |     this.props.toggleThisPanel(eventKey); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-22 20:25:49 -07:00
										 |  |  |   renderHeader(isOpen, title, time, isCompleted) { | 
					
						
							|  |  |  |     return ( | 
					
						
							| 
									
										
										
										
											2017-07-31 20:04:01 -07:00
										 |  |  |       <div className={ isCompleted ? 'faded' : '' }> | 
					
						
							|  |  |  |         <FA | 
					
						
							|  |  |  |           className='map-caret' | 
					
						
							|  |  |  |           name={ isOpen ? 'caret-down' : 'caret-right' } | 
					
						
							|  |  |  |           size='lg' | 
					
						
							|  |  |  |         /> | 
					
						
							|  |  |  |         <span> | 
					
						
							|  |  |  |         { title } | 
					
						
							|  |  |  |         </span> | 
					
						
							|  |  |  |         <span className={ `${ns}-block-time` }>({ time })</span> | 
					
						
							| 
									
										
										
										
											2016-06-22 20:25:49 -07:00
										 |  |  |       </div> | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-22 22:13:05 -07:00
										 |  |  |   render() { | 
					
						
							| 
									
										
										
										
											2016-06-09 16:02:51 -07:00
										 |  |  |     const { | 
					
						
							|  |  |  |       title, | 
					
						
							|  |  |  |       time, | 
					
						
							| 
									
										
										
										
											2016-06-22 14:55:35 -07:00
										 |  |  |       dashedName, | 
					
						
							|  |  |  |       isOpen, | 
					
						
							|  |  |  |       challenges | 
					
						
							| 
									
										
										
										
											2016-06-09 16:02:51 -07:00
										 |  |  |     } = this.props; | 
					
						
							| 
									
										
										
										
											2016-03-22 22:13:05 -07:00
										 |  |  |     return ( | 
					
						
							|  |  |  |       <Panel | 
					
						
							| 
									
										
										
										
											2017-07-31 20:04:01 -07:00
										 |  |  |         bsClass={ `${ns}-accordion-panel` } | 
					
						
							| 
									
										
										
										
											2016-03-22 22:13:05 -07:00
										 |  |  |         collapsible={ true } | 
					
						
							| 
									
										
										
										
											2016-06-22 14:55:35 -07:00
										 |  |  |         eventKey={ dashedName || title } | 
					
						
							|  |  |  |         expanded={ isOpen } | 
					
						
							| 
									
										
										
										
											2016-06-22 20:25:49 -07:00
										 |  |  |         header={ this.renderHeader(isOpen, title, time) } | 
					
						
							| 
									
										
										
										
											2016-03-22 22:13:05 -07:00
										 |  |  |         id={ title } | 
					
						
							| 
									
										
										
										
											2016-06-09 16:02:51 -07:00
										 |  |  |         key={ title } | 
					
						
							| 
									
										
										
										
											2016-06-22 14:55:35 -07:00
										 |  |  |         onSelect={ this.handleSelect } | 
					
						
							| 
									
										
										
										
											2016-06-09 16:02:51 -07:00
										 |  |  |         > | 
					
						
							| 
									
										
										
										
											2018-01-06 17:09:28 -08:00
										 |  |  |         { isOpen && <Challenges challenges={ challenges } /> } | 
					
						
							| 
									
										
										
										
											2016-03-22 22:13:05 -07:00
										 |  |  |       </Panel> | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2016-05-10 21:25:12 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-12 06:54:43 +00:00
										 |  |  | Block.displayName = 'Block'; | 
					
						
							|  |  |  | Block.propTypes = propTypes; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-14 17:13:48 -07:00
										 |  |  | export default connect(makeMapStateToProps, dispatchActions)(Block); |