import React from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { Link, NavLink } from 'react-router-dom'; import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { injectIntl, defineMessages } from 'react-intl'; import classNames from 'classnames'; import Avatar from './avatar'; import IconButton from './icon_button'; import Icon from './icon'; import DisplayName from './display_name'; import { closeSidebar } from '../actions/sidebar'; import { shortNumberFormat } from '../utils/numbers'; import { isStaff } from '../utils/accounts'; import { makeGetAccount } from '../selectors'; import { logOut } from 'soapbox/actions/auth'; import ThemeToggle from '../features/ui/components/theme_toggle'; const messages = defineMessages({ followers: { id: 'account.followers', defaultMessage: 'Followers' }, follows: { id: 'account.follows', defaultMessage: 'Follows' }, profile: { id: 'account.profile', defaultMessage: 'Profile' }, messages: { id: 'navigation_bar.messages', defaultMessage: 'Messages' }, preferences: { id: 'navigation_bar.preferences', defaultMessage: 'Preferences' }, follow_requests: { id: 'navigation_bar.follow_requests', defaultMessage: 'Follow requests' }, blocks: { id: 'navigation_bar.blocks', defaultMessage: 'Blocked users' }, domain_blocks: { id: 'navigation_bar.domain_blocks', defaultMessage: 'Hidden domains' }, mutes: { id: 'navigation_bar.mutes', defaultMessage: 'Muted users' }, filters: { id: 'navigation_bar.filters', defaultMessage: 'Muted words' }, admin_settings: { id: 'navigation_bar.admin_settings', defaultMessage: 'Admin settings' }, security: { id: 'navigation_bar.security', defaultMessage: 'Security' }, logout: { id: 'navigation_bar.logout', defaultMessage: 'Logout' }, lists: { id: 'column.lists', defaultMessage: 'Lists' }, bookmarks: { id: 'column.bookmarks', defaultMessage: 'Bookmarks' }, apps: { id: 'tabs_bar.apps', defaultMessage: 'Apps' }, news: { id: 'tabs_bar.news', defaultMessage: 'News' }, donate: { id: 'donate', defaultMessage: 'Donate' }, }); const mapStateToProps = state => { const me = state.get('me'); const getAccount = makeGetAccount(); return { account: getAccount(state, me), sidebarOpen: state.get('sidebar').sidebarOpen, donateUrl: state.getIn(['patron', 'instance', 'url']), isStaff: isStaff(state.getIn(['accounts', me])), }; }; const mapDispatchToProps = (dispatch) => ({ onClose() { dispatch(closeSidebar()); }, onClickLogOut(e) { dispatch(logOut()); e.preventDefault(); }, }); export default @connect(mapStateToProps, mapDispatchToProps) @injectIntl class SidebarMenu extends ImmutablePureComponent { static propTypes = { intl: PropTypes.object.isRequired, account: ImmutablePropTypes.map, sidebarOpen: PropTypes.bool, onClose: PropTypes.func.isRequired, isStaff: PropTypes.bool.isRequired, }; static defaultProps = { isStaff: false, } render() { const { sidebarOpen, onClose, intl, account, onClickLogOut, donateUrl, isStaff } = this.props; if (!account) return null; const acct = account.get('acct'); const classes = classNames('sidebar-menu__root', { 'sidebar-menu__root--visible': sidebarOpen, }); return (
Account Info
{shortNumberFormat(account.get('followers_count'))} {intl.formatMessage(messages.followers)} {shortNumberFormat(account.get('following_count'))} {intl.formatMessage(messages.follows)}
{intl.formatMessage(messages.profile)} {intl.formatMessage(messages.messages)} {donateUrl ? {intl.formatMessage(messages.donate)} : ''} {intl.formatMessage(messages.lists)} {intl.formatMessage(messages.bookmarks)}
{intl.formatMessage(messages.follow_requests)} {intl.formatMessage(messages.blocks)} {intl.formatMessage(messages.domain_blocks)} {intl.formatMessage(messages.mutes)} {/* {intl.formatMessage(messages.filters)} */} { isStaff && {intl.formatMessage(messages.admin_settings)} } {intl.formatMessage(messages.preferences)} {intl.formatMessage(messages.security)}
{intl.formatMessage(messages.logout)}
); } }