Skip to content
Snippets Groups Projects
Commit d32e0364 authored by Eugen Rochko's avatar Eugen Rochko
Browse files

Switch to compose route when replying and compose is not mounted

parent 93577f74
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,9 @@ export const COMPOSE_SUGGESTIONS_CLEAR = 'COMPOSE_SUGGESTIONS_CLEAR';
export const COMPOSE_SUGGESTIONS_READY = 'COMPOSE_SUGGESTIONS_READY';
export const COMPOSE_SUGGESTION_SELECT = 'COMPOSE_SUGGESTION_SELECT';
export const COMPOSE_MOUNT = 'COMPOSE_MOUNT';
export const COMPOSE_UNMOUNT = 'COMPOSE_UNMOUNT';
export function changeCompose(text) {
return {
type: COMPOSE_CHANGE,
......@@ -26,10 +29,16 @@ export function changeCompose(text) {
};
};
export function replyCompose(status) {
return {
type: COMPOSE_REPLY,
status: status
export function replyCompose(status, router) {
return (dispatch, getState) => {
dispatch({
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
};
};
......@@ -13,6 +13,11 @@ const messages = defineMessages({
});
const StatusActionBar = React.createClass({
contextTypes: {
router: React.PropTypes.object
},
propTypes: {
status: ImmutablePropTypes.map.isRequired,
onReply: React.PropTypes.func,
......@@ -25,7 +30,7 @@ const StatusActionBar = React.createClass({
mixins: [PureRenderMixin],
handleReplyClick () {
this.props.onReply(this.props.status);
this.props.onReply(this.props.status, this.context.router);
},
handleFavouriteClick () {
......
......@@ -61,8 +61,8 @@ const makeMapStateToPropsLast = () => {
const mapDispatchToProps = (dispatch) => ({
onReply (status) {
dispatch(replyCompose(status));
onReply (status, router) {
dispatch(replyCompose(status, router));
},
onReblog (status) {
......
import Drawer from './components/drawer';
import Drawer from './components/drawer';
import ComposeFormContainer from './containers/compose_form_container';
import UploadFormContainer from './containers/upload_form_container';
import NavigationContainer from './containers/navigation_container';
import PureRenderMixin from 'react-addons-pure-render-mixin';
import UploadFormContainer from './containers/upload_form_container';
import NavigationContainer from './containers/navigation_container';
import PureRenderMixin from 'react-addons-pure-render-mixin';
import SuggestionsContainer from './containers/suggestions_container';
import SearchContainer from './containers/search_container';
import SearchContainer from './containers/search_container';
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({
......@@ -17,9 +18,14 @@ const Compose = React.createClass({
mixins: [PureRenderMixin],
componentDidMount () {
this.props.dispatch(mountCompose());
this.props.dispatch(fetchSuggestions());
},
componentWillUnmount () {
this.props.dispatch(unmountCompose());
},
render () {
return (
<Drawer>
......
......@@ -38,6 +38,9 @@ const makeMapStateToProps = () => {
};
const Status = React.createClass({
contextTypes: {
router: React.PropTypes.object
},
propTypes: {
params: React.PropTypes.object.isRequired,
......@@ -64,7 +67,7 @@ const Status = React.createClass({
},
handleReplyClick (status) {
this.props.dispatch(replyCompose(status));
this.props.dispatch(replyCompose(status, this.context.router));
},
handleReblogClick (status) {
......
import {
COMPOSE_MOUNT,
COMPOSE_UNMOUNT,
COMPOSE_CHANGE,
COMPOSE_REPLY,
COMPOSE_REPLY_CANCEL,
......@@ -20,6 +22,7 @@ import { ACCOUNT_SET_SELF } from '../actions/accounts';
import Immutable from 'immutable';
const initialState = Immutable.Map({
mounted: false,
text: '',
in_reply_to: null,
is_submitting: false,
......@@ -80,6 +83,10 @@ const insertSuggestion = (state, position, completion) => {
export default function compose(state = initialState, action) {
switch(action.type) {
case COMPOSE_MOUNT:
return state.set('mounted', true);
case COMPOSE_UNMOUNT:
return state.set('mounted', false);
case COMPOSE_CHANGE:
return state.set('text', action.text);
case COMPOSE_REPLY:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment