Reduce composer differences with upstream and simplify code (#2518)

This commit is contained in:
Claire
2023-12-18 13:20:08 +01:00
committed by GitHub
parent 18856371be
commit 3d3fa75c81
7 changed files with 176 additions and 251 deletions

View File

@@ -1,4 +1,3 @@
// Package imports.
import PropTypes from 'prop-types';
import { defineMessages, injectIntl } from 'react-intl';
@@ -9,8 +8,6 @@ import { connect } from 'react-redux';
import Toggle from 'react-toggle';
// Components.
import { IconButton } from 'flavours/glitch/components/icon_button';
import { pollLimits } from 'flavours/glitch/initial_state';
@@ -20,11 +17,6 @@ import PrivacyDropdownContainer from '../containers/privacy_dropdown_container';
import TextIconButton from './text_icon_button';
// Utils.
// Messages.
const messages = defineMessages({
advanced_options_icon_title: {
defaultMessage: 'Advanced options',
@@ -133,12 +125,12 @@ class ComposerOptions extends ImmutablePureComponent {
allowPoll: PropTypes.bool,
hasPoll: PropTypes.bool,
intl: PropTypes.object.isRequired,
onChangeAdvancedOption: PropTypes.func,
onChangeContentType: PropTypes.func,
onTogglePoll: PropTypes.func,
onDoodleOpen: PropTypes.func,
onChangeAdvancedOption: PropTypes.func.isRequired,
onChangeContentType: PropTypes.func.isRequired,
onTogglePoll: PropTypes.func.isRequired,
onDoodleOpen: PropTypes.func.isRequired,
onToggleSpoiler: PropTypes.func,
onUpload: PropTypes.func,
onUpload: PropTypes.func.isRequired,
contentType: PropTypes.string,
resetFileKey: PropTypes.number,
spoiler: PropTypes.bool,
@@ -146,20 +138,17 @@ class ComposerOptions extends ImmutablePureComponent {
isEditing: PropTypes.bool,
};
// Handles file selection.
handleChangeFiles = ({ target: { files } }) => {
const { onUpload } = this.props;
if (files.length && onUpload) {
if (files.length) {
onUpload(files);
}
};
// Handles attachment clicks.
handleClickAttach = (name) => {
const { fileElement } = this;
const { onDoodleOpen } = this.props;
// We switch over the name of the option.
switch (name) {
case 'upload':
if (fileElement) {
@@ -167,14 +156,11 @@ class ComposerOptions extends ImmutablePureComponent {
}
return;
case 'doodle':
if (onDoodleOpen) {
onDoodleOpen();
}
onDoodleOpen();
return;
}
};
// Handles a ref to the file input.
handleRefFileElement = (fileElement) => {
this.fileElement = fileElement;
};
@@ -186,7 +172,6 @@ class ComposerOptions extends ImmutablePureComponent {
return <ToggleOption name={name} text={text} meta={meta} onChangeAdvancedOption={onChangeAdvancedOption} />;
};
// Rendering.
render () {
const {
acceptContentTypes,
@@ -290,7 +275,7 @@ class ComposerOptions extends ImmutablePureComponent {
{onToggleSpoiler && (
<TextIconButton
active={spoiler}
ariaControls='glitch.composer.spoiler.input'
ariaControls='cw-spoiler-input'
label='CW'
onClick={onToggleSpoiler}
title={formatMessage(messages.spoiler)}