Track caretCount as part of createPost's state so that we don't unnecessarily search for a thread to reply to when the user is typing
Этот коммит содержится в:
@@ -102,7 +102,7 @@ module.exports = React.createClass({
|
|||||||
$(".post-list-holder-by-time").perfectScrollbar('update');
|
$(".post-list-holder-by-time").perfectScrollbar('update');
|
||||||
|
|
||||||
if (this.state.rootId || this.state.parentId) {
|
if (this.state.rootId || this.state.parentId) {
|
||||||
this.setState({rootId: "", parentId: ""});
|
this.setState({rootId: "", parentId: "", caretCount: 0});
|
||||||
|
|
||||||
// clear the active thread since we've now sent our message
|
// clear the active thread since we've now sent our message
|
||||||
AppDispatcher.handleViewAction({
|
AppDispatcher.handleViewAction({
|
||||||
@@ -138,6 +138,12 @@ module.exports = React.createClass({
|
|||||||
// the number of carets indicates how many message threads back we're replying to
|
// the number of carets indicates how many message threads back we're replying to
|
||||||
var caretCount = replyMatch[0].length;
|
var caretCount = replyMatch[0].length;
|
||||||
|
|
||||||
|
// note that if someone else replies to this thread while a user is typing a reply, the message to which they're replying
|
||||||
|
// won't change unless they change the number of carets. this is probably the desired behaviour since we don't want the
|
||||||
|
// active message thread to change without the user noticing
|
||||||
|
if (caretCount != this.state.caretCount) {
|
||||||
|
this.setState({caretCount: caretCount});
|
||||||
|
|
||||||
var posts = PostStore.getCurrentPosts();
|
var posts = PostStore.getCurrentPosts();
|
||||||
|
|
||||||
var rootId = "";
|
var rootId = "";
|
||||||
@@ -147,16 +153,15 @@ module.exports = React.createClass({
|
|||||||
var postId = posts.order[i];
|
var postId = posts.order[i];
|
||||||
|
|
||||||
if (posts.posts[postId].parent_id === "") {
|
if (posts.posts[postId].parent_id === "") {
|
||||||
if (caretCount == 1) {
|
caretCount -= 1;
|
||||||
|
|
||||||
|
if (caretCount < 1) {
|
||||||
rootId = postId;
|
rootId = postId;
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
caretCount -= 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rootId) {
|
|
||||||
// only dispatch an event if something changed
|
// only dispatch an event if something changed
|
||||||
if (rootId != this.state.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
|
// set the parent id to match the root id so that we're replying to the first post in the thread
|
||||||
@@ -169,16 +174,11 @@ module.exports = React.createClass({
|
|||||||
parent_id: parentId
|
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: "",
|
|
||||||
parent_id: ""
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.state.rootId || this.state.parentId) {
|
if (this.state.caretCount > 0) {
|
||||||
|
this.setState({caretCount: 0});
|
||||||
|
|
||||||
// clear the active thread since there no longer is one
|
// 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,
|
||||||
@@ -287,7 +287,7 @@ module.exports = React.createClass({
|
|||||||
previews = draft['previews'];
|
previews = draft['previews'];
|
||||||
messageText = draft['message'];
|
messageText = draft['message'];
|
||||||
}
|
}
|
||||||
return { channel_id: ChannelStore.getCurrentId(), messageText: messageText, uploadsInProgress: 0, previews: previews, submitting: false, initialText: messageText };
|
return { channel_id: ChannelStore.getCurrentId(), messageText: messageText, uploadsInProgress: 0, previews: previews, submitting: false, initialText: messageText, caretCount: 0 };
|
||||||
},
|
},
|
||||||
setUploads: function(val) {
|
setUploads: function(val) {
|
||||||
var oldInProgress = this.state.uploadsInProgress
|
var oldInProgress = this.state.uploadsInProgress
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user