diff options
author | beatrix <beatrix.bitrot@gmail.com> | 2018-01-06 11:28:36 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-06 11:28:36 -0500 |
commit | a251c42192d0f8aa3481aae47429f4b732bfb623 (patch) | |
tree | 8b9d4b093b1e77561c9c063a2de0aa28b22abc04 /app/javascript/flavours/glitch/features/composer/textarea | |
parent | 2ec9a75a1de70e8b53b58c05e64a4772e5709fa3 (diff) | |
parent | c71d84885511793a1a5ef613e0e4566f85c2ffe5 (diff) |
Merge pull request #296 from glitch-soc/thread-mode
Threaded mode~
Diffstat (limited to 'app/javascript/flavours/glitch/features/composer/textarea')
-rw-r--r-- | app/javascript/flavours/glitch/features/composer/textarea/icons/index.js | 60 | ||||
-rw-r--r-- | app/javascript/flavours/glitch/features/composer/textarea/index.js | 7 |
2 files changed, 67 insertions, 0 deletions
diff --git a/app/javascript/flavours/glitch/features/composer/textarea/icons/index.js b/app/javascript/flavours/glitch/features/composer/textarea/icons/index.js new file mode 100644 index 000000000..049cdd5cd --- /dev/null +++ b/app/javascript/flavours/glitch/features/composer/textarea/icons/index.js @@ -0,0 +1,60 @@ +// Package imports. +import PropTypes from 'prop-types'; +import React from 'react'; +import ImmutablePropTypes from 'react-immutable-proptypes'; +import { defineMessages } from 'react-intl'; + +// Components. +import Icon from 'flavours/glitch/components/icon'; + +// Messages. +const messages = defineMessages({ + localOnly: { + defaultMessage: 'This post is local-only', + id: 'advanced_options.local-only.tooltip', + }, + threadedMode: { + defaultMessage: 'Threaded mode enabled', + id: 'advanced_options.threaded_mode.tooltip', + }, +}); + +// We use an array of tuples here instead of an object because it +// preserves order. +const iconMap = [ + ['do_not_federate', 'home', messages.localOnly], + ['threaded_mode', 'comments', messages.threadedMode], +]; + +// The component. +export default function ComposerTextareaIcons ({ + advancedOptions, + intl, +}) { + + // The result. We just map every active option to its icon. + return ( + <div className='composer--textarea--icons'> + {advancedOptions ? iconMap.map( + ([key, icon, message]) => advancedOptions.get(key) ? ( + <span + className='textarea_icon' + key={key} + title={intl.formatMessage(message)} + > + <Icon + fullwidth + icon={icon} + /> + </span> + ) : null + ) : null} + </div> + ); +} + +// Props. +ComposerTextareaIcons.propTypes = { + advancedOptions: ImmutablePropTypes.map, + intl: PropTypes.object.isRequired, +}; diff --git a/app/javascript/flavours/glitch/features/composer/textarea/index.js b/app/javascript/flavours/glitch/features/composer/textarea/index.js index 2e0b3e3d7..0f5fd4d4d 100644 --- a/app/javascript/flavours/glitch/features/composer/textarea/index.js +++ b/app/javascript/flavours/glitch/features/composer/textarea/index.js @@ -10,6 +10,7 @@ import Textarea from 'react-textarea-autosize'; // Components. import EmojiPicker from 'flavours/glitch/features/emoji_picker'; +import ComposerTextareaIcons from './icons'; import ComposerTextareaSuggestions from './suggestions'; // Utils. @@ -232,6 +233,7 @@ export default class ComposerTextarea extends React.Component { handleRefTextarea, } = this.handlers; const { + advancedOptions, autoFocus, disabled, intl, @@ -249,6 +251,10 @@ export default class ComposerTextarea extends React.Component { <div className='composer--textarea'> <label> <span {...hiddenComponent}><FormattedMessage {...messages.placeholder} /></span> + <ComposerTextareaIcons + advancedOptions={advancedOptions} + intl={intl} + /> <Textarea aria-autocomplete='list' autoFocus={autoFocus} @@ -280,6 +286,7 @@ export default class ComposerTextarea extends React.Component { // Props. ComposerTextarea.propTypes = { + advancedOptions: ImmutablePropTypes.map, autoFocus: PropTypes.bool, disabled: PropTypes.bool, intl: PropTypes.object.isRequired, |