From 556cede00f5c9a076d0d42b8f9a7b99ea749fa76 Mon Sep 17 00:00:00 2001 From: Surinna Curtis Date: Sat, 1 Jul 2017 16:39:19 -0500 Subject: [PATCH] Local-only option and dropdown all working --- app/javascript/mastodon/actions/compose.js | 8 +++ .../components/advanced_options_dropdown.js | 49 +++++++++++++++---- .../compose/components/compose_form.js | 3 ++ .../containers/advanced_options_container.js | 16 +++++- .../containers/compose_form_container.js | 1 + app/javascript/mastodon/reducers/compose.js | 9 ++++ 6 files changed, 76 insertions(+), 10 deletions(-) diff --git a/app/javascript/mastodon/actions/compose.js b/app/javascript/mastodon/actions/compose.js index 647a52b93..569ddf53e 100644 --- a/app/javascript/mastodon/actions/compose.js +++ b/app/javascript/mastodon/actions/compose.js @@ -24,6 +24,7 @@ export const COMPOSE_SUGGESTION_SELECT = 'COMPOSE_SUGGESTION_SELECT'; export const COMPOSE_MOUNT = 'COMPOSE_MOUNT'; export const COMPOSE_UNMOUNT = 'COMPOSE_UNMOUNT'; +export const COMPOSE_ADVANCED_OPTIONS_CHANGE = 'COMPOSE_ADVANCED_OPTIONS_CHANGE'; export const COMPOSE_SENSITIVITY_CHANGE = 'COMPOSE_SENSITIVITY_CHANGE'; export const COMPOSE_SPOILERNESS_CHANGE = 'COMPOSE_SPOILERNESS_CHANGE'; export const COMPOSE_SPOILER_TEXT_CHANGE = 'COMPOSE_SPOILER_TEXT_CHANGE'; @@ -244,6 +245,13 @@ export function unmountCompose() { }; }; +export function changeComposeAdvancedOption(option) { + return { + type: COMPOSE_ADVANCED_OPTIONS_CHANGE, + option: option, + }; +} + export function changeComposeSensitivity() { return { type: COMPOSE_SENSITIVITY_CHANGE, diff --git a/app/javascript/mastodon/features/compose/components/advanced_options_dropdown.js b/app/javascript/mastodon/features/compose/components/advanced_options_dropdown.js index 35a340565..904e88477 100644 --- a/app/javascript/mastodon/features/compose/components/advanced_options_dropdown.js +++ b/app/javascript/mastodon/features/compose/components/advanced_options_dropdown.js @@ -1,12 +1,30 @@ import React from 'react'; +import PropTypes from 'prop-types'; +import ImmutablePropTypes from 'react-immutable-proptypes'; import IconButton from '../../../components/icon_button'; +import { injectIntl, defineMessages } from 'react-intl'; + +const messages = defineMessages({ + local_only_short: { id: 'advanced-options.local-only.short', defaultMessage: 'Local-only'}, + local_only_long: { id: 'advanced-options.local-only.long', defaultMessage: 'bla' }, + advanced_options_icon_title: { id: 'advanced_options.icon_title', defaultMessage: 'Advanced options' }, +}); const iconStyle = { height: null, lineHeight: '27px', }; +@injectIntl export default class AdvancedOptionsDropdown extends React.PureComponent { + static propTypes = { + values: ImmutablePropTypes.contains({ + do_not_federate: PropTypes.bool.isRequired, + }).isRequired, + onChange: PropTypes.func.isRequired, + intl: PropTypes.object.isRequired, + }; + onToggleDropdown = () => { this.setState({ open: !this.state.open }); }; @@ -31,30 +49,43 @@ export default class AdvancedOptionsDropdown extends React.PureComponent { open: false, }; + handleClick = (e) => { + const option = e.currentTarget.getAttribute('data-index'); + e.preventDefault(); + this.props.onChange(option); + } + setRef = (c) => { this.node = c; } render () { const { open } = this.state; + const { intl, values } = this.props; const options = [ - { icon: 'wifi', shortText: 'Local-only', longText: 'bla' }, + { icon: 'wifi', shortText: messages.local_only_short, longText: messages.local_only_long, key: 'do_not_federate' }, ]; const optionElems = options.map((option) => { - return
-
- -
-
- {option.shortText} - {option.longText} + const active = values.get(option.key) ? 'active' : ''; + return ( +
+
+ +
+
+ {intl.formatMessage(option.shortText)} + {intl.formatMessage(option.longText)} +
-
; + ); }); + return
({ + values: state.getIn(['compose', 'advanced_options']), +}); + +const mapDispatchToProps = dispatch => ({ + + onChange (option) { + dispatch(changeComposeAdvancedOption(option)); + }, + +}); + +export default connect(mapStateToProps, mapDispatchToProps)(AdvancedOptionsDropdown); \ No newline at end of file diff --git a/app/javascript/mastodon/features/compose/containers/compose_form_container.js b/app/javascript/mastodon/features/compose/containers/compose_form_container.js index 12d435ded..1911edbf9 100644 --- a/app/javascript/mastodon/features/compose/containers/compose_form_container.js +++ b/app/javascript/mastodon/features/compose/containers/compose_form_container.js @@ -15,6 +15,7 @@ const mapStateToProps = state => ({ text: state.getIn(['compose', 'text']), suggestion_token: state.getIn(['compose', 'suggestion_token']), suggestions: state.getIn(['compose', 'suggestions']), + advanced_options: state.getIn(['compose', 'advanced_options']), spoiler: state.getIn(['compose', 'spoiler']), spoiler_text: state.getIn(['compose', 'spoiler_text']), privacy: state.getIn(['compose', 'privacy']), diff --git a/app/javascript/mastodon/reducers/compose.js b/app/javascript/mastodon/reducers/compose.js index d0b47a85c..9713f5ed9 100644 --- a/app/javascript/mastodon/reducers/compose.js +++ b/app/javascript/mastodon/reducers/compose.js @@ -16,6 +16,7 @@ import { COMPOSE_SUGGESTIONS_CLEAR, COMPOSE_SUGGESTIONS_READY, COMPOSE_SUGGESTION_SELECT, + COMPOSE_ADVANCED_OPTIONS_CHANGE, COMPOSE_SENSITIVITY_CHANGE, COMPOSE_SPOILERNESS_CHANGE, COMPOSE_SPOILER_TEXT_CHANGE, @@ -29,6 +30,9 @@ import uuid from '../uuid'; const initialState = Immutable.Map({ mounted: false, + advanced_options: Immutable.Map({ + do_not_federate: false + }), sensitive: false, spoiler: false, spoiler_text: '', @@ -140,6 +144,11 @@ export default function compose(state = initialState, action) { return state.set('mounted', true); case COMPOSE_UNMOUNT: return state.set('mounted', false); + case COMPOSE_ADVANCED_OPTIONS_CHANGE: + return state + .set('advanced_options', + state.get('advanced_options').set(action.option, !state.getIn(['advanced_options', action.option]))) + .set('idempotencyKey', uuid()); case COMPOSE_SENSITIVITY_CHANGE: return state .set('sensitive', !state.get('sensitive'))