import React from 'react' import PropTypes from 'prop-types' import { connect } from 'react-redux' import ImmutablePropTypes from 'react-immutable-proptypes' import ImmutablePureComponent from 'react-immutable-pure-component' import { injectIntl, defineMessages } from 'react-intl' import { openPopover } from '../../actions/popover' import { fetchShortcuts } from '../../actions/shortcuts' import { me } from '../../initial_state' import Responsive from '../../features/ui/util/responsive_component' import Button from '../button' import Text from '../text' import SidebarSectionTitle from '../sidebar_section_title' import SidebarSectionItem from '../sidebar_section_item' import SidebarLayout from './sidebar_layout' class DefaultSidebar extends ImmutablePureComponent { state = { hoveringShortcuts: false, } componentDidMount() { this.props.onFetchShortcuts() } handleOpenSidebarMorePopover = () => { this.props.openSidebarMorePopover({ targetRef: this.moreBtnRef, position: 'top', }) } handleMouseEnterShortcuts = () => { this.setState({ hoveringShortcuts: true }) } handleMouseLeaveShortcuts = () => { this.setState({ hoveringShortcuts: false }) } setMoreButtonRef = n => { this.moreBtnRef = n } render() { const { intl, notificationCount, homeItemsQueueCount, moreOpen, actions, tabs, title, showBackBtn, shortcuts, unreadChatsCount, } = this.props const { hoveringShortcuts } = this.state if (!me) return null let shortcutItems = [] if (!!shortcuts) { shortcuts.forEach((s) => { shortcutItems.push({ to: s.get('to'), title: s.get('title'), image: s.get('image'), }) }) } return ( {intl.formatMessage(messages.menu)} { shortcutItems.length > 0 &&
{intl.formatMessage(messages.shortcuts)}
{ shortcutItems.map((shortcutItem, i) => ( )) }
} {intl.formatMessage(messages.explore)}
) } } const messages = defineMessages({ explore: { id: 'explore', defaultMessage: 'Explore' }, gabPro: { id: 'gab_pro', defaultMessage: 'GabPRO' }, menu: { id: 'menu', defaultMessage: 'Menu' }, shortcuts: { id: 'navigation_bar.shortcuts', defaultMessage: 'Shortcuts' }, all: { id: 'all', defaultMessage: 'All' }, }) const mapStateToProps = (state) => ({ shortcuts: state.getIn(['shortcuts', 'items']), moreOpen: state.getIn(['popover', 'popoverType']) === 'SIDEBAR_MORE', notificationCount: state.getIn(['notifications', 'unread']), unreadChatsCount: state.getIn(['chats', 'chatsUnreadCount']), homeItemsQueueCount: state.getIn(['timelines', 'home', 'totalQueuedItemsCount']), }) const mapDispatchToProps = (dispatch) => ({ openSidebarMorePopover(props) { dispatch(openPopover('SIDEBAR_MORE', props)) }, onFetchShortcuts() { dispatch(fetchShortcuts()) }, }) DefaultSidebar.propTypes = { intl: PropTypes.object.isRequired, moreOpen: PropTypes.bool, onFetchShortcuts: PropTypes.func.isRequired, openSidebarMorePopover: PropTypes.func.isRequired, notificationCount: PropTypes.number.isRequired, homeItemsQueueCount: PropTypes.number.isRequired, unreadChatsCount: PropTypes.number.isRequired, actions: PropTypes.array, tabs: PropTypes.array, title: PropTypes.string, showBackBtn: PropTypes.bool, shortcuts: ImmutablePropTypes.list, } export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(DefaultSidebar))