mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Fixed like/unlike on replies
This commit is contained in:
parent
857dbbc315
commit
9735665ca1
1 changed files with 37 additions and 4 deletions
|
@ -125,14 +125,31 @@ async function likeComment({state, api, data: comment}) {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
comments: state.comments.map((c) => {
|
comments: state.comments.map((c) => {
|
||||||
|
const replies = c.replies.map((r) => {
|
||||||
|
if (r.id === comment.id) {
|
||||||
|
return {
|
||||||
|
...r,
|
||||||
|
liked: true,
|
||||||
|
likes_count: r.likes_count + 1
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
});
|
||||||
|
|
||||||
if (c.id === comment.id) {
|
if (c.id === comment.id) {
|
||||||
return {
|
return {
|
||||||
...c,
|
...c,
|
||||||
liked: true,
|
liked: true,
|
||||||
likes_count: c.likes_count + 1
|
likes_count: c.likes_count + 1,
|
||||||
|
replies
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return c;
|
|
||||||
|
return {
|
||||||
|
...c,
|
||||||
|
replies
|
||||||
|
};
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -142,14 +159,30 @@ async function unlikeComment({state, api, data: comment}) {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
comments: state.comments.map((c) => {
|
comments: state.comments.map((c) => {
|
||||||
|
const replies = c.replies.map((r) => {
|
||||||
|
if (r.id === comment.id) {
|
||||||
|
return {
|
||||||
|
...r,
|
||||||
|
liked: false,
|
||||||
|
likes_count: r.likes_count - 1
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
});
|
||||||
|
|
||||||
if (c.id === comment.id) {
|
if (c.id === comment.id) {
|
||||||
return {
|
return {
|
||||||
...c,
|
...c,
|
||||||
liked: false,
|
liked: false,
|
||||||
likes_count: c.likes_count - 1
|
likes_count: c.likes_count - 1,
|
||||||
|
replies
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return c;
|
return {
|
||||||
|
...c,
|
||||||
|
replies
|
||||||
|
};
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue