From f1a22e33e26f124cb1b3131e56678001b9e43bc3 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Sat, 20 Apr 2019 23:02:09 +0200 Subject: [PATCH] Inline spoiler input --- .../compose/components/compose_form.js | 51 ++++++--- .../glitch/features/composer/spoiler/index.js | 107 ------------------ 2 files changed, 38 insertions(+), 120 deletions(-) delete mode 100644 app/javascript/flavours/glitch/features/composer/spoiler/index.js diff --git a/app/javascript/flavours/glitch/features/compose/components/compose_form.js b/app/javascript/flavours/glitch/features/compose/components/compose_form.js index 10b51d920a..fdc4401f65 100644 --- a/app/javascript/flavours/glitch/features/compose/components/compose_form.js +++ b/app/javascript/flavours/glitch/features/compose/components/compose_form.js @@ -7,7 +7,6 @@ import ImmutablePureComponent from 'react-immutable-pure-component'; // Components. import ComposerOptions from '../../composer/options'; import ComposerPublisher from '../../composer/publisher'; -import ComposerSpoiler from '../../composer/spoiler'; import ComposerTextarea from '../../composer/textarea'; import ComposerUploadForm from '../../composer/upload_form'; import ComposerPollForm from '../../composer/poll_form'; @@ -23,6 +22,7 @@ const messages = defineMessages({ defaultMessage: 'At least one media attachment is lacking a description. Consider describing all media attachments for the visually impaired before sending your toot.' }, missingDescriptionConfirm: { id: 'confirmations.missing_media_description.confirm', defaultMessage: 'Send anyway' }, + spoiler_placeholder: { id: 'compose_form.spoiler_placeholder', defaultMessage: 'Write your warning here' }, }); export default @injectIntl @@ -124,6 +124,25 @@ class ComposeForm extends ImmutablePureComponent { } } + handleKeyDown = ({ ctrlKey, keyCode, metaKey, altKey }) => { + // We submit the status on control/meta + enter. + if (keyCode === 13 && (ctrlKey || metaKey)) { + handleSubmit(); + } + + // Submit the status with secondary visibility on alt + enter. + if (keyCode === 13 && altKey) { + handleSecondarySubmit(); + } + } + + // When the escape key is released, we focus the UI. + handleKeyUp = ({ key }) => { + if (key === 'Escape') { + document.querySelector('.ui').parentElement.focus(); + } + } + // Submits the status. handleSubmit = () => { const { textarea: { value }, uploadForm } = this; @@ -181,7 +200,7 @@ class ComposeForm extends ImmutablePureComponent { // Sets a reference to the CW field. handleRefSpoilerText = (spoilerComponent) => { if (spoilerComponent) { - this.spoilerText = spoilerComponent.spoilerText; + this.spoilerText = spoilerComponent; } } @@ -260,14 +279,12 @@ class ComposeForm extends ImmutablePureComponent { render () { const { - handleChangeSpoiler, handleEmoji, handleSecondarySubmit, handleSelect, handleSubmit, handleRefUploadForm, handleRefTextarea, - handleRefSpoilerText, } = this; const { acceptContentTypes, @@ -317,15 +334,23 @@ class ComposeForm extends ImmutablePureComponent { -