0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Fixed comment content missing after unhiding them

fixes https://github.com/TryGhost/Team/issues/1786
This commit is contained in:
Simon Backx 2022-08-12 14:22:48 +02:00
parent de30741fce
commit 11c3dcc77a
2 changed files with 22 additions and 10 deletions

View file

@ -102,28 +102,26 @@ async function hideComment({state, adminApi, data: comment}) {
};
}
async function showComment({state, adminApi, data: comment}) {
async function showComment({state, api, adminApi, data: comment}) {
await adminApi.showComment(comment.id);
// We need to refetch the comment, to make sure we have an up to date HTML content
// + all relations are loaded as the current member (not the admin)
const data = await api.comments.read(comment.id);
const updatedComment = data.comments[0];
return {
comments: state.comments.map((c) => {
const replies = c.replies.map((r) => {
if (r.id === comment.id) {
return {
...r,
status: 'published'
};
return updatedComment;
}
return r;
});
if (c.id === comment.id) {
return {
...c,
status: 'published',
replies
};
return updatedComment;
}
return {

View file

@ -199,6 +199,20 @@ function setupGhostApi({siteUrl = window.location.origin, apiUrl, apiKey}) {
}
});
},
read(commentId) {
const url = endpointFor({type: 'members', resource: `comments/${commentId}`});
return makeRequest({
url,
method: 'GET',
credentials: 'same-origin'
}).then(function (res) {
if (res.ok) {
return res.json();
} else {
throw new Error('Failed to read comment');
}
});
},
like({comment}) {
const url = endpointFor({type: 'members', resource: `comments/${comment.id}/like`});
return makeRequest({