Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(article): add report button to article detail #529

Merged
merged 1 commit into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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