Switch to compose route when replying and compose is not mounted

pull/6/head
Eugen Rochko 2016-11-21 10:52:11 +01:00
parent 93577f74e7
commit d32e0364f9
6 changed files with 56 additions and 14 deletions

View File

@ -19,6 +19,9 @@ export const COMPOSE_SUGGESTIONS_CLEAR = 'COMPOSE_SUGGESTIONS_CLEAR';
export const COMPOSE_SUGGESTIONS_READY = 'COMPOSE_SUGGESTIONS_READY'; export const COMPOSE_SUGGESTIONS_READY = 'COMPOSE_SUGGESTIONS_READY';
export const COMPOSE_SUGGESTION_SELECT = 'COMPOSE_SUGGESTION_SELECT'; export const COMPOSE_SUGGESTION_SELECT = 'COMPOSE_SUGGESTION_SELECT';
export const COMPOSE_MOUNT = 'COMPOSE_MOUNT';
export const COMPOSE_UNMOUNT = 'COMPOSE_UNMOUNT';
export function changeCompose(text) { export function changeCompose(text) {
return { return {
type: COMPOSE_CHANGE, type: COMPOSE_CHANGE,
@ -26,10 +29,16 @@ export function changeCompose(text) {
}; };
}; };
export function replyCompose(status) { export function replyCompose(status, router) {
return { return (dispatch, getState) => {
type: COMPOSE_REPLY, dispatch({
status: status type: COMPOSE_REPLY,
status: status
});
if (!getState().getIn(['compose', 'mounted'])) {
router.push('/statuses/new');
}
}; };
}; };
@ -176,3 +185,15 @@ export function selectComposeSuggestion(position, accountId) {
}); });
}; };
}; };
export function mountCompose() {
return {
type: COMPOSE_MOUNT
};
};
export function unmountCompose() {
return {
type: COMPOSE_UNMOUNT
};
};

View File

@ -13,6 +13,11 @@ const messages = defineMessages({
}); });
const StatusActionBar = React.createClass({ const StatusActionBar = React.createClass({
contextTypes: {
router: React.PropTypes.object
},
propTypes: { propTypes: {
status: ImmutablePropTypes.map.isRequired, status: ImmutablePropTypes.map.isRequired,
onReply: React.PropTypes.func, onReply: React.PropTypes.func,
@ -25,7 +30,7 @@ const StatusActionBar = React.createClass({
mixins: [PureRenderMixin], mixins: [PureRenderMixin],
handleReplyClick () { handleReplyClick () {
this.props.onReply(this.props.status); this.props.onReply(this.props.status, this.context.router);
}, },
handleFavouriteClick () { handleFavouriteClick () {

View File

@ -61,8 +61,8 @@ const makeMapStateToPropsLast = () => {
const mapDispatchToProps = (dispatch) => ({ const mapDispatchToProps = (dispatch) => ({
onReply (status) { onReply (status, router) {
dispatch(replyCompose(status)); dispatch(replyCompose(status, router));
}, },
onReblog (status) { onReblog (status) {

View File

@ -1,12 +1,13 @@
import Drawer from './components/drawer'; import Drawer from './components/drawer';
import ComposeFormContainer from './containers/compose_form_container'; import ComposeFormContainer from './containers/compose_form_container';
import UploadFormContainer from './containers/upload_form_container'; import UploadFormContainer from './containers/upload_form_container';
import NavigationContainer from './containers/navigation_container'; import NavigationContainer from './containers/navigation_container';
import PureRenderMixin from 'react-addons-pure-render-mixin'; import PureRenderMixin from 'react-addons-pure-render-mixin';
import SuggestionsContainer from './containers/suggestions_container'; import SuggestionsContainer from './containers/suggestions_container';
import SearchContainer from './containers/search_container'; import SearchContainer from './containers/search_container';
import { fetchSuggestions } from '../../actions/suggestions'; import { fetchSuggestions } from '../../actions/suggestions';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { mountCompose, unmountCompose } from '../../actions/compose';
const Compose = React.createClass({ const Compose = React.createClass({
@ -17,9 +18,14 @@ const Compose = React.createClass({
mixins: [PureRenderMixin], mixins: [PureRenderMixin],
componentDidMount () { componentDidMount () {
this.props.dispatch(mountCompose());
this.props.dispatch(fetchSuggestions()); this.props.dispatch(fetchSuggestions());
}, },
componentWillUnmount () {
this.props.dispatch(unmountCompose());
},
render () { render () {
return ( return (
<Drawer> <Drawer>

View File

@ -38,6 +38,9 @@ const makeMapStateToProps = () => {
}; };
const Status = React.createClass({ const Status = React.createClass({
contextTypes: {
router: React.PropTypes.object
},
propTypes: { propTypes: {
params: React.PropTypes.object.isRequired, params: React.PropTypes.object.isRequired,
@ -64,7 +67,7 @@ const Status = React.createClass({
}, },
handleReplyClick (status) { handleReplyClick (status) {
this.props.dispatch(replyCompose(status)); this.props.dispatch(replyCompose(status, this.context.router));
}, },
handleReblogClick (status) { handleReblogClick (status) {

View File

@ -1,4 +1,6 @@
import { import {
COMPOSE_MOUNT,
COMPOSE_UNMOUNT,
COMPOSE_CHANGE, COMPOSE_CHANGE,
COMPOSE_REPLY, COMPOSE_REPLY,
COMPOSE_REPLY_CANCEL, COMPOSE_REPLY_CANCEL,
@ -20,6 +22,7 @@ import { ACCOUNT_SET_SELF } from '../actions/accounts';
import Immutable from 'immutable'; import Immutable from 'immutable';
const initialState = Immutable.Map({ const initialState = Immutable.Map({
mounted: false,
text: '', text: '',
in_reply_to: null, in_reply_to: null,
is_submitting: false, is_submitting: false,
@ -80,6 +83,10 @@ const insertSuggestion = (state, position, completion) => {
export default function compose(state = initialState, action) { export default function compose(state = initialState, action) {
switch(action.type) { switch(action.type) {
case COMPOSE_MOUNT:
return state.set('mounted', true);
case COMPOSE_UNMOUNT:
return state.set('mounted', false);
case COMPOSE_CHANGE: case COMPOSE_CHANGE:
return state.set('text', action.text); return state.set('text', action.text);
case COMPOSE_REPLY: case COMPOSE_REPLY: