Skip to content

Commit

Permalink
Merge pull request #529 from cofacts/report-article
Browse files Browse the repository at this point in the history
feat(article): add report button to article detail
  • Loading branch information
MrOrz authored Feb 15, 2023
2 parents c43b193 + 0862da6 commit 1244820
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/ActionMenu/ReportAbuseMenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function useCanReportAbuse(itemUserId) {
/**
* @param {object} props
* @param {string} props.userId - spammer's user ID
* @param {'replyRequest' | 'articleReplyFeedback' | 'reply'} props.itemType - reported spam item type
* @param {'replyRequest' | 'articleReplyFeedback' | 'reply' | 'article'} props.itemType - reported spam item type
* @param {string} props.itemId - reply ID for reply; article ID for replyRequest; article ID,reply ID (separated in comma) for article reply feedback.
*
* @returns {string} Pre-filled URL to the google form that reports spam.
Expand Down
42 changes: 41 additions & 1 deletion components/CreateReplyRequestForm/CreateReplyRequestForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ import {
Fab,
} from '@material-ui/core';
import { makeStyles } from '@material-ui/core/styles';
import MoreVertIcon from '@material-ui/icons/MoreVert';
import Avatar from 'components/AppLayout/Widgets/Avatar';
import { CardContent } from 'components/Card';
import { PenIcon } from 'components/icons';
import Hint from 'components/NewReplySection/ReplyForm/Hint';
import ReportAbuseMenuItem, {
useCanReportAbuse,
} from 'components/ActionMenu/ReportAbuseMenuItem';
import useCurrentUser from 'lib/useCurrentUser';
import cx from 'clsx';

Expand Down Expand Up @@ -135,14 +139,17 @@ const SubmitButton = ({
};

const CreateReplyRequestForm = React.memo(
({ articleId, requestedForReply, onNewReplyButtonClick }) => {
({ articleId, articleUserId, requestedForReply, onNewReplyButtonClick }) => {
const buttonRef = useRef(null);
const [disabled, setDisabled] = useState(false);
const [showForm, setShowForm] = useState(false);
const [showFloatButton, setShowFloatButton] = useState(false);
const [text, setText] = useState('');

const [shareAnchor, setShareAnchor] = useState(null);
const [moreAnchor, setMoreAnchor] = useState(null);

const canReportAbuse = useCanReportAbuse();

useEffect(() => {
// restore from localStorage if applicable.
Expand Down Expand Up @@ -252,6 +259,17 @@ const CreateReplyRequestForm = React.memo(
>
{t`Share`}
</Button>
{canReportAbuse && (
<Button
type="button"
className={cx({ [classes.isButtonActive]: !!moreAnchor })}
onClick={e => setMoreAnchor(e.currentTarget)}
disableElevation
style={{ flex: 0 }}
>
<MoreVertIcon />
</Button>
)}
</ButtonGroup>
<Menu
id="share-article-menu"
Expand Down Expand Up @@ -279,6 +297,28 @@ const CreateReplyRequestForm = React.memo(
{t`Facebook`}
</MenuItem>
</Menu>
<Menu
id="more-article-menu"
anchorEl={moreAnchor}
keepMounted
getContentAnchorEl={null}
open={!!moreAnchor}
onClose={() => setMoreAnchor(null)}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'center',
}}
transformOrigin={{
vertical: 'top',
horizontal: 'center',
}}
>
<ReportAbuseMenuItem
itemType="article"
itemId={articleId}
userId={articleUserId}
/>
</Menu>
</Box>
</CardContent>
<Button
Expand Down
4 changes: 4 additions & 0 deletions pages/article/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ const LOAD_ARTICLE = gql`
visit
}
}
user {
id
}
}
}
${Hyperlinks.fragments.HyperlinkData}
Expand Down Expand Up @@ -467,6 +470,7 @@ function ArticlePage() {
<CreateReplyRequestForm
requestedForReply={article.requestedForReply}
articleId={article.id}
articleUserId={article.user.id}
onNewReplyButtonClick={() => {
setShowForm(true);
// use setTimeout to make sure the form has shown
Expand Down

0 comments on commit 1244820

Please sign in to comment.