Merge pull request #369 (nice)

main
Eugen Rochko 2016-12-24 01:28:37 +01:00
commit 60f2da1b2f
4 changed files with 50 additions and 10 deletions

View File

@ -24,6 +24,7 @@ export const COMPOSE_UNMOUNT = 'COMPOSE_UNMOUNT';
export const COMPOSE_SENSITIVITY_CHANGE = 'COMPOSE_SENSITIVITY_CHANGE'; export const COMPOSE_SENSITIVITY_CHANGE = 'COMPOSE_SENSITIVITY_CHANGE';
export const COMPOSE_VISIBILITY_CHANGE = 'COMPOSE_VISIBILITY_CHANGE'; export const COMPOSE_VISIBILITY_CHANGE = 'COMPOSE_VISIBILITY_CHANGE';
export const COMPOSE_LISTABILITY_CHANGE = 'COMPOSE_LISTABILITY_CHANGE';
export function changeCompose(text) { export function changeCompose(text) {
return { return {
@ -67,14 +68,14 @@ export function submitCompose() {
in_reply_to_id: getState().getIn(['compose', 'in_reply_to'], null), in_reply_to_id: getState().getIn(['compose', 'in_reply_to'], null),
media_ids: getState().getIn(['compose', 'media_attachments']).map(item => item.get('id')), media_ids: getState().getIn(['compose', 'media_attachments']).map(item => item.get('id')),
sensitive: getState().getIn(['compose', 'sensitive']), sensitive: getState().getIn(['compose', 'sensitive']),
visibility: getState().getIn(['compose', 'private']) ? 'private' : 'public' visibility: getState().getIn(['compose', 'private']) ? 'private' : (getState().getIn(['compose', 'unlisted']) ? 'unlisted' : 'public')
}).then(function (response) { }).then(function (response) {
dispatch(submitComposeSuccess({ ...response.data })); dispatch(submitComposeSuccess({ ...response.data }));
// To make the app more responsive, immediately get the status into the columns // To make the app more responsive, immediately get the status into the columns
dispatch(updateTimeline('home', { ...response.data })); dispatch(updateTimeline('home', { ...response.data }));
if (response.data.in_reply_to_id === null && !getState().getIn(['compose', 'private'])) { if (response.data.in_reply_to_id === null && !getState().getIn(['compose', 'private']) && !getState().getIn(['compose', 'unlisted'])) {
dispatch(updateTimeline('public', { ...response.data })); dispatch(updateTimeline('public', { ...response.data }));
} }
}).catch(function (error) { }).catch(function (error) {
@ -223,3 +224,10 @@ export function changeComposeVisibility(checked) {
checked checked
}; };
}; };
export function changeComposeListability(checked) {
return {
type: COMPOSE_LISTABILITY_CHANGE,
checked
};
};

View File

@ -10,6 +10,7 @@ import { debounce } from 'react-decoration';
import UploadButtonContainer from '../containers/upload_button_container'; import UploadButtonContainer from '../containers/upload_button_container';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import Toggle from 'react-toggle'; import Toggle from 'react-toggle';
import { Motion, spring } from 'react-motion';
const messages = defineMessages({ const messages = defineMessages({
placeholder: { id: 'compose_form.placeholder', defaultMessage: 'What is on your mind?' }, placeholder: { id: 'compose_form.placeholder', defaultMessage: 'What is on your mind?' },
@ -24,9 +25,11 @@ const ComposeForm = React.createClass({
suggestions: ImmutablePropTypes.list, suggestions: ImmutablePropTypes.list,
sensitive: React.PropTypes.bool, sensitive: React.PropTypes.bool,
unlisted: React.PropTypes.bool, unlisted: React.PropTypes.bool,
private: React.PropTypes.bool,
is_submitting: React.PropTypes.bool, is_submitting: React.PropTypes.bool,
is_uploading: React.PropTypes.bool, is_uploading: React.PropTypes.bool,
in_reply_to: ImmutablePropTypes.map, in_reply_to: ImmutablePropTypes.map,
media_count: React.PropTypes.number,
onChange: React.PropTypes.func.isRequired, onChange: React.PropTypes.func.isRequired,
onSubmit: React.PropTypes.func.isRequired, onSubmit: React.PropTypes.func.isRequired,
onCancelReply: React.PropTypes.func.isRequired, onCancelReply: React.PropTypes.func.isRequired,
@ -34,7 +37,8 @@ const ComposeForm = React.createClass({
onFetchSuggestions: React.PropTypes.func.isRequired, onFetchSuggestions: React.PropTypes.func.isRequired,
onSuggestionSelected: React.PropTypes.func.isRequired, onSuggestionSelected: React.PropTypes.func.isRequired,
onChangeSensitivity: React.PropTypes.func.isRequired, onChangeSensitivity: React.PropTypes.func.isRequired,
onChangeVisibility: React.PropTypes.func.isRequired onChangeVisibility: React.PropTypes.func.isRequired,
onChangeListability: React.PropTypes.func.isRequired,
}, },
mixins: [PureRenderMixin], mixins: [PureRenderMixin],
@ -74,6 +78,10 @@ const ComposeForm = React.createClass({
this.props.onChangeVisibility(e.target.checked); this.props.onChangeVisibility(e.target.checked);
}, },
handleChangeListability (e) {
this.props.onChangeListability(e.target.checked);
},
componentDidUpdate (prevProps) { componentDidUpdate (prevProps) {
if (prevProps.in_reply_to !== this.props.in_reply_to) { if (prevProps.in_reply_to !== this.props.in_reply_to) {
this.autosuggestTextarea.textarea.focus(); this.autosuggestTextarea.textarea.focus();
@ -121,10 +129,23 @@ const ComposeForm = React.createClass({
<span style={{ display: 'inline-block', verticalAlign: 'middle', marginBottom: '14px', marginLeft: '8px', color: '#9baec8' }}><FormattedMessage id='compose_form.private' defaultMessage='Mark as private' /></span> <span style={{ display: 'inline-block', verticalAlign: 'middle', marginBottom: '14px', marginLeft: '8px', color: '#9baec8' }}><FormattedMessage id='compose_form.private' defaultMessage='Mark as private' /></span>
</label> </label>
<label style={{ display: 'block', lineHeight: '24px', verticalAlign: 'middle' }}> <Motion defaultStyle={{ opacity: 100, height: 39.5 }} style={{ opacity: spring(this.props.private ? 0 : 100), height: spring(this.props.private ? 0 : 39.5) }}>
{({ opacity, height }) =>
<label style={{ display: 'block', lineHeight: '24px', verticalAlign: 'middle', height: `${height}px`, overflow: 'hidden', opacity: opacity / 100 }}>
<Toggle checked={this.props.unlisted} onChange={this.handleChangeListability} />
<span style={{ display: 'inline-block', verticalAlign: 'middle', marginBottom: '14px', marginLeft: '8px', color: '#9baec8' }}><FormattedMessage id='compose_form.unlisted' defaultMessage='Do not display in public timeline' /></span>
</label>
}
</Motion>
<Motion defaultStyle={{ opacity: 100, height: 39.5 }} style={{ opacity: spring(this.props.media_count === 0 ? 0 : 100), height: spring(this.props.media_count === 0 ? 0 : 39.5) }}>
{({ opacity, height }) =>
<label style={{ display: 'block', lineHeight: '24px', verticalAlign: 'middle', height: `${height}px`, overflow: 'hidden', opacity: opacity / 100 }}>
<Toggle checked={this.props.sensitive} onChange={this.handleChangeSensitivity} /> <Toggle checked={this.props.sensitive} onChange={this.handleChangeSensitivity} />
<span style={{ display: 'inline-block', verticalAlign: 'middle', marginBottom: '14px', marginLeft: '8px', color: '#9baec8' }}><FormattedMessage id='compose_form.sensitive' defaultMessage='Mark content as sensitive' /></span> <span style={{ display: 'inline-block', verticalAlign: 'middle', marginBottom: '14px', marginLeft: '8px', color: '#9baec8' }}><FormattedMessage id='compose_form.sensitive' defaultMessage='Mark content as sensitive' /></span>
</label> </label>
}
</Motion>
</div> </div>
); );
} }

View File

@ -8,7 +8,8 @@ import {
fetchComposeSuggestions, fetchComposeSuggestions,
selectComposeSuggestion, selectComposeSuggestion,
changeComposeSensitivity, changeComposeSensitivity,
changeComposeVisibility changeComposeVisibility,
changeComposeListability
} from '../../../actions/compose'; } from '../../../actions/compose';
import { makeGetStatus } from '../../../selectors'; import { makeGetStatus } from '../../../selectors';
@ -21,10 +22,12 @@ const makeMapStateToProps = () => {
suggestion_token: state.getIn(['compose', 'suggestion_token']), suggestion_token: state.getIn(['compose', 'suggestion_token']),
suggestions: state.getIn(['compose', 'suggestions']), suggestions: state.getIn(['compose', 'suggestions']),
sensitive: state.getIn(['compose', 'sensitive']), sensitive: state.getIn(['compose', 'sensitive']),
unlisted: state.getIn(['compose', 'unlisted']),
private: state.getIn(['compose', 'private']), private: state.getIn(['compose', 'private']),
is_submitting: state.getIn(['compose', 'is_submitting']), is_submitting: state.getIn(['compose', 'is_submitting']),
is_uploading: state.getIn(['compose', 'is_uploading']), is_uploading: state.getIn(['compose', 'is_uploading']),
in_reply_to: getStatus(state, state.getIn(['compose', 'in_reply_to'])) in_reply_to: getStatus(state, state.getIn(['compose', 'in_reply_to'])),
media_count: state.getIn(['compose', 'media_attachments']).size
}; };
}; };
@ -63,6 +66,10 @@ const mapDispatchToProps = function (dispatch) {
onChangeVisibility (checked) { onChangeVisibility (checked) {
dispatch(changeComposeVisibility(checked)); dispatch(changeComposeVisibility(checked));
},
onChangeListability (checked) {
dispatch(changeComposeListability(checked));
} }
} }
}; };

View File

@ -17,7 +17,8 @@ import {
COMPOSE_SUGGESTIONS_READY, COMPOSE_SUGGESTIONS_READY,
COMPOSE_SUGGESTION_SELECT, COMPOSE_SUGGESTION_SELECT,
COMPOSE_SENSITIVITY_CHANGE, COMPOSE_SENSITIVITY_CHANGE,
COMPOSE_VISIBILITY_CHANGE COMPOSE_VISIBILITY_CHANGE,
COMPOSE_LISTABILITY_CHANGE
} from '../actions/compose'; } from '../actions/compose';
import { TIMELINE_DELETE } from '../actions/timelines'; import { TIMELINE_DELETE } from '../actions/timelines';
import { ACCOUNT_SET_SELF } from '../actions/accounts'; import { ACCOUNT_SET_SELF } from '../actions/accounts';
@ -26,6 +27,7 @@ import Immutable from 'immutable';
const initialState = Immutable.Map({ const initialState = Immutable.Map({
mounted: false, mounted: false,
sensitive: false, sensitive: false,
unlisted: false,
private: false, private: false,
text: '', text: '',
in_reply_to: null, in_reply_to: null,
@ -93,6 +95,8 @@ export default function compose(state = initialState, action) {
return state.set('sensitive', action.checked); return state.set('sensitive', action.checked);
case COMPOSE_VISIBILITY_CHANGE: case COMPOSE_VISIBILITY_CHANGE:
return state.set('private', action.checked); return state.set('private', action.checked);
case COMPOSE_LISTABILITY_CHANGE:
return state.set('unlisted', action.checked);
case COMPOSE_CHANGE: case COMPOSE_CHANGE:
return state.set('text', action.text); return state.set('text', action.text);
case COMPOSE_REPLY: case COMPOSE_REPLY: