summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorhmhealey <harrisonmhealey@gmail.com>2015-07-16 16:03:06 -0400
committerhmhealey <harrisonmhealey@gmail.com>2015-07-21 11:56:27 -0400
commit644c78755cb7cf8ef818106b9629df1018d0d736 (patch)
treee107baed9edf0a7b7a551cc1d7d55b3671975b4c /web
parent25b2e75dc664bfb80470713331c33c88e726dcf5 (diff)
downloadchat-644c78755cb7cf8ef818106b9629df1018d0d736.tar.gz
chat-644c78755cb7cf8ef818106b9629df1018d0d736.tar.bz2
chat-644c78755cb7cf8ef818106b9629df1018d0d736.zip
Change the create_post component to track the active thread using the event dispatcher so that it stays in sync with the post_list
Diffstat (limited to 'web')
-rw-r--r--web/react/components/create_post.jsx38
1 files changed, 24 insertions, 14 deletions
diff --git a/web/react/components/create_post.jsx b/web/react/components/create_post.jsx
index 681ca252f..7bc5e2481 100644
--- a/web/react/components/create_post.jsx
+++ b/web/react/components/create_post.jsx
@@ -152,26 +152,29 @@ module.exports = React.createClass({
}
if (rootId) {
- // set the parent id to match the root id so that we're replying to the first post in the thread
- var parentId = rootId;
-
- // alert the post list so that it can display the active thread
+ // only dispatch an event if something changed
+ if (rootId != this.state.rootId) {
+ // set the parent id to match the root id so that we're replying to the first post in the thread
+ var parentId = rootId;
+
+ // alert the post list so that it can display the active thread
+ AppDispatcher.handleViewAction({
+ type: ActionTypes.RECEIVED_ACTIVE_THREAD_CHANGED,
+ root_id: rootId,
+ parent_id: parentId
+ });
+ }
+ } else {
+ // we couldn't find a post to respond to so clear the active thread
AppDispatcher.handleViewAction({
type: ActionTypes.RECEIVED_ACTIVE_THREAD_CHANGED,
- root_id: rootId,
- parent_id: parentId
+ root_id: "",
+ parent_id: ""
});
-
- // save these so that we don't need to recalculate them when we send this post
- this.setState({rootId: rootId, parentId: parentId});
- } else {
- // we couldn't find a post to respond to
- this.setState({rootId: "", parentId: ""});
}
} else {
if (this.state.rootId || this.state.parentId) {
- this.setState({rootId: "", parentId: ""});
-
+ // clear the active thread since there no longer is one
AppDispatcher.handleViewAction({
type: ActionTypes.RECEIVED_ACTIVE_THREAD_CHANGED,
root_id: "",
@@ -242,10 +245,12 @@ module.exports = React.createClass({
},
componentDidMount: function() {
ChannelStore.addChangeListener(this._onChange);
+ PostStore.addActiveThreadChangedListener(this._onActiveThreadChanged);
this.resizePostHolder();
},
componentWillUnmount: function() {
ChannelStore.removeChangeListener(this._onChange);
+ PostStore.removeActiveThreadChangedListener(this._onActiveThreadChanged);
},
_onChange: function() {
var channel_id = ChannelStore.getCurrentId();
@@ -262,6 +267,11 @@ module.exports = React.createClass({
this.setState({ channel_id: channel_id, messageText: messageText, initialText: messageText, submitting: false, post_error: null, previews: previews, uploadsInProgress: uploadsInProgress });
}
},
+ _onActiveThreadChanged: function(rootId, parentId) {
+ // note that we register for our own events and set the state from there so we don't need to manually set
+ // our state and dispatch an event each time the active thread changes
+ this.setState({"rootId": rootId, "parentId": parentId});
+ },
getInitialState: function() {
PostStore.clearDraftUploads();