diff --git a/phone/src/apps/twitter/components/Avatar.js b/phone/src/apps/twitter/components/Avatar.js index 0509428..0417e2b 100644 --- a/phone/src/apps/twitter/components/Avatar.js +++ b/phone/src/apps/twitter/components/Avatar.js @@ -7,20 +7,13 @@ const useStyles = makeStyles({ root: { width: "100%", }, - imgContainer: {}, - button: { - background: "none", - border: "none", - }, img: { - height: "125px", - width: "125px", borderRadius: "50%", objectFit: "cover", }, }); -function Avatar({ avatarUrl, showInvalidImage }) { +function Avatar({ avatarUrl, showInvalidImage, height, width }) { const classes = useStyles(); const [showImageError, setShowImageError] = useState(false); @@ -29,23 +22,22 @@ function Avatar({ avatarUrl, showInvalidImage }) { return (
-
- {showImageError && ( - Invalid avatar image - )} + {showImageError && ( Your profile avatar -
+ )} + Your profile avatar
); } @@ -53,6 +45,8 @@ function Avatar({ avatarUrl, showInvalidImage }) { Avatar.defaultProps = { avatarUrl: null, showInvalidImage: false, + height: "125px", + width: "125px", }; export default Avatar; diff --git a/phone/src/apps/twitter/components/ImageDisplay.js b/phone/src/apps/twitter/components/ImageDisplay.js index 966548c..1e84715 100644 --- a/phone/src/apps/twitter/components/ImageDisplay.js +++ b/phone/src/apps/twitter/components/ImageDisplay.js @@ -5,7 +5,7 @@ import Image from "./Image"; const useStyles = makeStyles((theme) => ({ root: { - margin: "2px 15px", + margin: "2px 0px", }, })); @@ -13,8 +13,10 @@ export const ImageDisplay = ({ visible, images, removeImage, small }) => { const classes = useStyles(); if (!visible || !images || images.length === 0) return null; + const styles = { margin: small ? "2px 0px" : "2px 15px" }; + return ( -
+
{images.map((image) => ( ({ root: { overflowX: "hidden", display: "flex", - flexFlow: "column nowrap", + flexFlow: "row nowrap", alignItems: "flex-start", width: "100%", }, - text: { - width: "100%", + content: { + display: "flex", + flexFlow: "column nowrap", + }, + date: { + marginLeft: "10px", }, buttonContainer: { display: "flex", @@ -28,23 +38,57 @@ const useStyles = makeStyles(() => ({ })); export const Tweet = (tweet) => { - const { message, images } = tweet; + const { + message, + images, + avatar_url, + profile_name, + seconds_since_tweet, + } = tweet; const classes = useStyles(); + const { t } = useTranslation(); + + const Message = () => ( + <> +
{message}
+ + + ); + + const Primary = () => ( + <> + {`@${profile_name}`} + + {secondsToHumanReadable(t, seconds_since_tweet)} + + + ); return ( - - -
- - - + + + + + +
+ } secondary={} /> +
+ + + +
); diff --git a/phone/src/apps/twitter/components/TweetList.js b/phone/src/apps/twitter/components/TweetList.js index 6b4ad94..a8e21f7 100644 --- a/phone/src/apps/twitter/components/TweetList.js +++ b/phone/src/apps/twitter/components/TweetList.js @@ -28,11 +28,9 @@ export function TweetList() { return ( - {tweets - .filter((t) => t.visible) - .map((tweet) => ( - - ))} + {tweets.map((tweet) => ( + + ))} ); } diff --git a/phone/src/apps/twitter/components/TwitterApp.js b/phone/src/apps/twitter/components/TwitterApp.js index 44ab090..e81295a 100644 --- a/phone/src/apps/twitter/components/TwitterApp.js +++ b/phone/src/apps/twitter/components/TwitterApp.js @@ -15,6 +15,7 @@ import { useProfile } from "../hooks/useProfile"; import "./twitter.css"; +// TODO move this to the router so the application back button works const PAGE_COMPONENT_MAPPING = { 0: , 1: , @@ -25,7 +26,7 @@ const MINIMUM_LOAD_TIME = 750; export const TwitterApp = () => { const [minimumLoadPassed, setMimimumLoadPassed] = useState(false); const [modalVisible, setModalVisible] = useState(false); - const [activePage, setActivePage] = useState(2); + const [activePage, setActivePage] = useState(0); const { profile } = useProfile(); useEffect(() => { diff --git a/phone/src/apps/twitter/utils/time.js b/phone/src/apps/twitter/utils/time.js new file mode 100644 index 0000000..b01953f --- /dev/null +++ b/phone/src/apps/twitter/utils/time.js @@ -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)}`; + } +} diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json index 172a20c..fb2541c 100644 --- a/phone/src/locale/en.json +++ b/phone/src/locale/en.json @@ -24,6 +24,10 @@ "APPS_TWITTER_EDIT_PROFILE_NAME": "Profile name", "APPS_TWITTER_EDIT_PROFILE_BIO": "Bio", "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" } } diff --git a/resources/server/sv_twitter.lua b/resources/server/sv_twitter.lua index cefcd75..fc121ff 100644 --- a/resources/server/sv_twitter.lua +++ b/resources/server/sv_twitter.lua @@ -11,10 +11,24 @@ TriggerEvent('esx:getSharedObject', function(obj) end) ESX.RegisterServerCallback('phone:fetchTweets', function(source, cb) - local _source = source - local xPlayer = ESX.GetPlayerFromId(_source) - local _identifier = xPlayer.getIdentifier() - MySQL.Async.fetchAll('SELECT * FROM npwd_twitter_tweets WHERE visible = 1 ORDER BY updatedAt DESC', {}, function(tweets) + MySQL.Async.fetchAll([[ + SELECT + npwd_twitter_tweets.id, + 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) end) end)