You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
3.9 KiB
138 lines
3.9 KiB
7 years ago
|
// Package imports //
|
||
8 years ago
|
import React from 'react';
|
||
8 years ago
|
import PropTypes from 'prop-types';
|
||
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||
8 years ago
|
import Toggle from 'react-toggle';
|
||
8 years ago
|
import { injectIntl, defineMessages } from 'react-intl';
|
||
|
|
||
7 years ago
|
// Mastodon imports //
|
||
7 years ago
|
import IconButton from '../../../../mastodon/components/icon_button';
|
||
7 years ago
|
|
||
8 years ago
|
const messages = defineMessages({
|
||
8 years ago
|
local_only_short: { id: 'advanced-options.local-only.short', defaultMessage: 'Local-only' },
|
||
8 years ago
|
local_only_long: { id: 'advanced-options.local-only.long', defaultMessage: 'Do not post to other instances' },
|
||
8 years ago
|
advanced_options_icon_title: { id: 'advanced_options.icon_title', defaultMessage: 'Advanced options' },
|
||
|
});
|
||
8 years ago
|
|
||
8 years ago
|
const iconStyle = {
|
||
|
height: null,
|
||
|
lineHeight: '27px',
|
||
|
};
|
||
|
|
||
7 years ago
|
class AdvancedOptionToggle extends React.PureComponent {
|
||
7 years ago
|
|
||
|
static propTypes = {
|
||
7 years ago
|
onChange: PropTypes.func.isRequired,
|
||
|
active: PropTypes.bool.isRequired,
|
||
7 years ago
|
name: PropTypes.string.isRequired,
|
||
7 years ago
|
shortText: PropTypes.string.isRequired,
|
||
|
longText: PropTypes.string.isRequired,
|
||
|
}
|
||
|
|
||
|
onToggle = () => {
|
||
|
this.props.onChange(this.props.name);
|
||
|
}
|
||
|
|
||
|
render() {
|
||
|
const { active, shortText, longText } = this.props;
|
||
7 years ago
|
return (
|
||
|
<div role='button' tabIndex='0' className='advanced-options-dropdown__option' onClick={this.onToggle}>
|
||
|
<div className='advanced-options-dropdown__option__toggle'>
|
||
|
<Toggle checked={active} onChange={this.onToggle} />
|
||
7 years ago
|
</div>
|
||
7 years ago
|
<div className='advanced-options-dropdown__option__content'>
|
||
|
<strong>{shortText}</strong>
|
||
|
{longText}
|
||
|
</div>
|
||
|
</div>
|
||
|
);
|
||
7 years ago
|
}
|
||
7 years ago
|
|
||
7 years ago
|
}
|
||
|
|
||
8 years ago
|
@injectIntl
|
||
7 years ago
|
export default class ComposeAdvancedOptions extends React.PureComponent {
|
||
8 years ago
|
|
||
8 years ago
|
static propTypes = {
|
||
|
values: ImmutablePropTypes.contains({
|
||
|
do_not_federate: PropTypes.bool.isRequired,
|
||
|
}).isRequired,
|
||
|
onChange: PropTypes.func.isRequired,
|
||
|
intl: PropTypes.object.isRequired,
|
||
|
};
|
||
|
|
||
8 years ago
|
onToggleDropdown = () => {
|
||
8 years ago
|
this.setState({ open: !this.state.open });
|
||
8 years ago
|
};
|
||
|
|
||
|
onGlobalClick = (e) => {
|
||
|
if (e.target !== this.node && !this.node.contains(e.target) && this.state.open) {
|
||
|
this.setState({ open: false });
|
||
|
}
|
||
|
}
|
||
|
|
||
|
componentDidMount () {
|
||
|
window.addEventListener('click', this.onGlobalClick);
|
||
|
window.addEventListener('touchstart', this.onGlobalClick);
|
||
|
}
|
||
|
|
||
|
componentWillUnmount () {
|
||
|
window.removeEventListener('click', this.onGlobalClick);
|
||
|
window.removeEventListener('touchstart', this.onGlobalClick);
|
||
|
}
|
||
|
|
||
|
state = {
|
||
|
open: false,
|
||
|
};
|
||
|
|
||
8 years ago
|
handleClick = (e) => {
|
||
|
const option = e.currentTarget.getAttribute('data-index');
|
||
|
e.preventDefault();
|
||
|
this.props.onChange(option);
|
||
|
}
|
||
|
|
||
8 years ago
|
setRef = (c) => {
|
||
|
this.node = c;
|
||
|
}
|
||
|
|
||
|
render () {
|
||
|
const { open } = this.state;
|
||
8 years ago
|
const { intl, values } = this.props;
|
||
8 years ago
|
|
||
|
const options = [
|
||
7 years ago
|
{ icon: 'wifi', shortText: messages.local_only_short, longText: messages.local_only_long, key: 'do_not_federate' },
|
||
8 years ago
|
];
|
||
8 years ago
|
|
||
8 years ago
|
const anyEnabled = values.some((enabled) => enabled);
|
||
8 years ago
|
const optionElems = options.map((option) => {
|
||
8 years ago
|
return (
|
||
7 years ago
|
<AdvancedOptionToggle
|
||
|
onChange={this.props.onChange}
|
||
|
active={values.get(option.key)}
|
||
|
key={option.key}
|
||
|
name={option.key}
|
||
|
shortText={intl.formatMessage(option.shortText)}
|
||
|
longText={intl.formatMessage(option.longText)}
|
||
|
/>
|
||
8 years ago
|
);
|
||
8 years ago
|
});
|
||
8 years ago
|
|
||
8 years ago
|
return (<div ref={this.setRef} className={`advanced-options-dropdown ${open ? 'open' : ''} ${anyEnabled ? 'active' : ''} `}>
|
||
8 years ago
|
<div className='advanced-options-dropdown__value'>
|
||
8 years ago
|
<IconButton
|
||
|
className='advanced-options-dropdown__value'
|
||
8 years ago
|
title={intl.formatMessage(messages.advanced_options_icon_title)}
|
||
8 years ago
|
icon='ellipsis-h' active={open || anyEnabled}
|
||
8 years ago
|
size={18}
|
||
8 years ago
|
style={iconStyle}
|
||
8 years ago
|
onClick={this.onToggleDropdown}
|
||
|
/>
|
||
8 years ago
|
</div>
|
||
|
<div className='advanced-options-dropdown__dropdown'>
|
||
8 years ago
|
{optionElems}
|
||
8 years ago
|
</div>
|
||
8 years ago
|
</div>);
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
}
|