metamaps--metamaps/frontend/src/components/Maps/Header.js

92 lines
2.8 KiB
JavaScript
Raw Normal View History

import React, { Component, PropTypes } from 'react'
import _ from 'lodash'
const MapLink = props => {
2016-08-05 02:13:55 +00:00
const { show, text, href, linkClass } = props
const otherProps = _.omit(props, ['show', 'text', 'href', 'linkClass'])
if (!show) {
return null
}
return (
<a { ...otherProps } href={href} className={linkClass}>
<div className="exploreMapsIcon"></div>
2016-08-05 02:13:55 +00:00
{text}
</a>
)
}
class Header extends Component {
render = () => {
2016-08-02 01:20:19 +00:00
const { signedIn, section } = this.props
const activeClass = (title) => {
2016-10-07 16:31:32 +00:00
let forClass = 'exploreMapsButton'
forClass += ' ' + title + 'Maps'
if (title === 'my' && section === 'mine' ||
title === section) forClass += ' active'
return forClass
}
2016-10-07 16:31:32 +00:00
const explore = section === 'mine' || section === 'active' || section === 'starred' || section === 'shared' || section === 'featured'
const mapper = section === 'mapper'
return (
<div id="exploreMapsHeader">
<div className="exploreMapsBar exploreElement">
<div className="exploreMapsMenu">
<div className="exploreMapsCenter">
<MapLink show={signedIn && explore}
href="/explore/mine"
2016-10-07 16:31:32 +00:00
linkClass={activeClass('my')}
data-router="true"
text="My Maps"
/>
<MapLink show={signedIn && explore}
href="/explore/shared"
2016-10-07 16:31:32 +00:00
linkClass={activeClass('shared')}
data-router="true"
text="Shared With Me"
/>
<MapLink show={signedIn && explore}
href="/explore/starred"
2016-10-07 16:31:32 +00:00
linkClass={activeClass('starred')}
data-router="true"
text="Starred By Me"
/>
<MapLink show={explore}
2016-10-07 16:31:32 +00:00
href={signedIn ? '/' : '/explore/active'}
linkClass={activeClass('active')}
data-router="true"
2016-10-17 14:53:33 +00:00
text="All Maps"
/>
<MapLink show={!signedIn && explore}
href="/explore/featured"
2016-10-07 16:31:32 +00:00
linkClass={activeClass('featured')}
data-router="true"
text="Featured Maps"
/>
{mapper ? (
<div className='exploreMapsButton active mapperButton'>
<img className='exploreMapperImage' width='24' height='24' src={this.props.user.image} />
<div className='exploreMapperName'>{this.props.user.name}&rsquo;s Maps</div>
<div className='clearfloat'></div>
</div>
) : null }
</div>
</div>
</div>
</div>
)
}
}
2016-08-02 01:19:12 +00:00
Header.propTypes = {
signedIn: PropTypes.bool.isRequired,
section: PropTypes.string.isRequired,
user: PropTypes.object
2016-08-02 01:19:12 +00:00
}
export default Header