Change the create_post component to track the active thread using the event dispatcher so that it stays in sync with the post_list
Этот коммит содержится в:
@@ -152,26 +152,29 @@ module.exports = React.createClass({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rootId) {
|
if (rootId) {
|
||||||
// set the parent id to match the root id so that we're replying to the first post in the thread
|
// only dispatch an event if something changed
|
||||||
var parentId = rootId;
|
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
|
// 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({
|
AppDispatcher.handleViewAction({
|
||||||
type: ActionTypes.RECEIVED_ACTIVE_THREAD_CHANGED,
|
type: ActionTypes.RECEIVED_ACTIVE_THREAD_CHANGED,
|
||||||
root_id: rootId,
|
root_id: "",
|
||||||
parent_id: parentId
|
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 {
|
} else {
|
||||||
if (this.state.rootId || this.state.parentId) {
|
if (this.state.rootId || this.state.parentId) {
|
||||||
this.setState({rootId: "", parentId: ""});
|
// clear the active thread since there no longer is one
|
||||||
|
|
||||||
AppDispatcher.handleViewAction({
|
AppDispatcher.handleViewAction({
|
||||||
type: ActionTypes.RECEIVED_ACTIVE_THREAD_CHANGED,
|
type: ActionTypes.RECEIVED_ACTIVE_THREAD_CHANGED,
|
||||||
root_id: "",
|
root_id: "",
|
||||||
@@ -242,10 +245,12 @@ module.exports = React.createClass({
|
|||||||
},
|
},
|
||||||
componentDidMount: function() {
|
componentDidMount: function() {
|
||||||
ChannelStore.addChangeListener(this._onChange);
|
ChannelStore.addChangeListener(this._onChange);
|
||||||
|
PostStore.addActiveThreadChangedListener(this._onActiveThreadChanged);
|
||||||
this.resizePostHolder();
|
this.resizePostHolder();
|
||||||
},
|
},
|
||||||
componentWillUnmount: function() {
|
componentWillUnmount: function() {
|
||||||
ChannelStore.removeChangeListener(this._onChange);
|
ChannelStore.removeChangeListener(this._onChange);
|
||||||
|
PostStore.removeActiveThreadChangedListener(this._onActiveThreadChanged);
|
||||||
},
|
},
|
||||||
_onChange: function() {
|
_onChange: function() {
|
||||||
var channel_id = ChannelStore.getCurrentId();
|
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 });
|
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() {
|
getInitialState: function() {
|
||||||
PostStore.clearDraftUploads();
|
PostStore.clearDraftUploads();
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user