From fe963b41cbe9b3cbf1931e6af1c70141bb3da607 Mon Sep 17 00:00:00 2001 From: Maksym Mykhailenko Date: Wed, 24 Apr 2019 16:36:51 +0800 Subject: [PATCH 1/2] fix actions with private topics --- .../detail/containers/FeedContainer.js | 41 ++++++++++++------- src/routes.jsx | 8 +--- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/projects/detail/containers/FeedContainer.js b/src/projects/detail/containers/FeedContainer.js index 75e9367f3..cc291b038 100644 --- a/src/projects/detail/containers/FeedContainer.js +++ b/src/projects/detail/containers/FeedContainer.js @@ -254,8 +254,8 @@ class FeedView extends React.Component { } onShowAllComments(feedId) { - const { feeds } = this.props - const feed = _.find(feeds, feed => feed.id === feedId) + const { feeds } = this.state + const feed = _.find(feeds, { id: feedId }) const stateFeedIdx = _.findIndex(this.state.feeds, (f) => f.id === feedId) // in case we have already have all comments for that feed from the server, // just change the state to show all comments for that FeedId. @@ -271,7 +271,7 @@ class FeedView extends React.Component { showAll: { $push: [feedId] }, feeds: { $splice: [[stateFeedIdx, 1, updatedFeed ]] } })) - this.props.loadFeedComments(feedId, PROJECT_FEED_TYPE_PRIMARY, commentIdsToRetrieve) + this.props.loadFeedComments(feedId, feed.tag, commentIdsToRetrieve) } else { this.setState(update(this.state, { showAll: { $push: [feedId] }, @@ -281,13 +281,14 @@ class FeedView extends React.Component { } onAddNewComment(feedId, content) { - const { currentUser } = this.props + const { currentUser, feeds } = this.props + const feed = _.find(feeds, { id: feedId }) const newComment = { date: new Date(), userId: parseInt(currentUser.id), content } - this.props.addFeedComment(feedId, PROJECT_FEED_TYPE_PRIMARY, newComment) + this.props.addFeedComment(feedId, feed.tag, newComment) } onSaveMessageChange(feedId, messageId, content, editMode) { @@ -309,28 +310,34 @@ class FeedView extends React.Component { onSaveMessage(feedId, message, content) { const newMessage = {...message} + const { feeds } = this.state + const feed = _.find(feeds, { id: feedId }) newMessage.content = content - this.props.saveFeedComment(feedId, PROJECT_FEED_TYPE_PRIMARY, newMessage) + this.props.saveFeedComment(feedId, feed.tag, newMessage) } onDeleteMessage(feedId, postId) { - this.props.deleteFeedComment(feedId, PROJECT_FEED_TYPE_PRIMARY, postId) + const { feeds } = this.state + const feed = _.find(feeds, { id: feedId }) + this.props.deleteFeedComment(feedId, feed.tag, postId) } onEditMessage(feedId, postId) { - const thread = _.find(this.state.feeds, t => feedId === t.id) - const comment = _.find(thread.comments, message => message.id === postId) + const { feeds } = this.state + const feed = _.find(feeds, { id: feedId }) + const comment = _.find(feed.comments, message => message.id === postId) if (!comment.rawContent) { - this.props.getFeedComment(feedId, PROJECT_FEED_TYPE_PRIMARY, postId) + this.props.getFeedComment(feedId, feed.tag, postId) } this.onSaveMessageChange(feedId, postId, null, true) } onEditTopic(feedId) { - const thread = _.find(this.state.feeds, t => feedId === t.id) - const comment = thread.topicMessage + const { feeds } = this.state + const feed = _.find(feeds, { id: feedId }) + const comment = feed.topicMessage if (!comment.rawContent) { - this.props.getFeedComment(feedId, PROJECT_FEED_TYPE_PRIMARY, comment.id) + this.props.getFeedComment(feedId, feed.tag, comment.id) } this.onTopicChange(feedId, comment.id, null, null, true) } @@ -350,11 +357,15 @@ class FeedView extends React.Component { } onSaveTopic(feedId, postId, title, content) { - this.props.saveProjectTopic(feedId, PROJECT_FEED_TYPE_PRIMARY, {postId, title, content}) + const { feeds } = this.state + const feed = _.find(feeds, { id: feedId }) + this.props.saveProjectTopic(feedId, feed.tag, {postId, title, content}) } onDeleteTopic(feedId) { - this.props.deleteProjectTopic(feedId, PROJECT_FEED_TYPE_PRIMARY) + const { feeds } = this.state + const feed = _.find(feeds, { id: feedId }) + this.props.deleteProjectTopic(feedId, feed.tag) } onRefreshFeeds() { diff --git a/src/routes.jsx b/src/routes.jsx index f28d622de..19274b59b 100644 --- a/src/routes.jsx +++ b/src/routes.jsx @@ -77,12 +77,8 @@ class RedirectToProject extends React.Component { if (resp.topic) { const topic = resp.topic const projectId = topic.referenceId - if (topic.tag === PROJECT_FEED_TYPE_PRIMARY) { - history.replace(`/projects/${projectId}/`) - } else if (topic.tag === PROJECT_FEED_TYPE_MESSAGES) { - history.replace({ - pathname: `/projects/${projectId}/discussions/${topic.id}` - }) + if (topic.tag === PROJECT_FEED_TYPE_PRIMARY || topic.tag === PROJECT_FEED_TYPE_MESSAGES) { + history.replace(`/projects/${projectId}#feed-${topic.id}`) } else { history.replace('/projects') } From be78210197d0f206ec77fc2556cfc72845f62acc Mon Sep 17 00:00:00 2001 From: Maksym Mykhailenko Date: Wed, 24 Apr 2019 16:42:35 +0800 Subject: [PATCH 2/2] fix: should be able to delete the first post in the topic, which in reverse order is last one --- src/components/Feed/FeedComments.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Feed/FeedComments.jsx b/src/components/Feed/FeedComments.jsx index 6f47bfa52..da73a6984 100644 --- a/src/components/Feed/FeedComments.jsx +++ b/src/components/Feed/FeedComments.jsx @@ -324,7 +324,7 @@ class FeedComments extends React.Component { allMembers={allMembers} projectMembers={projectMembers} noInfo={item.noInfo} - canDelete={idx !== 0} + canDelete={idx !== comments.length - 1} // cannot delete the first post which is now shown as a last one commentAnchorPrefix={commentAnchorPrefix} >