From 03e64029e3e29c52be5c66894c55e6349a45a1da Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Mon, 26 Dec 2016 12:47:30 +0530 Subject: [PATCH] Github issue #596, Status update: a comment post remains in the composer window after being posted -- Fixed --- src/projects/detail/containers/FeedContainer.js | 13 ++++++++++--- .../detail/containers/MessagesContainer.js | 14 +++++++++++--- src/projects/reducers/projectTopics.js | 2 +- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/projects/detail/containers/FeedContainer.js b/src/projects/detail/containers/FeedContainer.js index f621ca219..44be02ded 100644 --- a/src/projects/detail/containers/FeedContainer.js +++ b/src/projects/detail/containers/FeedContainer.js @@ -54,7 +54,7 @@ class FeedView extends React.Component { } componentWillReceiveProps(nextProps) { - this.init(nextProps) + this.init(nextProps, this.props) } componentWillUnmount() { @@ -128,11 +128,18 @@ class FeedView extends React.Component { return item } - init(props) { + init(props, prevProps) { const { feeds } = props this.setState({ feeds: feeds.map((feed) => { - return this.mapFeed(feed, this.state.showAll.indexOf(feed.id) > -1) + // finds the same feed from previous props, if exists + let prevFeed + if (prevProps && prevProps.feeds) { + prevFeed = _.find(prevProps.feeds, f => feed.id === f.id) + } + // reset new comment if we were adding comment and there is no error in doing so + const resetNewComment = prevFeed && prevFeed.isAddingComment && !feed.isAddingComment && !feed.error + return this.mapFeed(feed, this.state.showAll.indexOf(feed.id) > -1, resetNewComment) }).filter(item => item) }) } diff --git a/src/projects/detail/containers/MessagesContainer.js b/src/projects/detail/containers/MessagesContainer.js index 6b3455a84..34cbec399 100644 --- a/src/projects/detail/containers/MessagesContainer.js +++ b/src/projects/detail/containers/MessagesContainer.js @@ -63,7 +63,7 @@ class MessagesView extends React.Component { } componentWillReceiveProps(nextProps) { - this.init(nextProps) + this.init(nextProps, this.props) } componentWillUnmount() { @@ -138,7 +138,7 @@ class MessagesView extends React.Component { return item } - init(props) { + init(props, prevProps) { const { activeThreadId } = this.state const propsThreadId = _.get(props, 'location.state.threadId', null) const threadId = activeThreadId ? activeThreadId : propsThreadId @@ -149,9 +149,17 @@ class MessagesView extends React.Component { this.setState({ scrollPosition: activeThreadIndex * 71, threads: props.threads.map((thread, idx) => { + // finds the same thread from previous props, if exists + let prevThread + if (prevProps && prevProps.threads) { + prevThread = _.find(prevProps.threads, t => thread.id === t.id) + } + // reset new message if we were adding message and there is no error in doing so + const resetNewMessage = prevThread && prevThread.isAddingComment && !thread.isAddingComment && !thread.error return this.mapFeed(thread, idx === activeThreadIndex, - this.state.showAll.indexOf(thread.id) > -1) + this.state.showAll.indexOf(thread.id) > -1, + resetNewMessage) }).filter(item => item) }) } diff --git a/src/projects/reducers/projectTopics.js b/src/projects/reducers/projectTopics.js index c3fa25651..01c2c16dd 100644 --- a/src/projects/reducers/projectTopics.js +++ b/src/projects/reducers/projectTopics.js @@ -243,7 +243,7 @@ export const projectTopics = function (state=initialState, action) { const feed = state.feeds[tag].topics[feedIndex] const updatedFeed = update (feed, { isAddingComment : { $set : false }, - error: { $set: false } + error: { $set: true } }) const feedUpdateQuery = {} feedUpdateQuery[tag] = { topics: { $splice: [[feedIndex, 1, updatedFeed]] } }