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,
};
};
-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');
+ }
};
};
});
};
};
+
+export function mountCompose() {
+ return {
+ type: COMPOSE_MOUNT
+ };
+};
+
+export function unmountCompose() {
+ return {
+ type: COMPOSE_UNMOUNT
+ };
+};
});
const StatusActionBar = React.createClass({
+
+ contextTypes: {
+ router: React.PropTypes.object
+ },
+
propTypes: {
status: ImmutablePropTypes.map.isRequired,
onReply: React.PropTypes.func,
mixins: [PureRenderMixin],
handleReplyClick () {
- this.props.onReply(this.props.status);
+ this.props.onReply(this.props.status, this.context.router);
},
handleFavouriteClick () {
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({
mixins: [PureRenderMixin],
componentDidMount () {
+ this.props.dispatch(mountCompose());
this.props.dispatch(fetchSuggestions());
},
+ componentWillUnmount () {
+ this.props.dispatch(unmountCompose());
+ },
+
render () {
return (
<Drawer>
};
const Status = React.createClass({
+ contextTypes: {
+ router: React.PropTypes.object
+ },
propTypes: {
params: React.PropTypes.object.isRequired,
},
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,
import Immutable from 'immutable';
const initialState = Immutable.Map({
+ mounted: false,
text: '',
in_reply_to: null,
is_submitting: false,
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: