Merge branch 'master' into feature/sticky-notes

This commit is contained in:
Christopher Gjelten authored and GitHub committed 2020-10-30 14:33:07 +01:00
commit 18be1a7d0f
22 files changed
+466 -107

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;
@@ -0,0 +1,92 @@
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import {
Button,
Menu,
MenuItem
} from "@material-ui/core";
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";
/**
* Ok this is some bullshit. Due to either scaling issues or the NUI
* overlay being different than the display resolution just letting
* material-ui determine what the anchor positioning of the popover
* is not reliable and has some error that appears to scale vertically.
*
* This vertical offset raises the popover positioning implementing the
* transformOrigin prop that material-ui's Popover element provides.
*
* These coefficients are NOT based on any known offsets or calc()
* functions. They are empiricallly determined. The actual scaling issue
* does NOT appear to be linear, but over the comparatively low height
* of the phone compared to the window it produces results that are within
* acceptable tolerances from the player's perspective.
* @param top - the computed distance from the top of the window to the top
* of the anchor element
*/
function calculateVerticalOffset(top: number): number {
return top * 0.20 - 38;
}
export const ShowMore = ({ id, isReported, isMine }) => {
const [anchorEl, setAnchorEl] = useState<Element | null>(null);
const [verticalOffset, setVerticalOffset] = useState(0);
const { t } = useTranslation();
const { config } = usePhone();
if (!config) return null;
const handleClick = (event: React.MouseEvent) => {
const element = event.currentTarget
setAnchorEl(element);
const top = window.pageYOffset + element.getBoundingClientRect().top
setVerticalOffset(calculateVerticalOffset(top));
};
const handleClose = () => {
setAnchorEl(null);
setVerticalOffset(0);
};
const handleDeleteTweet = () => {
Nui.send("phone:deleteTweet", id);
handleClose();
}
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} >
<MoreIcon />
</Button>
<Menu
id="simple-menu"
anchorEl={anchorEl}
keepMounted
open={Boolean(anchorEl)}
onClose={handleClose}
transformOrigin={{
vertical: verticalOffset,
horizontal: 'left'
}}
>
{allowedToDelete && <MenuItem onClick={handleDeleteTweet}>{t('APPS_TWITTER_DELETE')}</MenuItem >}
{allowedToReport && <ReportButton handleClose={handleClose} isReported={isReported} tweetId={id}/>}
</Menu>
</>
);
};
export default ShowMore;
@@ -1,22 +1,27 @@
import React from "react";
import React, { useState, memo } from "react";
import { useTranslation } from "react-i18next";
import { makeStyles } from "@material-ui/core/styles";
import {
ListItemAvatar,
Avatar as MuiAvatar,
Button,
List,
ListItem,
ListItemText,
Paper,
Typography,
} from "@material-ui/core";
import MoreIcon from "@material-ui/icons/MoreVert";
import { ListItem } from "../../../../ui/components/ListItem";
import { secondsToHumanReadable } from "../../utils/time";
import LikeButton from "../buttons/LikeButton";
import ReplyButton from "../buttons/ReplyButton";
import ImageDisplay from "../images/ImageDisplay";
import Avatar from "../Avatar";
import ShowMore from './ShowMore';
import { QuoteButton } from "../buttons/QuoteButton";
import { usePhone } from "../../../../os/phone/hooks/usePhone";
import Nui from "../../../../os/nui-events/utils/Nui";
const useStyles = makeStyles(() => ({
root: {
@@ -58,7 +63,7 @@ const useStyles = makeStyles(() => ({
width: "100%",
marginLeft: "-20px", // easier to do this here than override the MUI styles
marginTop: "3px",
},
}
}));
export const Tweet = (tweet) => {
@@ -70,6 +75,8 @@ export const Tweet = (tweet) => {
profile_name,
seconds_since_tweet,
isLiked,
isMine,
isReported,
} = tweet;
const classes = useStyles();
const { t } = useTranslation();
@@ -81,7 +88,6 @@ export const Tweet = (tweet) => {
// this is a workaround to transfer string new lines and returns that
// are stored into the database into html for the UI to render
const formattedMessage = message.replace(/\n\r?/g, "<br />");
const profileName = profile_name ? `@${profile_name}` : "";
return (
@@ -114,13 +120,11 @@ export const Tweet = (tweet) => {
<ReplyButton profile_name={profile_name} />
<LikeButton tweetId={id} isLiked={isLiked} />
<QuoteButton message={message} />
<Button>
<MoreIcon />
</Button>
<ShowMore isMine={isMine} isReported={isReported} id={id} />
</div>
</div>
</ListItem>
);
};
export default Tweet;
export default memo(Tweet);
@@ -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,6 +1,6 @@
import { useRecoilValue } from "recoil";
import { Tweet } from "../interfaces";
import { Tweet } from "../../../common/interfaces/twitter";
import { twitterState } from "./state";
interface ITwitterNotification {
Whitespace-only changes.
+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 = () => {