Skip to content
This repository has been archived by the owner on Nov 15, 2018. It is now read-only.

Commit

Permalink
fix: (#451) 修复动态、帖子、资讯详情第一页的置顶评论重复显示的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
mutoe committed Jul 2, 2018
1 parent b7d06f1 commit 050bb8b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
18 changes: 10 additions & 8 deletions src/page/feed/feedDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -413,18 +413,20 @@ export default {
this.fetchComing = true;
getFeedComments({ feedId: this.feedID, after })
.then(({ data: { pinneds = [], comments = [] } }) => {
!after && (this.pinnedCom = pinneds);
if (!after) {
this.pinnedCom = pinneds;
// 过滤第一页中的置顶评论
const pinnedIds = pinneds.map(p => p.id);
this.comments = comments.filter(c => pinnedIds.indexOf(c.id) < 0);
} else {
this.comments = [...this.comments, ...comments];
}
if (comments.length) {
(this.comments = after
? [...this.comments, ...comments]
: comments),
(this.maxComId = comments[comments.length - 1].id);
this.maxComId = comments[comments.length - 1].id;
}
comments.length === limit
? (this.noMoreCom = false)
: (this.noMoreCom = true);
this.noMoreCom = comments.length !== limit;
this.$nextTick(() => {
this.fetchComing = false;
this.loading = false;
Expand Down
19 changes: 11 additions & 8 deletions src/page/group/GroupPostDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -191,20 +191,23 @@ export default {
this.fetchComing = true;
getPostComments(this.postID, { after })
.then(({ data: { pinneds = [], comments = [] } }) => {
pinneds &&
pinneds.length &&
(this.pinnedCom = after ? [...this.pinneds, ...pinneds] : pinneds);
if (!after) {
this.pinnedCom = pinneds;
// 过滤第一页中的置顶评论
const pinnedIds = pinneds.map(p => p.id);
this.comments = comments.filter(c => pinnedIds.indexOf(c.id) < 0);
} else {
this.comments = [...this.comments, ...comments];
}
if (comments.length) {
this.comments = after ? [...this.comments, ...comments] : comments;
this.maxComId = comments[comments.length - 1].id;
}
comments.length === limit
? (this.noMoreCom = false)
: (this.noMoreCom = true);
this.noMoreCom = comments.length !== limit;
this.$nextTick(() => {
this.fetchComing = false;
this.loading = false;
this.fetchComing = false;
});
})
.catch(() => {
Expand Down
20 changes: 15 additions & 5 deletions src/page/news/newsDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ import md from "@/util/markdown.js";
import wechatShare from "@/util/wechatShare.js";
import ArticleCard from "@/page/article/ArticleCard.vue";
import CommentItem from "@/page/article/ArticleComment.vue";
import { limit } from "@/api/api.js";
import {
deleteNewsComment,
applyTopNews,
Expand Down Expand Up @@ -281,11 +282,20 @@ export default {
getNewsComments(this.newsID, { after })
.then(({ data: { pinneds = [], comments = [] } }) => {
this.pinnedCom = after ? [...this.pinneds, ...pinneds] : pinneds;
this.comments = after ? [...this.comments, ...comments] : comments;
comments.length
? (this.maxComId = comments[comments.length - 1].id)
: (this.noMoreCom = true);
if (!after) {
this.pinnedCom = pinneds;
// 过滤第一页中的置顶评论
const pinnedIds = pinneds.map(p => p.id);
this.comments = comments.filter(c => pinnedIds.indexOf(c.id) < 0);
} else {
this.comments = [...this.comments, ...comments];
}
if (comments.length) {
this.maxComId = comments[comments.length - 1].id;
}
this.noMoreCom = comments.lenght !== limit;
this.fetchComing = false;
})
.catch(() => {
Expand Down

0 comments on commit 050bb8b

Please sign in to comment.