Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/projects/detail/containers/FeedContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class FeedView extends React.Component {
}

componentWillReceiveProps(nextProps) {
this.init(nextProps)
this.init(nextProps, this.props)
}

componentWillUnmount() {
Expand Down Expand Up @@ -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)
})
}
Expand Down
14 changes: 11 additions & 3 deletions src/projects/detail/containers/MessagesContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class MessagesView extends React.Component {
}

componentWillReceiveProps(nextProps) {
this.init(nextProps)
this.init(nextProps, this.props)
}

componentWillUnmount() {
Expand Down Expand Up @@ -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
Expand All @@ -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)
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/projects/reducers/projectTopics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]] } }
Expand Down