about summary refs log tree commit diff
path: root/app/assets/javascripts
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-11-21 10:52:11 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-11-21 10:52:11 +0100
commitd32e0364f9aa2d61080c53489996351d4bd7b1c4 (patch)
treeb30efea75acedb9a7fdf54727c2a54066f976c6d /app/assets/javascripts
parent93577f74e7ec2edee3a1a208513ae7290211e682 (diff)
Switch to compose route when replying and compose is not mounted
Diffstat (limited to 'app/assets/javascripts')
-rw-r--r--app/assets/javascripts/components/actions/compose.jsx29
-rw-r--r--app/assets/javascripts/components/components/status_action_bar.jsx7
-rw-r--r--app/assets/javascripts/components/containers/status_container.jsx4
-rw-r--r--app/assets/javascripts/components/features/compose/index.jsx18
-rw-r--r--app/assets/javascripts/components/features/status/index.jsx5
-rw-r--r--app/assets/javascripts/components/reducers/compose.jsx7
6 files changed, 56 insertions, 14 deletions
diff --git a/app/assets/javascripts/components/actions/compose.jsx b/app/assets/javascripts/components/actions/compose.jsx
index b77a9c727..af3cdbf30 100644
--- a/app/assets/javascripts/components/actions/compose.jsx
+++ b/app/assets/javascripts/components/actions/compose.jsx
@@ -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
+  };
+};
diff --git a/app/assets/javascripts/components/components/status_action_bar.jsx b/app/assets/javascripts/components/components/status_action_bar.jsx
index 051b898bd..dec1decff 100644
--- a/app/assets/javascripts/components/components/status_action_bar.jsx
+++ b/app/assets/javascripts/components/components/status_action_bar.jsx
@@ -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 () {
diff --git a/app/assets/javascripts/components/containers/status_container.jsx b/app/assets/javascripts/components/containers/status_container.jsx
index 2bcb7026c..28756b5ef 100644
--- a/app/assets/javascripts/components/containers/status_container.jsx
+++ b/app/assets/javascripts/components/containers/status_container.jsx
@@ -61,8 +61,8 @@ const makeMapStateToPropsLast = () => {
 
 const mapDispatchToProps = (dispatch) => ({
 
-  onReply (status) {
-    dispatch(replyCompose(status));
+  onReply (status, router) {
+    dispatch(replyCompose(status, router));
   },
 
   onReblog (status) {
diff --git a/app/assets/javascripts/components/features/compose/index.jsx b/app/assets/javascripts/components/features/compose/index.jsx
index a50118bef..5c1b22e00 100644
--- a/app/assets/javascripts/components/features/compose/index.jsx
+++ b/app/assets/javascripts/components/features/compose/index.jsx
@@ -1,12 +1,13 @@
-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>
diff --git a/app/assets/javascripts/components/features/status/index.jsx b/app/assets/javascripts/components/features/status/index.jsx
index 553baf863..0a1528fe9 100644
--- a/app/assets/javascripts/components/features/status/index.jsx
+++ b/app/assets/javascripts/components/features/status/index.jsx
@@ -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) {
diff --git a/app/assets/javascripts/components/reducers/compose.jsx b/app/assets/javascripts/components/reducers/compose.jsx
index 3adff36a3..e6e86d4f5 100644
--- a/app/assets/javascripts/components/reducers/compose.jsx
+++ b/app/assets/javascripts/components/reducers/compose.jsx
@@ -1,4 +1,6 @@
 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: