2020-08-17 21:07:16 +01:00
|
|
|
import React from 'react'
|
2020-08-17 21:59:29 +01:00
|
|
|
import PropTypes from 'prop-types'
|
2020-10-30 18:05:30 +00:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
2020-08-17 21:39:25 +01:00
|
|
|
import { connect } from 'react-redux'
|
2020-05-07 05:03:34 +01:00
|
|
|
import { withRouter } from 'react-router-dom'
|
|
|
|
import { me } from '../initial_state'
|
2020-10-30 18:05:30 +00:00
|
|
|
import { openSidebar } from '../actions/sidebar'
|
2020-05-10 04:26:58 +01:00
|
|
|
import { CX } from '../constants'
|
2020-05-06 05:33:54 +01:00
|
|
|
import Button from './button'
|
2020-10-30 18:05:30 +00:00
|
|
|
import Avatar from './avatar'
|
2020-05-06 05:33:54 +01:00
|
|
|
|
2020-10-30 18:05:30 +00:00
|
|
|
class FooterBar extends ImmutablePureComponent {
|
2020-05-06 05:33:54 +01:00
|
|
|
|
2020-05-10 04:26:58 +01:00
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object,
|
|
|
|
}
|
|
|
|
|
2020-10-31 23:20:21 +00:00
|
|
|
handleOnOpenSidebar = () => {
|
|
|
|
this.props.onOpenSidebar()
|
|
|
|
}
|
|
|
|
|
2020-05-06 05:33:54 +01:00
|
|
|
render() {
|
2020-05-29 23:30:31 +01:00
|
|
|
const {
|
2020-10-30 18:05:30 +00:00
|
|
|
account,
|
2020-05-29 23:30:31 +01:00
|
|
|
notificationCount,
|
|
|
|
homeItemsQueueCount,
|
|
|
|
} = this.props
|
2020-05-06 05:33:54 +01:00
|
|
|
|
2020-05-10 04:26:58 +01:00
|
|
|
const noRouter = !this.context.router
|
|
|
|
const currentPathname = noRouter ? '' : this.context.router.route.location.pathname
|
|
|
|
|
|
|
|
const buttons = [
|
|
|
|
{
|
2020-08-06 06:14:42 +01:00
|
|
|
to: !me ? '/' : '/home',
|
2020-05-10 04:26:58 +01:00
|
|
|
icon: 'home',
|
|
|
|
title: 'Home',
|
2020-08-06 06:14:42 +01:00
|
|
|
active: !me ? currentPathname === '/' : currentPathname === '/home',
|
2020-05-10 04:26:58 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
to: '/notifications',
|
|
|
|
icon: 'notifications',
|
|
|
|
title: 'Notifications',
|
2020-07-25 03:20:46 +01:00
|
|
|
isHidden: !me,
|
2020-10-30 18:05:30 +00:00
|
|
|
active: currentPathname.indexOf('/notifications') > -1,
|
2020-05-10 04:26:58 +01:00
|
|
|
},
|
|
|
|
{
|
2020-05-16 04:22:49 +01:00
|
|
|
to: '/groups',
|
|
|
|
icon: 'group',
|
|
|
|
title: 'Groups',
|
2020-10-30 18:05:30 +00:00
|
|
|
active: currentPathname.indexOf('/groups') > -1,
|
2020-05-10 04:26:58 +01:00
|
|
|
},
|
2020-11-03 23:12:11 +00:00
|
|
|
{
|
|
|
|
to: '/search',
|
|
|
|
icon: 'explore',
|
|
|
|
title: 'Explore',
|
|
|
|
active: currentPathname.indexOf('/search') > -1,
|
|
|
|
},
|
2020-08-06 06:14:42 +01:00
|
|
|
{
|
|
|
|
to: '/news',
|
|
|
|
icon: 'news',
|
|
|
|
title: 'News',
|
2020-10-30 18:05:30 +00:00
|
|
|
isHidden: !!me,
|
|
|
|
active: currentPathname.indexOf('/news') > -1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Menu',
|
|
|
|
isHidden: !me,
|
2020-10-30 18:18:42 +00:00
|
|
|
active: !!account ? currentPathname === `/${account.get('username')}` : false,
|
2020-10-31 23:20:21 +00:00
|
|
|
onClick: this.handleOnOpenSidebar,
|
2020-08-06 06:14:42 +01:00
|
|
|
},
|
2020-05-10 04:26:58 +01:00
|
|
|
]
|
|
|
|
|
2020-05-06 05:33:54 +01:00
|
|
|
return (
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.z4, _s.minH58PX, _s.w100PC].join(' ')}>
|
|
|
|
<div className={[_s.d, _s.posFixed, _s.left0, _s.right0, _s.bottom0, _s.minH58PX, _s.w100PC, _s.bgPrimary, _s.borderTop1PX, _s.borderColorSecondary].join(' ')}>
|
|
|
|
<div className={[_s.d, _s.flexRow, _s.aiCenter, _s.h100PC, _s.minH58PX, _s.saveAreaInsetPB, _s.jcSpaceAround].join(' ')}>
|
2020-05-10 04:26:58 +01:00
|
|
|
{
|
2020-11-05 03:02:40 +00:00
|
|
|
buttons.map((props, i) => {
|
2020-07-25 03:20:46 +01:00
|
|
|
if (props.isHidden) return null
|
|
|
|
|
2020-05-10 04:26:58 +01:00
|
|
|
const classes = CX({
|
|
|
|
borderTop2PX: 1,
|
|
|
|
borderColorTransparent: !props.active,
|
|
|
|
borderColorBrand: props.active,
|
2020-08-18 21:43:06 +01:00
|
|
|
h100PC: 1,
|
|
|
|
minH58PX: 1,
|
2020-05-10 04:26:58 +01:00
|
|
|
px15: 1,
|
|
|
|
flexGrow1: 1,
|
2020-08-18 21:43:06 +01:00
|
|
|
aiCenter: 1,
|
|
|
|
jcCenter: 1,
|
2020-05-10 04:26:58 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
const color = props.active ? 'brand' : 'secondary'
|
2020-05-29 23:30:31 +01:00
|
|
|
let childIcon;
|
|
|
|
if (props.to === '/notifications' && notificationCount > 0) {
|
|
|
|
childIcon = (
|
|
|
|
<div className={[_s.posAbs, _s.ml5, _s.top0, _s.pt5, _s.pl20].join(' ')}>
|
2020-08-18 21:43:06 +01:00
|
|
|
<span className={[_s.bgRed, _s.cWhite, _s.circle, _s.py2, _s.px2, _s.minW14PX, _s.displayBlock].join(' ')} style={{fontSize: '12px'}}>
|
2020-05-29 23:30:31 +01:00
|
|
|
{notificationCount}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
} else if (props.to === '/home' && homeItemsQueueCount > 0) {
|
|
|
|
childIcon = (
|
|
|
|
<div className={[_s.posAbs, _s.ml5, _s.top0, _s.pt2, _s.pl20].join(' ')}>
|
2020-08-18 21:43:06 +01:00
|
|
|
<span className={[_s.cBrand, _s.circle, _s.py2, _s.px2, _s.minW14PX, _s.displayBlock].join(' ')} style={{fontSize: '18px'}}>
|
2020-05-29 23:30:31 +01:00
|
|
|
•
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
)
|
2020-10-30 18:18:42 +00:00
|
|
|
} else if (props.title === 'Menu' && !!account) {
|
2020-10-30 18:05:30 +00:00
|
|
|
const avatarContainerClasses = CX({
|
|
|
|
d: 1,
|
|
|
|
circle: 1,
|
|
|
|
boxShadowProfileAvatarFooter: !!props.active,
|
|
|
|
})
|
|
|
|
childIcon = (
|
|
|
|
<div className={avatarContainerClasses}>
|
|
|
|
<Avatar account={account} size={24} />
|
|
|
|
</div>
|
|
|
|
)
|
2020-05-29 23:30:31 +01:00
|
|
|
}
|
2020-05-10 04:26:58 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
isText
|
|
|
|
backgroundColor='none'
|
|
|
|
iconSize='20px'
|
|
|
|
color={color}
|
|
|
|
to={props.to}
|
2020-10-30 18:05:30 +00:00
|
|
|
onClick={props.onClick}
|
2020-05-10 04:26:58 +01:00
|
|
|
icon={props.icon}
|
|
|
|
href={props.href}
|
|
|
|
title={props.title}
|
|
|
|
className={classes}
|
2020-11-05 03:02:40 +00:00
|
|
|
key={`footer-bar-item-${i}`}
|
2020-05-15 23:27:06 +01:00
|
|
|
>
|
|
|
|
{childIcon}
|
|
|
|
</Button>
|
2020-05-10 04:26:58 +01:00
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
2020-05-06 05:33:54 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2020-07-25 03:20:46 +01:00
|
|
|
|
2020-05-06 05:33:54 +01:00
|
|
|
}
|
2020-08-18 01:57:35 +01:00
|
|
|
|
2020-10-30 18:05:30 +00:00
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
onOpenSidebar() {
|
|
|
|
dispatch(openSidebar())
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2020-08-18 01:57:35 +01:00
|
|
|
const mapStateToProps = (state) => ({
|
2020-10-30 18:05:30 +00:00
|
|
|
account: !!me ? state.getIn(['accounts', me]) : undefined,
|
2020-08-18 01:57:35 +01:00
|
|
|
notificationCount: !!me ? state.getIn(['notifications', 'unread']) : 0,
|
|
|
|
homeItemsQueueCount: !!me ? state.getIn(['timelines', 'home', 'totalQueuedItemsCount']) : 0,
|
|
|
|
})
|
|
|
|
|
|
|
|
FooterBar.propTypes = {
|
2020-10-30 18:05:30 +00:00
|
|
|
account: ImmutablePropTypes.map,
|
|
|
|
onOpenSidebar: PropTypes.func.isRequired,
|
2020-08-18 01:57:35 +01:00
|
|
|
notificationCount: PropTypes.number.isRequired,
|
|
|
|
homeItemsQueueCount: PropTypes.number.isRequired,
|
|
|
|
}
|
|
|
|
|
2020-10-30 18:05:30 +00:00
|
|
|
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(FooterBar))
|