mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-05 06:28:51 +00:00
integrating avatar and time into tweet list
This commit is contained in:
1 parent
3d5aadc46d
commit
619f75544c
8 files changed
+111
-29
No files matched your search
@@ -7,20 +7,13 @@ const useStyles = makeStyles({
|
|||||||
root: {
|
root: {
|
||||||
width: "100%",
|
width: "100%",
|
||||||
},
|
},
|
||||||
imgContainer: {},
|
|
||||||
button: {
|
|
||||||
background: "none",
|
|
||||||
border: "none",
|
|
||||||
},
|
|
||||||
img: {
|
img: {
|
||||||
height: "125px",
|
|
||||||
width: "125px",
|
|
||||||
borderRadius: "50%",
|
borderRadius: "50%",
|
||||||
objectFit: "cover",
|
objectFit: "cover",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
function Avatar({ avatarUrl, showInvalidImage }) {
|
function Avatar({ avatarUrl, showInvalidImage, height, width }) {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const [showImageError, setShowImageError] = useState(false);
|
const [showImageError, setShowImageError] = useState(false);
|
||||||
|
|
||||||
@@ -29,12 +22,12 @@ function Avatar({ avatarUrl, showInvalidImage }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classes.root}>
|
<div className={classes.root}>
|
||||||
<div className={classes.imgContainer}>
|
|
||||||
{showImageError && (
|
{showImageError && (
|
||||||
<img
|
<img
|
||||||
className={classes.img}
|
className={classes.img}
|
||||||
src={showInvalidImage ? IMG_INVALID_AVATAR : IMG_DEFAULT_AVATAR}
|
src={showInvalidImage ? IMG_INVALID_AVATAR : IMG_DEFAULT_AVATAR}
|
||||||
alt="Invalid avatar image"
|
alt="Invalid avatar image"
|
||||||
|
style={{ height, width }}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<img
|
<img
|
||||||
@@ -43,16 +36,17 @@ function Avatar({ avatarUrl, showInvalidImage }) {
|
|||||||
alt="Your profile avatar"
|
alt="Your profile avatar"
|
||||||
onError={handleImageError}
|
onError={handleImageError}
|
||||||
onLoad={handleImageLoad}
|
onLoad={handleImageLoad}
|
||||||
style={{ display: showImageError ? "none" : "block" }}
|
style={{ display: showImageError ? "none" : "block", height, width }}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Avatar.defaultProps = {
|
Avatar.defaultProps = {
|
||||||
avatarUrl: null,
|
avatarUrl: null,
|
||||||
showInvalidImage: false,
|
showInvalidImage: false,
|
||||||
|
height: "125px",
|
||||||
|
width: "125px",
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Avatar;
|
export default Avatar;
|
||||||
@@ -5,7 +5,7 @@ import Image from "./Image";
|
|||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
root: {
|
root: {
|
||||||
margin: "2px 15px",
|
margin: "2px 0px",
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -13,8 +13,10 @@ export const ImageDisplay = ({ visible, images, removeImage, small }) => {
|
|||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
if (!visible || !images || images.length === 0) return null;
|
if (!visible || !images || images.length === 0) return null;
|
||||||
|
|
||||||
|
const styles = { margin: small ? "2px 0px" : "2px 15px" };
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classes.root}>
|
<div className={classes.root} style={styles}>
|
||||||
{images.map((image) => (
|
{images.map((image) => (
|
||||||
<Image
|
<Image
|
||||||
key={image.id}
|
key={image.id}
|
||||||
|
|||||||
@@ -1,24 +1,34 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
import { makeStyles } from "@material-ui/core/styles";
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
import ListItemText from "@material-ui/core/ListItemText";
|
import ListItemText from "@material-ui/core/ListItemText";
|
||||||
import { Button } from "@material-ui/core";
|
import ListItemAvatar from "@material-ui/core/ListItemAvatar";
|
||||||
|
import MuiAvatar from "@material-ui/core/Avatar";
|
||||||
|
import Button from "@material-ui/core/Button";
|
||||||
|
import Typography from "@material-ui/core/Typography";
|
||||||
import FavoriteBorderIcon from "@material-ui/icons/FavoriteBorder";
|
import FavoriteBorderIcon from "@material-ui/icons/FavoriteBorder";
|
||||||
import ReplyIcon from "@material-ui/icons/Reply";
|
import ReplyIcon from "@material-ui/icons/Reply";
|
||||||
import QuoteIcon from "@material-ui/icons/FormatQuote";
|
import QuoteIcon from "@material-ui/icons/FormatQuote";
|
||||||
|
|
||||||
import { ListItem } from "../../../ui/components/ListItem";
|
import { ListItem } from "../../../ui/components/ListItem";
|
||||||
|
import { secondsToHumanReadable } from "../utils/time";
|
||||||
import ImageDisplay from "./ImageDisplay";
|
import ImageDisplay from "./ImageDisplay";
|
||||||
|
import Avatar from "./Avatar";
|
||||||
|
|
||||||
const useStyles = makeStyles(() => ({
|
const useStyles = makeStyles(() => ({
|
||||||
root: {
|
root: {
|
||||||
overflowX: "hidden",
|
overflowX: "hidden",
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexFlow: "column nowrap",
|
flexFlow: "row nowrap",
|
||||||
alignItems: "flex-start",
|
alignItems: "flex-start",
|
||||||
width: "100%",
|
width: "100%",
|
||||||
},
|
},
|
||||||
text: {
|
content: {
|
||||||
width: "100%",
|
display: "flex",
|
||||||
|
flexFlow: "column nowrap",
|
||||||
|
},
|
||||||
|
date: {
|
||||||
|
marginLeft: "10px",
|
||||||
},
|
},
|
||||||
buttonContainer: {
|
buttonContainer: {
|
||||||
display: "flex",
|
display: "flex",
|
||||||
@@ -28,13 +38,46 @@ const useStyles = makeStyles(() => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
export const Tweet = (tweet) => {
|
export const Tweet = (tweet) => {
|
||||||
const { message, images } = tweet;
|
const {
|
||||||
|
message,
|
||||||
|
images,
|
||||||
|
avatar_url,
|
||||||
|
profile_name,
|
||||||
|
seconds_since_tweet,
|
||||||
|
} = tweet;
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const Message = () => (
|
||||||
|
<>
|
||||||
|
<div>{message}</div>
|
||||||
|
<ImageDisplay visible images={images} small />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
const Primary = () => (
|
||||||
|
<>
|
||||||
|
<strong>{`@${profile_name}`}</strong>
|
||||||
|
<Typography
|
||||||
|
className={classes.date}
|
||||||
|
component="span"
|
||||||
|
variant="body2"
|
||||||
|
color="textSecondary"
|
||||||
|
>
|
||||||
|
{secondsToHumanReadable(t, seconds_since_tweet)}
|
||||||
|
</Typography>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ListItem className={classes.root} divider>
|
<ListItem className={classes.root} divider>
|
||||||
<ListItemText className={classes.text} primary={message} />
|
<ListItemAvatar>
|
||||||
<ImageDisplay visible images={images} small />
|
<MuiAvatar>
|
||||||
|
<Avatar avatarUrl={avatar_url} height="45px" width="45px" />
|
||||||
|
</MuiAvatar>
|
||||||
|
</ListItemAvatar>
|
||||||
|
<div className={classes.content}>
|
||||||
|
<ListItemText primary={<Primary />} secondary={<Message />} />
|
||||||
<div className={classes.buttonContainer}>
|
<div className={classes.buttonContainer}>
|
||||||
<Button>
|
<Button>
|
||||||
<FavoriteBorderIcon />
|
<FavoriteBorderIcon />
|
||||||
@@ -46,6 +89,7 @@ export const Tweet = (tweet) => {
|
|||||||
<QuoteIcon />
|
<QuoteIcon />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -28,9 +28,7 @@ export function TweetList() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<List>
|
<List>
|
||||||
{tweets
|
{tweets.map((tweet) => (
|
||||||
.filter((t) => t.visible)
|
|
||||||
.map((tweet) => (
|
|
||||||
<Tweet key={tweet.id} {...tweet} />
|
<Tweet key={tweet.id} {...tweet} />
|
||||||
))}
|
))}
|
||||||
</List>
|
</List>
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import { useProfile } from "../hooks/useProfile";
|
|||||||
|
|
||||||
import "./twitter.css";
|
import "./twitter.css";
|
||||||
|
|
||||||
|
// TODO move this to the router so the application back button works
|
||||||
const PAGE_COMPONENT_MAPPING = {
|
const PAGE_COMPONENT_MAPPING = {
|
||||||
0: <TweetList />,
|
0: <TweetList />,
|
||||||
1: <TweetList />,
|
1: <TweetList />,
|
||||||
@@ -25,7 +26,7 @@ const MINIMUM_LOAD_TIME = 750;
|
|||||||
export const TwitterApp = () => {
|
export const TwitterApp = () => {
|
||||||
const [minimumLoadPassed, setMimimumLoadPassed] = useState(false);
|
const [minimumLoadPassed, setMimimumLoadPassed] = useState(false);
|
||||||
const [modalVisible, setModalVisible] = useState(false);
|
const [modalVisible, setModalVisible] = useState(false);
|
||||||
const [activePage, setActivePage] = useState(2);
|
const [activePage, setActivePage] = useState(0);
|
||||||
const { profile } = useProfile();
|
const { profile } = useProfile();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
const ONE_MINUTE = 60;
|
||||||
|
const ONE_HOUR = 60 * ONE_MINUTE;
|
||||||
|
const ONE_DAY = 24 * ONE_HOUR;
|
||||||
|
|
||||||
|
const JUST_NOW = "APPS_TWITTER_TIME_JUST_NOW";
|
||||||
|
const MINUTES = "APPS_TWITTER_TIME_MINUTES";
|
||||||
|
const HOURS = "APPS_TWITTER_TIME_HOURS";
|
||||||
|
const DAYS = "APPS_TWITTER_TIME_DAYS";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert seconds to a human readable format i.e. "Just Now", "2m", "3d"
|
||||||
|
* @param {function} t - translation object passed from a component implementing the hook
|
||||||
|
* @param {number} seconds - seconds to translate to a string
|
||||||
|
*/
|
||||||
|
export function secondsToHumanReadable(t, seconds) {
|
||||||
|
if (seconds < 60) {
|
||||||
|
return t(JUST_NOW);
|
||||||
|
} else if (seconds < ONE_HOUR) {
|
||||||
|
return `${Math.floor(seconds / ONE_MINUTE)}${t(MINUTES)}`;
|
||||||
|
} else if (seconds < ONE_DAY) {
|
||||||
|
return `${Math.floor(seconds / ONE_HOUR)}${t(HOURS)}`;
|
||||||
|
} else {
|
||||||
|
return `${Math.floor(seconds / ONE_DAY)}${t(DAYS)}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,6 +24,10 @@
|
|||||||
"APPS_TWITTER_EDIT_PROFILE_NAME": "Profile name",
|
"APPS_TWITTER_EDIT_PROFILE_NAME": "Profile name",
|
||||||
"APPS_TWITTER_EDIT_PROFILE_BIO": "Bio",
|
"APPS_TWITTER_EDIT_PROFILE_BIO": "Bio",
|
||||||
"APPS_TWITTER_EDIT_PROFILE_LOCATION": "Location",
|
"APPS_TWITTER_EDIT_PROFILE_LOCATION": "Location",
|
||||||
"APPS_TWITTER_EDIT_PROFILE_JOB": "Job"
|
"APPS_TWITTER_EDIT_PROFILE_JOB": "Job",
|
||||||
|
"APPS_TWITTER_TIME_JUST_NOW": "Just now",
|
||||||
|
"APPS_TWITTER_TIME_MINUTES": "m",
|
||||||
|
"APPS_TWITTER_TIME_HOURS": "h",
|
||||||
|
"APPS_TWITTER_TIME_DAYS": "d"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,10 +11,24 @@ TriggerEvent('esx:getSharedObject', function(obj)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
ESX.RegisterServerCallback('phone:fetchTweets', function(source, cb)
|
ESX.RegisterServerCallback('phone:fetchTweets', function(source, cb)
|
||||||
local _source = source
|
MySQL.Async.fetchAll([[
|
||||||
local xPlayer = ESX.GetPlayerFromId(_source)
|
SELECT
|
||||||
local _identifier = xPlayer.getIdentifier()
|
npwd_twitter_tweets.id,
|
||||||
MySQL.Async.fetchAll('SELECT * FROM npwd_twitter_tweets WHERE visible = 1 ORDER BY updatedAt DESC', {}, function(tweets)
|
npwd_twitter_tweets.createdAt,
|
||||||
|
npwd_twitter_tweets.likes,
|
||||||
|
npwd_twitter_tweets.identifier,
|
||||||
|
npwd_twitter_tweets.visible,
|
||||||
|
npwd_twitter_tweets.images,
|
||||||
|
npwd_twitter_tweets.message,
|
||||||
|
npwd_twitter_profiles.profile_name,
|
||||||
|
npwd_twitter_profiles.avatar_url,
|
||||||
|
TIME_TO_SEC(TIMEDIFF( NOW(), npwd_twitter_tweets.createdAt)) AS seconds_since_tweet
|
||||||
|
FROM npwd_twitter_tweets
|
||||||
|
LEFT OUTER JOIN npwd_twitter_profiles ON npwd_twitter_tweets.identifier = npwd_twitter_profiles.identifier
|
||||||
|
WHERE visible = 1
|
||||||
|
ORDER BY npwd_twitter_tweets.createdAt DESC
|
||||||
|
LIMIT 75
|
||||||
|
]], {}, function(tweets)
|
||||||
cb(tweets)
|
cb(tweets)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in new issue
Block a user