working reporting system

This commit is contained in:
erik-sn committed 2020-10-29 19:13:07 -04:00
1 parent 8c1f823bcb
commit ea77114da6
19 files changed
+264 -43

No files matched your search

@@ -0,0 +1,49 @@
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import {
Button,
CircularProgress,
MenuItem
} from "@material-ui/core";
import DoneIcon from '@material-ui/icons/Done';
import Nui from "../../../../os/nui-events/utils/Nui";
const LOADING_TIME = 1250;
function ReportButton({ handleClose, tweetId, isReported }) {
const { t } = useTranslation();
const [loading, setLoading] = useState(false);
const handleClick = () => {
Nui.send("phone:reportTweet", tweetId);
setLoading(true);
window.setTimeout(() => {
setLoading(false);
handleClose();
}, LOADING_TIME);
};
if (isReported) {
return (
<MenuItem onClick={handleClose}>
<DoneIcon />
<span style={{ marginLeft: '5px' }}>{t('APPS_TWITTER_REPORTED')}</span>
</MenuItem >
);
}
if (loading) {
return (
<Button disabled>
<CircularProgress id="twitter-report-progress" size={22} />
</Button>
);
}
return (
<MenuItem onClick={handleClick}>{t('APPS_TWITTER_REPORT')}</MenuItem >
);
}
export default ReportButton;
@@ -8,6 +8,8 @@ import {
import MoreIcon from "@material-ui/icons/MoreVert";
import { usePhone } from "../../../../os/phone/hooks/usePhone";
import Nui from "../../../../os/nui-events/utils/Nui";
import ReportButton from '../buttons/ReportButton';
import { Tweet } from "./Tweet";
/**
@@ -31,7 +33,7 @@ function calculateVerticalOffset(top: number): number {
return top * 0.20 - 38;
}
export const ShowMore = ({ id, isMine }) => {
export const ShowMore = ({ id, isReported, isMine }) => {
const [anchorEl, setAnchorEl] = useState<Element | null>(null);
const [verticalOffset, setVerticalOffset] = useState(0);
const { t } = useTranslation();
@@ -58,10 +60,15 @@ export const ShowMore = ({ id, isMine }) => {
}
const allowedToDelete = config.twitter.allowDeleteTweets && isMine;
const allowedToReport = config.twitter.allowReportTweets && !isMine;
// if the user cannot perform any actions in show more then don't
// allow them to interact with it
let _handleClick = allowedToDelete || allowedToReport ? handleClick : () => null;
return (
<>
<Button aria-controls="simple-menu" aria-haspopup="true" onClick={handleClick} >
<Button aria-controls="simple-menu" aria-haspopup="true" onClick={_handleClick} >
<MoreIcon />
</Button>
<Menu
@@ -76,7 +83,7 @@ export const ShowMore = ({ id, isMine }) => {
}}
>
{allowedToDelete && <MenuItem onClick={handleDeleteTweet}>{t('APPS_TWITTER_DELETE')}</MenuItem >}
<MenuItem onClick={handleClose}>{t('APPS_TWITTER_REPORT')}</MenuItem >
{allowedToReport && <ReportButton handleClose={handleClose} isReported={isReported} tweetId={id}/>}
</Menu>
</>
);
@@ -76,6 +76,7 @@ export const Tweet = (tweet) => {
seconds_since_tweet,
isLiked,
isMine,
isReported,
} = tweet;
const classes = useStyles();
const { t } = useTranslation();
@@ -119,7 +120,7 @@ export const Tweet = (tweet) => {
<ReplyButton profile_name={profile_name} />
<LikeButton tweetId={id} isLiked={isLiked} />
<QuoteButton message={message} />
<ShowMore isMine={isMine} id={id} />
<ShowMore isMine={isMine} isReported={isReported} id={id} />
</div>
</div>
</ListItem>
@@ -30,6 +30,11 @@ some of the Material UI primary theme settings */
color: #00acee !important;
}
/* override circular progress on the report button */
#twitter-report-progress {
color: #00acee !important;
}
/*
override position of the snackbar so that it appears
within the phone rather than on the game UI */
+1 -1
View File
@@ -10,7 +10,7 @@ export const IMAGE_DELIMITER = "||!||";
* @param {string} link - a URL we are trying to validate
* @param {func} onSuccess - callback if the link is valid
*/
export function withValidImage(link, onSuccess) {
export function withValidImage(link: string, onSuccess: any): void {
const image = new Image();
image.onload = onSuccess;
image.onerror = () => {
+1
View File
@@ -3,6 +3,7 @@ interface TwitterConfig {
generateProfileNameFromUsers: boolean;
allowEdtiableProfileName: boolean;
allowDeleteTweets: boolean;
allowReportTweets: boolean;
characterLimit: number;
enableAvatars: boolean;
enableEmojis: boolean;
+2
View File
@@ -2,6 +2,8 @@ export interface Tweet {
id: number;
profile_name?: string;
profile_id: number;
isMine: boolean;
isReported: boolean;
avatar_url?: string;
message: string;
createdAt?: string;
+1
View File
@@ -20,6 +20,7 @@
"APPS_TWITTER_CLOSE": "Close",
"APPS_TWITTER_DELETE": "Delete",
"APPS_TWITTER_REPORT": "Report",
"APPS_TWITTER_REPORTED": " Reported",
"APPS_TWITTER_JUST_NOW": "Just now",
"APPS_TWITTER_SEARCH_TWEETS": "Search for tweets",
"APPS_TWITTER_SEARCH_TWEETS_PLACEHOLDER": "Search by profile name or message",