working tweet deletion

This commit is contained in:
erik-sn committed 2020-10-24 11:05:57 -04:00
1 parent 73272a6a43
commit c0dbf1a765
11 files changed
+200 -14

No files matched your search

@@ -0,0 +1,85 @@
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";
/**
* 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, 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;
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 >}
<MenuItem onClick={handleClose}>{t('APPS_TWITTER_REPORT')}</MenuItem >
</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,7 @@ export const Tweet = (tweet) => {
profile_name,
seconds_since_tweet,
isLiked,
isMine,
} = tweet;
const classes = useStyles();
const { t } = useTranslation();
@@ -81,7 +87,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 +119,11 @@ export const Tweet = (tweet) => {
<ReplyButton profile_name={profile_name} />
<LikeButton tweetId={id} isLiked={isLiked} />
<QuoteButton message={message} />
<Button>
<MoreIcon />
</Button>
<ShowMore isMine={isMine} id={id} />
</div>
</div>
</ListItem>
);
};
export default Tweet;
export default memo(Tweet);
+2
View File
@@ -20,6 +20,8 @@
"APPS_TWITTER_SUBMIT_IMAGE": "Add Media",
"APPS_TWITTER_CLOSE_IMAGE": "Close",
"APPS_TWITTER_CLOSE": "Close",
"APPS_TWITTER_DELETE": "Delete",
"APPS_TWITTER_REPORT": "Report",
"APPS_TWITTER_JUST_NOW": "Just now",
"APPS_TWITTER_SEARCH_TWEETS": "Search for tweets",
"APPS_TWITTER_SEARCH_TWEETS_PLACEHOLDER": "Search by profile name or message",
+1
View File
@@ -3,6 +3,7 @@ interface TwitterConfig {
generateProfileNameFromUsers: boolean;
characterLimit: number;
allowEdtiableProfileName: boolean;
allowDeleteTweets: boolean;
enableAvatars: boolean;
enableEmojis: boolean;
enableImages: boolean;