Skip to content

Commit

Permalink
Merge d21f021 into ade621b
Browse files Browse the repository at this point in the history
  • Loading branch information
MrOrz committed Jan 24, 2023
2 parents ade621b + d21f021 commit a5b3aec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 7 additions & 2 deletions components/ReplyRequestReason/ReplyRequestReason.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ActionMenu, {
ReportAbuseMenuItem,
useCanReportAbuse,
} from 'components/ActionMenu';
import useCurrentUser from 'lib/useCurrentUser';

const useStyles = makeStyles(theme => ({
root: {
Expand Down Expand Up @@ -62,6 +63,7 @@ const ReplyRequestInfo = gql`
negativeFeedbackCount
user {
id
name
...AvatarData
}
Expand Down Expand Up @@ -92,6 +94,7 @@ function ReplyRequestReason({ replyRequest, articleId }) {
user,
} = replyRequest;

const currentUser = useCurrentUser();
const canReportAbuse = useCanReportAbuse(user.id);
const [voteReason, { loading }] = useMutation(UPDATE_VOTE);
const handleVote = vote => {
Expand All @@ -102,6 +105,8 @@ function ReplyRequestReason({ replyRequest, articleId }) {

if (!replyRequestReason) return null;

const isOwnReplyRequest = user && currentUser && user.id === currentUser.id;

return (
<div className={classes.root}>
<Box color="primary.main" pr={2}>
Expand All @@ -118,7 +123,7 @@ function ReplyRequestReason({ replyRequest, articleId }) {
className={classes.vote}
type="button"
onClick={() => handleVote(UPVOTE)}
disabled={loading}
disabled={loading || isOwnReplyRequest}
>
<ThumbUpIcon className={classes.thumbIcon} />
{positiveFeedbackCount}
Expand All @@ -130,7 +135,7 @@ function ReplyRequestReason({ replyRequest, articleId }) {
className={classes.vote}
type="button"
onClick={() => handleVote(DOWNVOTE)}
disabled={loading}
disabled={loading || isOwnReplyRequest}
>
<ThumbDownIcon className={classes.thumbIcon} />
{negativeFeedbackCount}
Expand Down
8 changes: 7 additions & 1 deletion pages/article/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ const LOAD_ARTICLE_FOR_USER = gql`
id # Required, https://github.com/apollographql/apollo-client/issues/2510
originalAttachmentUrl: attachmentUrl(variant: ORIGINAL)
replyRequests(statuses: $replyRequestStatuses) {
positiveFeedbackCount
negativeFeedbackCount
...ReplyRequestInfoForUser
}
articleReplies(statuses: $articleReplyStatuses) {
Expand Down Expand Up @@ -345,7 +347,11 @@ function ArticlePage() {
);

const replyRequestsWithComments = (article.replyRequests || []).filter(
({ reason }) => reason
({ reason, positiveFeedbackCount, negativeFeedbackCount }) =>
reason &&
reason.trim().length > 0 &&
// For users not logged in yet, only show reply requests with positive feedbacks
(currentUser ? true : positiveFeedbackCount - negativeFeedbackCount > 0)
);

return (
Expand Down

0 comments on commit a5b3aec

Please sign in to comment.