bigbuffet-rw/app/soapbox/features/compose/components/action_bar.js

104 lines
4.4 KiB
JavaScript
Raw Normal View History

2020-03-27 13:59:38 -07:00
import React from 'react';
import { connect } from 'react-redux';
import { openModal } from '../../../actions/modal';
import PropTypes from 'prop-types';
import DropdownMenuContainer from '../../../containers/dropdown_menu_container';
2020-05-28 15:52:07 -07:00
import { isStaff } from 'soapbox/utils/accounts';
2020-03-27 13:59:38 -07:00
import { defineMessages, injectIntl } from 'react-intl';
2020-05-28 15:52:07 -07:00
import { logOut } from 'soapbox/actions/auth';
2020-03-27 13:59:38 -07:00
const messages = defineMessages({
profile: { id: 'account.profile', defaultMessage: 'Profile' },
messages: { id: 'navigation_bar.messages', defaultMessage: 'Messages' },
2020-04-25 16:27:13 -07:00
lists: { id: 'navigation_bar.lists', defaultMessage: 'Lists' },
2020-07-29 14:08:36 -07:00
bookmarks: { id: 'navigation_bar.bookmarks', defaultMessage: 'Bookmarks' },
2020-03-27 13:59:38 -07:00
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' },
2020-05-18 16:48:33 -07:00
admin_settings: { id: 'navigation_bar.admin_settings', defaultMessage: 'Admin settings' },
2020-08-23 13:21:19 -07:00
soapbox_config: { id: 'navigation_bar.soapbox_config', defaultMessage: 'Soapbox config' },
2020-09-27 09:18:25 -07:00
import_data: { id: 'navigation_bar.import_data', defaultMessage: 'Import data' },
2020-06-05 12:58:59 -07:00
security: { id: 'navigation_bar.security', defaultMessage: 'Security' },
2020-03-27 13:59:38 -07:00
logout: { id: 'navigation_bar.logout', defaultMessage: 'Logout' },
keyboard_shortcuts: { id: 'navigation_bar.keyboard_shortcuts', defaultMessage: 'Hotkeys' },
});
2020-04-17 15:14:04 -07:00
const mapStateToProps = state => {
const me = state.get('me');
return {
meUsername: state.getIn(['accounts', me, 'username']),
2020-05-18 16:48:33 -07:00
isStaff: isStaff(state.getIn(['accounts', me])),
2020-04-17 15:14:04 -07:00
};
};
const mapDispatchToProps = (dispatch, { intl }) => ({
2020-03-27 13:59:38 -07:00
onOpenHotkeys() {
dispatch(openModal('HOTKEYS'));
},
2020-04-11 12:41:13 -07:00
onClickLogOut(e) {
dispatch(logOut(intl));
2020-04-11 12:41:13 -07:00
e.preventDefault();
},
2020-03-27 13:59:38 -07:00
});
class ActionBar extends React.PureComponent {
static propTypes = {
intl: PropTypes.object.isRequired,
size: PropTypes.number,
2020-04-14 14:37:17 -07:00
onOpenHotkeys: PropTypes.func.isRequired,
onClickLogOut: PropTypes.func.isRequired,
2020-04-17 15:14:04 -07:00
meUsername: PropTypes.string,
2020-05-18 16:48:33 -07:00
isStaff: PropTypes.bool.isRequired,
2020-03-27 13:59:38 -07:00
};
2020-05-18 16:48:33 -07:00
static defaultProps = {
isStaff: false,
}
2020-03-27 13:59:38 -07:00
handleHotkeyClick = () => {
this.props.onOpenHotkeys();
}
render() {
2020-05-18 16:48:33 -07:00
const { intl, onClickLogOut, meUsername, isStaff } = this.props;
2020-03-27 13:59:38 -07:00
const size = this.props.size || 16;
let menu = [];
menu.push({ text: intl.formatMessage(messages.profile), to: `/@${meUsername}` });
2020-04-25 16:27:13 -07:00
menu.push({ text: intl.formatMessage(messages.lists), to: '/lists' });
2020-07-29 14:08:36 -07:00
menu.push({ text: intl.formatMessage(messages.bookmarks), to: '/bookmarks' });
2020-03-27 13:59:38 -07:00
menu.push(null);
menu.push({ text: intl.formatMessage(messages.follow_requests), to: '/follow_requests' });
menu.push({ text: intl.formatMessage(messages.mutes), to: '/mutes' });
menu.push({ text: intl.formatMessage(messages.blocks), to: '/blocks' });
menu.push({ text: intl.formatMessage(messages.domain_blocks), to: '/domain_blocks' });
2020-08-04 13:21:42 -07:00
menu.push({ text: intl.formatMessage(messages.filters), to: '/filters' });
2020-03-27 13:59:38 -07:00
menu.push(null);
menu.push({ text: intl.formatMessage(messages.keyboard_shortcuts), action: this.handleHotkeyClick });
2020-05-18 16:48:33 -07:00
if (isStaff) {
menu.push({ text: intl.formatMessage(messages.admin_settings), href: '/pleroma/admin', newTab: true });
2020-08-23 19:48:31 -07:00
menu.push({ text: intl.formatMessage(messages.soapbox_config), to: '/soapbox/config' });
2020-05-18 16:48:33 -07:00
}
2020-04-11 12:41:13 -07:00
menu.push({ text: intl.formatMessage(messages.preferences), to: '/settings/preferences' });
2020-09-27 09:18:25 -07:00
menu.push({ text: intl.formatMessage(messages.import_data), to: '/settings/import' });
2020-06-05 12:58:59 -07:00
menu.push({ text: intl.formatMessage(messages.security), to: '/auth/edit' });
2020-04-11 12:41:13 -07:00
menu.push({ text: intl.formatMessage(messages.logout), to: '/auth/sign_out', action: onClickLogOut });
2020-03-27 13:59:38 -07:00
return (
2020-04-14 11:44:40 -07:00
<div className='compose__action-bar' style={{ 'marginTop':'-6px' }}>
2020-03-27 13:59:38 -07:00
<div className='compose__action-bar-dropdown'>
<DropdownMenuContainer items={menu} icon='chevron-down' size={size} direction='right' />
</div>
</div>
);
}
2020-04-14 11:44:40 -07:00
2020-03-27 13:59:38 -07:00
}
2020-04-17 15:14:04 -07:00
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(ActionBar));