mirror of
https://github.com/wassname/talk.git
synced 2026-07-14 11:18:50 +08:00
Featured comments error in permalink view, handling permaview moderation and handling replies moderation
This commit is contained in:
@@ -341,7 +341,7 @@ export default class Comment extends React.Component {
|
||||
emit,
|
||||
commentClassNames = []
|
||||
} = this.props;
|
||||
|
||||
|
||||
if (this.commentIsRejected(comment)) {
|
||||
return <CommentTombstone action="rejected" />;
|
||||
}
|
||||
|
||||
@@ -127,6 +127,27 @@ export const withSetCommentStatus = withMutation(
|
||||
commentId,
|
||||
status,
|
||||
},
|
||||
optimisticResponse: {
|
||||
setCommentStatus: {
|
||||
__typename: 'SetCommentStatusResponse',
|
||||
errors: null,
|
||||
}
|
||||
},
|
||||
update: (proxy) => {
|
||||
|
||||
const fragment = gql`
|
||||
fragment Talk_SetCommentStatus on Comment {
|
||||
status
|
||||
}`;
|
||||
|
||||
const fragmentId = `Comment_${commentId}`;
|
||||
|
||||
const data = proxy.readFragment({fragment, id: fragmentId});
|
||||
|
||||
data.status = status;
|
||||
|
||||
proxy.writeFragment({fragment, id: fragmentId, data});
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
@@ -49,36 +49,39 @@ export default {
|
||||
AddTag: ({variables}) => ({
|
||||
updateQueries: {
|
||||
CoralEmbedStream_Embed: (previous) => {
|
||||
let updated = previous;
|
||||
|
||||
if (variables.name !== 'FEATURED') {
|
||||
return;
|
||||
}
|
||||
|
||||
const comment = findCommentInEmbedQuery(previous, variables.id);
|
||||
|
||||
const updated = update(previous, {
|
||||
asset: {
|
||||
comments: {
|
||||
nodes: {
|
||||
$apply: (nodes) => nodes.map((node) => {
|
||||
if (node.id === variables.id) {
|
||||
node.status = 'ACCEPTED';
|
||||
}
|
||||
|
||||
return node;
|
||||
})
|
||||
}
|
||||
},
|
||||
featuredComments: {
|
||||
nodes: {
|
||||
$apply: (nodes) => prependNewNodes(nodes, [comment]),
|
||||
}
|
||||
},
|
||||
featuredCommentsCount: {
|
||||
$apply: (value) => value + 1
|
||||
|
||||
if (previous.asset.comments) {
|
||||
updated = update(previous, {
|
||||
asset: {
|
||||
comments: {
|
||||
nodes: {
|
||||
$apply: (nodes) => nodes.map((node) => {
|
||||
if (node.id === variables.id) {
|
||||
node.status = 'ACCEPTED';
|
||||
}
|
||||
|
||||
return node;
|
||||
})
|
||||
}
|
||||
},
|
||||
featuredComments: {
|
||||
nodes: {
|
||||
$apply: (nodes) => prependNewNodes(nodes, [comment]),
|
||||
}
|
||||
},
|
||||
featuredCommentsCount: {
|
||||
$apply: (value) => value + 1
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return updated;
|
||||
},
|
||||
@@ -87,24 +90,27 @@ export default {
|
||||
RemoveTag: ({variables}) => ({
|
||||
updateQueries: {
|
||||
CoralEmbedStream_Embed: (previous) => {
|
||||
|
||||
let updated = previous;
|
||||
|
||||
if (variables.name !== 'FEATURED') {
|
||||
return;
|
||||
}
|
||||
|
||||
const updated = update(previous, {
|
||||
asset: {
|
||||
featuredComments: {
|
||||
nodes: {
|
||||
$apply: (nodes) =>
|
||||
nodes.filter((n) => n.id !== variables.id)
|
||||
if (previous.asset.comments) {
|
||||
updated = update(previous, {
|
||||
asset: {
|
||||
featuredComments: {
|
||||
nodes: {
|
||||
$apply: (nodes) =>
|
||||
nodes.filter((n) => n.id !== variables.id)
|
||||
}
|
||||
},
|
||||
featuredCommentsCount: {
|
||||
$apply: (value) => value - 1
|
||||
}
|
||||
},
|
||||
featuredCommentsCount: {
|
||||
$apply: (value) => value - 1
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return updated;
|
||||
},
|
||||
|
||||
@@ -3,6 +3,7 @@ import {getErrorMessages} from 'plugin-api/beta/client/utils';
|
||||
import {withSetCommentStatus} from 'plugin-api/beta/client/hocs';
|
||||
import {notify} from 'plugin-api/beta/client/actions/notification';
|
||||
import ApproveCommentAction from '../components/ApproveCommentAction';
|
||||
import isNil from 'lodash/isNil';
|
||||
|
||||
class ApproveCommentActionContainer extends React.Component {
|
||||
|
||||
@@ -15,7 +16,7 @@ class ApproveCommentActionContainer extends React.Component {
|
||||
status: 'ACCEPTED'
|
||||
});
|
||||
|
||||
if (result.data.setCommentStatus.errors) {
|
||||
if (!isNil(result.data.setCommentStatus)) {
|
||||
throw result.data.setCommentStatus.errors;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import {getErrorMessages} from 'plugin-api/beta/client/utils';
|
||||
import {withSetCommentStatus} from 'plugin-api/beta/client/hocs';
|
||||
import {notify} from 'plugin-api/beta/client/actions/notification';
|
||||
import RejectCommentAction from '../components/RejectCommentAction';
|
||||
import isNil from 'lodash/isNil';
|
||||
|
||||
class RejectCommentActionContainer extends React.Component {
|
||||
|
||||
@@ -15,7 +16,7 @@ class RejectCommentActionContainer extends React.Component {
|
||||
status: 'REJECTED'
|
||||
});
|
||||
|
||||
if (result.data.setCommentStatus.errors) {
|
||||
if (!isNil(result.data.setCommentStatus)) {
|
||||
throw result.data.setCommentStatus.errors;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,56 +1,9 @@
|
||||
import ModerationActions from './containers/ModerationActions';
|
||||
import translations from './translations.yml';
|
||||
import update from 'immutability-helper';
|
||||
|
||||
export default {
|
||||
slots: {
|
||||
commentInfoBar: [ModerationActions],
|
||||
},
|
||||
translations,
|
||||
mutations: {
|
||||
SetCommentStatus: ({variables: {status, commentId}}) => ({
|
||||
updateQueries: {
|
||||
CoralEmbedStream_Embed: (prev) => {
|
||||
|
||||
if (status !== 'REJECTED' && status !== "ACCEPTED") {
|
||||
return prev;
|
||||
}
|
||||
|
||||
// Permalink view will retrieve only one comment.
|
||||
if (prev.asset.comment) {
|
||||
const updated = update(prev, {
|
||||
asset: {
|
||||
comment: {
|
||||
status: {
|
||||
$set: status
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return updated;
|
||||
}
|
||||
|
||||
// Stream View
|
||||
const updated = update(prev, {
|
||||
asset: {
|
||||
comments: {
|
||||
nodes: {
|
||||
$apply: (nodes) => nodes.map((node) => {
|
||||
if (node.id === commentId) {
|
||||
node.status = status;
|
||||
}
|
||||
|
||||
return node;
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return updated;
|
||||
}
|
||||
}
|
||||
}),
|
||||
},
|
||||
translations
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user