import React from 'react'; import PropTypes from 'prop-types'; import ImmutablePropTypes from 'react-immutable-proptypes'; import { Link, NavLink, withRouter } from 'react-router-dom'; import { FormattedMessage, injectIntl, defineMessages } from 'react-intl'; import { connect } from 'react-redux'; import classNames from 'classnames'; import NotificationsCounterIcon from './notifications_counter_icon'; import SearchContainer from 'soapbox/features/compose/containers/search_container'; import Avatar from '../../../components/avatar'; import ActionBar from 'soapbox/features/compose/components/action_bar'; import { openModal } from '../../../actions/modal'; import { openSidebar } from '../../../actions/sidebar'; import Icon from '../../../components/icon'; import { changeSetting, getSettings } from 'soapbox/actions/settings'; const messages = defineMessages({ post: { id: 'tabs_bar.post', defaultMessage: 'Post' }, switchToLight: { id: 'tabs_bar.theme_toggle_light', defaultMessage: 'Switch to light theme' }, switchToDark: { id: 'tabs_bar.theme_toggle_dark', defaultMessage: 'Switch to dark theme' }, }); @withRouter class TabsBar extends React.PureComponent { static propTypes = { intl: PropTypes.object.isRequired, history: PropTypes.object.isRequired, onOpenCompose: PropTypes.func, onOpenSidebar: PropTypes.func.isRequired, toggleTheme: PropTypes.func, logo: PropTypes.string, account: ImmutablePropTypes.map, themeMode: PropTypes.string, } state = { collapsed: false, } static contextTypes = { router: PropTypes.object, } setRef = ref => { this.node = ref; } getNavLinks() { const { intl: { formatMessage }, logo, account } = this.props; let links = []; if (logo) { links.push( Logo ); } links.push( ); if (account) { links.push( ); } links.push( ); return links.map((link) => React.cloneElement(link, { 'aria-label': formatMessage({ id: link.props['data-preview-title-id'], }), })); } getNewThemeValue() { if (this.props.themeMode === 'light') return 'dark'; return 'light'; } handleToggleTheme = () => { this.props.toggleTheme(this.getNewThemeValue()); } render() { const { account, onOpenCompose, onOpenSidebar, intl, themeMode } = this.props; const { collapsed } = this.state; const classes = classNames('tabs-bar', { 'tabs-bar--collapsed': collapsed, }); return ( ); } } const mapStateToProps = state => { const me = state.get('me'); const settings = getSettings(state); return { account: state.getIn(['accounts', me]), logo: state.getIn(['soapbox', 'logo']), themeMode: settings.get('themeMode'), }; }; const mapDispatchToProps = (dispatch) => ({ onOpenCompose() { dispatch(openModal('COMPOSE')); }, onOpenSidebar() { dispatch(openSidebar()); }, toggleTheme(setting) { dispatch(changeSetting(['themeMode'], setting)); }, }); export default injectIntl( connect(mapStateToProps, mapDispatchToProps, null, { forwardRef: true } )(TabsBar));