2023-05-24 01:15:17 +10:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-23 18:52:27 +10:00
|
|
|
import { PureComponent } from 'react';
|
2023-05-24 01:15:17 +10:00
|
|
|
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
|
|
|
2017-12-06 09:02:27 +11:00
|
|
|
import { connect } from 'react-redux';
|
2023-05-24 01:15:17 +10:00
|
|
|
|
2022-11-06 09:06:32 +11:00
|
|
|
import { changeListEditorTitle, submitListEditor } from 'mastodon/actions/lists';
|
|
|
|
import Button from 'mastodon/components/button';
|
2017-12-06 09:02:27 +11:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
label: { id: 'lists.new.title_placeholder', defaultMessage: 'New list title' },
|
|
|
|
title: { id: 'lists.new.create', defaultMessage: 'Add list' },
|
|
|
|
});
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
value: state.getIn(['listEditor', 'title']),
|
|
|
|
disabled: state.getIn(['listEditor', 'isSubmitting']),
|
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
|
|
|
onChange: value => dispatch(changeListEditorTitle(value)),
|
|
|
|
onSubmit: () => dispatch(submitListEditor(true)),
|
|
|
|
});
|
|
|
|
|
2023-05-23 18:52:27 +10:00
|
|
|
class NewListForm extends PureComponent {
|
2017-12-06 09:02:27 +11:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
value: PropTypes.string.isRequired,
|
|
|
|
disabled: PropTypes.bool,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
onChange: PropTypes.func.isRequired,
|
|
|
|
onSubmit: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
handleChange = e => {
|
|
|
|
this.props.onChange(e.target.value);
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2017-12-06 09:02:27 +11:00
|
|
|
|
2017-12-06 22:18:10 +11:00
|
|
|
handleSubmit = e => {
|
|
|
|
e.preventDefault();
|
|
|
|
this.props.onSubmit();
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2017-12-06 09:02:27 +11:00
|
|
|
|
|
|
|
handleClick = () => {
|
|
|
|
this.props.onSubmit();
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2017-12-06 09:02:27 +11:00
|
|
|
|
|
|
|
render () {
|
|
|
|
const { value, disabled, intl } = this.props;
|
|
|
|
|
|
|
|
const label = intl.formatMessage(messages.label);
|
|
|
|
const title = intl.formatMessage(messages.title);
|
|
|
|
|
|
|
|
return (
|
2017-12-06 22:18:10 +11:00
|
|
|
<form className='column-inline-form' onSubmit={this.handleSubmit}>
|
2017-12-06 09:02:27 +11:00
|
|
|
<label>
|
|
|
|
<span style={{ display: 'none' }}>{label}</span>
|
|
|
|
|
|
|
|
<input
|
|
|
|
className='setting-text'
|
|
|
|
value={value}
|
|
|
|
disabled={disabled}
|
|
|
|
onChange={this.handleChange}
|
|
|
|
placeholder={label}
|
|
|
|
/>
|
|
|
|
</label>
|
|
|
|
|
2022-11-06 09:06:32 +11:00
|
|
|
<Button
|
2019-08-04 03:10:39 +10:00
|
|
|
disabled={disabled || !value}
|
2022-11-06 09:06:32 +11:00
|
|
|
text={title}
|
2017-12-06 09:02:27 +11:00
|
|
|
onClick={this.handleClick}
|
|
|
|
/>
|
2017-12-06 22:18:10 +11:00
|
|
|
</form>
|
2017-12-06 09:02:27 +11:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-03-24 13:17:53 +11:00
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(NewListForm));
|