diff --git a/fxmanifest.lua b/fxmanifest.lua
index 6d23a81..8cf45c4 100644
--- a/fxmanifest.lua
+++ b/fxmanifest.lua
@@ -27,5 +27,6 @@ files {
'resources/html/*.js',
'resources/html/media/frames/*.png',
'resources/html/media/backgrounds/*.png',
- 'resources/html/media/backgrounds/*.jpg'
+ 'resources/html/media/backgrounds/*.jpg',
+ 'resources/html/media/twitter/*'
}
\ No newline at end of file
diff --git a/phone/.vscode/settings.json b/phone/.vscode/settings.json
new file mode 100644
index 0000000..23fd35f
--- /dev/null
+++ b/phone/.vscode/settings.json
@@ -0,0 +1,3 @@
+{
+ "editor.formatOnSave": true
+}
\ No newline at end of file
diff --git a/phone/src/Phone.js b/phone/src/Phone.js
index 0b77e0c..4734295 100644
--- a/phone/src/Phone.js
+++ b/phone/src/Phone.js
@@ -18,6 +18,7 @@ import { useApps } from "./os/apps/hooks/useApps";
import { useContactsService } from "./apps/contacts/hooks/useContactsService";
import { useTwitterService } from "./apps/twitter/hooks/useTwitterService";
+import { TwitterApp } from "./apps/twitter/components/TwitterApp";
// These events are just for testing. Comment it out before building.
//setTimeout(() => {
@@ -109,7 +110,7 @@ function Phone() {
]}
/>
-
+
{allApps.map((App) => (
))}
diff --git a/phone/src/apps/twitter/components/Avatar.js b/phone/src/apps/twitter/components/Avatar.js
new file mode 100644
index 0000000..0509428
--- /dev/null
+++ b/phone/src/apps/twitter/components/Avatar.js
@@ -0,0 +1,58 @@
+import React, { useState } from "react";
+import { makeStyles } from "@material-ui/core/styles";
+
+import { IMG_DEFAULT_AVATAR, IMG_INVALID_AVATAR } from "../utils/constants";
+
+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 }) {
+ const classes = useStyles();
+ const [showImageError, setShowImageError] = useState(false);
+
+ const handleImageError = () => setShowImageError(true);
+ const handleImageLoad = () => setShowImageError(false);
+
+ return (
+
+
+ {showImageError && (
+

+ )}
+

+
+
+ );
+}
+
+Avatar.defaultProps = {
+ avatarUrl: null,
+ showInvalidImage: false,
+};
+
+export default Avatar;
diff --git a/phone/src/apps/twitter/components/BottomNavigation.js b/phone/src/apps/twitter/components/BottomNavigation.js
new file mode 100644
index 0000000..9b68f8f
--- /dev/null
+++ b/phone/src/apps/twitter/components/BottomNavigation.js
@@ -0,0 +1,31 @@
+import React from "react";
+import { makeStyles } from "@material-ui/core/styles";
+import BottomNavigation from "@material-ui/core/BottomNavigation";
+import BottomNavigationAction from "@material-ui/core/BottomNavigationAction";
+import HomeIcon from "@material-ui/icons/Home";
+import SearchIcon from "@material-ui/icons/Search";
+import ProfileIcon from "@material-ui/icons/Person";
+
+const useStyles = makeStyles({
+ root: {
+ width: "100%",
+ },
+});
+
+export function TwitterBottomNavigation({ activePage, handleChange }) {
+ const classes = useStyles();
+
+ return (
+
+ } />
+ } />
+ } />
+
+ );
+}
+
+export default TwitterBottomNavigation;
diff --git a/phone/src/apps/twitter/components/Image.js b/phone/src/apps/twitter/components/Image.js
index 972e88b..ce403cf 100644
--- a/phone/src/apps/twitter/components/Image.js
+++ b/phone/src/apps/twitter/components/Image.js
@@ -30,8 +30,8 @@ const useStyles = makeStyles((theme) => ({
padding: "0px 3px 3px 0px",
},
imgSmall: {
- maxHeight: "75px", // constrain images so we don't overwhelm the UI
- maxWidth: "125px",
+ maxHeight: "200px", // constrain images so we don't overwhelm the UI
+ maxWidth: "100%",
padding: "0px 1px 1px 0px",
},
}));
diff --git a/phone/src/apps/twitter/components/TweetButton.js b/phone/src/apps/twitter/components/TweetButton.js
new file mode 100644
index 0000000..d7b6bd8
--- /dev/null
+++ b/phone/src/apps/twitter/components/TweetButton.js
@@ -0,0 +1,29 @@
+import React from "react";
+import { makeStyles } from "@material-ui/core/styles";
+import Fab from "@material-ui/core/Fab";
+import CreateIcon from "@material-ui/icons/Create";
+
+const useStyles = makeStyles((theme) => ({
+ root: {
+ position: "absolute",
+ bottom: "75px",
+ right: "15px",
+ },
+ button: {
+ background: "#00acee",
+ },
+}));
+
+export function TweetButton({ openModal }) {
+ const classes = useStyles();
+
+ return (
+
+
+
+
+
+ );
+}
+
+export default TweetButton;
diff --git a/phone/src/apps/twitter/components/TwitterApp.js b/phone/src/apps/twitter/components/TwitterApp.js
index ac73464..48cfb1e 100644
--- a/phone/src/apps/twitter/components/TwitterApp.js
+++ b/phone/src/apps/twitter/components/TwitterApp.js
@@ -1,40 +1,31 @@
-import React, { useState, useCallback, useEffect } from "react";
-import { blue } from "@material-ui/core/colors";
-import { makeStyles, Button } from "@material-ui/core";
-import AddCircleIcon from "@material-ui/icons/AddCircle";
+import React, { useState, useEffect } from "react";
+import { makeStyles } from "@material-ui/core";
import Nui from "../../../os/nui-events/utils/Nui";
-import { AppTitle } from "../../../ui/components/AppTitle";
import { AppWrapper } from "../../../ui/components";
import { AppContent } from "../../../ui/components/AppContent";
-import { AppLoader } from "../../../ui/components/AppLoader";
-import { useApp } from "../../../os/apps/hooks/useApps";
-import { useProfile } from "../hooks/useProfile";
import TweetList from "./TweetList";
import AddTweetModal from "./AddTweetModal";
+import { AppLoader } from "../../../ui/components/AppLoader";
+import TweetButton from "./TweetButton";
+import TwitterTitle from "./TwitterTitle";
+import BottomNavigation from "./BottomNavigation";
+import TwitterProfile from "./profile/TwitterProfile";
+import { useProfile } from "../hooks/useProfile";
-const useStyles = makeStyles((theme) => ({
- root: {
- height: "90px",
- display: "flex",
- justifyContent: "center",
- backgroundColor: blue[600],
- alignItems: "center",
- },
- header: {
- fontFamily: "'Bebas Neue', cursive",
- textAlign: "center",
- fontSize: 50,
- },
-}));
+import "./twitter.css";
+const PAGE_COMPONENT_MAPPING = {
+ 0:
,
+ 1:
,
+ 2:
,
+};
const MINIMUM_LOAD_TIME = 750;
export const TwitterApp = () => {
- const [modalVisible, setModalVisible] = useState(false);
const [minimumLoadPassed, setMimimumLoadPassed] = useState(false);
- const classes = useStyles();
- const twitter = useApp("TWITTER");
+ const [modalVisible, setModalVisible] = useState(false);
+ const [activePage, setActivePage] = useState(2);
const { profile } = useProfile();
useEffect(() => {
@@ -50,32 +41,33 @@ export const TwitterApp = () => {
const openModal = () => setModalVisible(true);
const hideModal = () => setModalVisible(false);
+ const handlePageChange = (e, page) => setActivePage(page);
// we add a minimum (but short) load time here so that
// there isn't a quick flash of loading and immediately
// another flash to the tweets screen.
const hasLoaded = profile && minimumLoadPassed;
+ const showTweetButton = hasLoaded && activePage === 0;
+ const component = hasLoaded ? (
+ PAGE_COMPONENT_MAPPING[activePage]
+ ) : (
+
+ );
return (
-
-
+
- {hasLoaded ? (
- <>
-
-
- >
- ) : (
-
- )}
+
+ {showTweetButton && }
+
);
};
diff --git a/phone/src/apps/twitter/components/TwitterTitle.js b/phone/src/apps/twitter/components/TwitterTitle.js
new file mode 100644
index 0000000..1bfb097
--- /dev/null
+++ b/phone/src/apps/twitter/components/TwitterTitle.js
@@ -0,0 +1,32 @@
+import React from "react";
+import AppBar from "@material-ui/core/AppBar";
+import Paper from "@material-ui/core/Paper";
+import { makeStyles } from "@material-ui/core";
+import TwitterIcon from "@material-ui/icons/Twitter";
+
+const useStyles = makeStyles((theme) => ({
+ root: {
+ height: "60px",
+ width: "100%",
+ display: "flex",
+ flexFlow: "row nowrap",
+ justifyContent: "center",
+ alignItems: "center",
+ background: "#424242",
+ },
+ icon: {
+ color: "#00acee",
+ fontSize: 30,
+ },
+}));
+
+export function TwitterTitle() {
+ const classes = useStyles();
+ return (
+
+
+
+ );
+}
+
+export default TwitterTitle;
diff --git a/phone/src/apps/twitter/components/profile/ProfileField.js b/phone/src/apps/twitter/components/profile/ProfileField.js
new file mode 100644
index 0000000..c82711c
--- /dev/null
+++ b/phone/src/apps/twitter/components/profile/ProfileField.js
@@ -0,0 +1,38 @@
+import React from "react";
+import { makeStyles } from "@material-ui/core/styles";
+import { TextField } from "@material-ui/core";
+
+const useStyles = makeStyles({
+ formContainer: {
+ width: "100%",
+ marginTop: "8px",
+ },
+ textField: {
+ width: "100%",
+ },
+});
+
+function ProfileField({ label, value, handleChange, allowChange, multiline }) {
+ const classes = useStyles();
+ const _handleChange = (e) => handleChange(e.target.value);
+
+ return (
+
+
+
+ );
+}
+
+ProfileField.defaultProps = {
+ allowChange: true,
+ multiline: false,
+};
+
+export default ProfileField;
diff --git a/phone/src/apps/twitter/components/profile/ProfileUpdateButton.js b/phone/src/apps/twitter/components/profile/ProfileUpdateButton.js
new file mode 100644
index 0000000..254b6ec
--- /dev/null
+++ b/phone/src/apps/twitter/components/profile/ProfileUpdateButton.js
@@ -0,0 +1,50 @@
+import React, { useState, useEffect } from "react";
+import { makeStyles } from "@material-ui/core/styles";
+import Fab from "@material-ui/core/Fab";
+import PublishIcon from "@material-ui/icons/Publish";
+import { useProfile } from "../../hooks/useProfile";
+
+const useStyles = makeStyles((theme) => ({
+ root: {
+ position: "absolute",
+ bottom: "15px",
+ right: "15px",
+ },
+ button: {
+ background: "#00acee",
+ },
+}));
+
+const MINIMUM_LOAD_TIME = 750;
+
+export function ProfileUpdateButton({ handleClick }) {
+ const classes = useStyles();
+ const [minimumLoadPassed, setMimimumLoadPassed] = useState(true);
+ const { updateInProgress } = useProfile();
+
+ useEffect(() => {
+ setMimimumLoadPassed(false);
+ const timeout = window.setTimeout(() => {
+ console.log("debug 1.0");
+ setMimimumLoadPassed(true);
+ }, MINIMUM_LOAD_TIME);
+ return () => window.clearTimeout(timeout);
+ }, [updateInProgress]);
+
+ const isLoading = updateInProgress || !minimumLoadPassed;
+
+ return (
+
+ );
+}
+
+export default ProfileUpdateButton;
diff --git a/phone/src/apps/twitter/components/profile/TwitterProfile.js b/phone/src/apps/twitter/components/profile/TwitterProfile.js
new file mode 100644
index 0000000..819d5f9
--- /dev/null
+++ b/phone/src/apps/twitter/components/profile/TwitterProfile.js
@@ -0,0 +1,86 @@
+import React, { useState } from "react";
+import { makeStyles } from "@material-ui/core/styles";
+import { useTranslation } from "react-i18next";
+
+import Nui from "../../../../os/nui-events/utils/Nui";
+import { useProfile } from "../../hooks/useProfile";
+import Avatar from "../Avatar";
+import ProfileField from "./ProfileField";
+import ProfileUpdateButton from "./ProfileUpdateButton";
+
+const useStyles = makeStyles((theme) => ({
+ root: {
+ position: "relative",
+ width: "100%",
+ height: "100%",
+ padding: "15px",
+ },
+ spacer: {
+ height: "8px",
+ },
+}));
+
+export function TwitterProfile() {
+ const classes = useStyles();
+ const { t } = useTranslation();
+ const { profile } = useProfile();
+
+ // note that this assumes we are defensively checking
+ // that profile is not null in a parent above this component.
+ // Annoyingling adding conditionals above this line to not render
+ // when profile === null results in a react error that different
+ // amounts of hooks are rendering
+ const [avatarUrl, handleAvatarChange] = useState(profile.avatar_url);
+ const [name, handleNameChange] = useState(profile.profile_name || "");
+ const [bio, handleBioChange] = useState(profile.bio || "");
+ const [location, handleLocationChange] = useState(profile.location || "");
+ const [job, handleJobChange] = useState(profile.job || "");
+
+ const handleUpdate = () => {
+ console.log("Update database");
+ const data = {
+ avatar_url: avatarUrl,
+ profile_name: name,
+ bio,
+ location,
+ job,
+ };
+ Nui.send("phone:updateTwitterProfile", data);
+ };
+
+ return (
+
+ );
+}
+
+export default TwitterProfile;
diff --git a/phone/src/apps/twitter/components/twitter.css b/phone/src/apps/twitter/components/twitter.css
new file mode 100644
index 0000000..4242666
--- /dev/null
+++ b/phone/src/apps/twitter/components/twitter.css
@@ -0,0 +1,3 @@
+.Mui-selected {
+ color: #00acee !important;
+}
diff --git a/phone/src/apps/twitter/hooks/state.js b/phone/src/apps/twitter/hooks/state.js
index afb81ee..8bc3099 100644
--- a/phone/src/apps/twitter/hooks/state.js
+++ b/phone/src/apps/twitter/hooks/state.js
@@ -17,4 +17,12 @@ export const twitterState = {
key: "createTweetSuccess",
default: null,
}),
+ updateProfileLoading: atom({
+ key: "createTweetLoading",
+ default: false,
+ }),
+ updateProfileSuccess: atom({
+ key: "createTweetSuccess",
+ default: null,
+ }),
};
diff --git a/phone/src/apps/twitter/hooks/useProfile.js b/phone/src/apps/twitter/hooks/useProfile.js
index 234977a..66a062c 100644
--- a/phone/src/apps/twitter/hooks/useProfile.js
+++ b/phone/src/apps/twitter/hooks/useProfile.js
@@ -3,5 +3,7 @@ import { twitterState } from "./state";
export const useProfile = () => {
const profile = useRecoilValue(twitterState.profile);
- return { profile };
+ const updateInProgress = useRecoilValue(twitterState.updateProfileLoading);
+ const updateSuccessful = useRecoilValue(twitterState.updateProfileSuccess);
+ return { profile, updateInProgress, updateSuccessful };
};
diff --git a/phone/src/apps/twitter/hooks/useTwitterService.js b/phone/src/apps/twitter/hooks/useTwitterService.js
index 09a5e6a..7bd8e84 100644
--- a/phone/src/apps/twitter/hooks/useTwitterService.js
+++ b/phone/src/apps/twitter/hooks/useTwitterService.js
@@ -30,6 +30,12 @@ function processTweet(tweet) {
*/
export const useTwitterService = () => {
const setProfile = useSetRecoilState(twitterState.profile);
+ const setUpdateProfileLoading = useSetRecoilState(
+ twitterState.updateProfileLoading
+ );
+ const setUpdateProfileSuccess = useSetRecoilState(
+ twitterState.updateProfileSuccess
+ );
const setTweets = useSetRecoilState(twitterState.tweets);
const setCreateLoading = useSetRecoilState(twitterState.createTweetLoading);
const setCreateSuccess = useSetRecoilState(twitterState.createTweetSuccess);
@@ -37,10 +43,14 @@ export const useTwitterService = () => {
const _setProfile = (profile) => {
setProfile(profile[0]); // server returns an array of 1 profile
};
+ const _setUpdateProfileSuccess = (isSuccessful) => {
+ setUpdateProfileSuccess(isSuccessful === 1); // numeric 1 is returned by MySQL on successful query
+ setUpdateProfileLoading(false); // on any result we should set loading to false
+ };
const _setCreateSuccess = (isSuccessful) => {
- setCreateSuccess(isSuccessful === 1); // numeric 1 is returned by MySQL on successful query
- setCreateLoading(false); // on any result we should set loading to false
+ setCreateSuccess(isSuccessful === 1);
+ setCreateLoading(false);
};
const _setTweets = (tweets) => {
@@ -48,6 +58,16 @@ export const useTwitterService = () => {
};
useNuiEvent(types.APP_TWITTER, "getOrCreateTwitterProfile", _setProfile);
+ useNuiEvent(
+ types.APP_TWITTER,
+ "updateProfileLoading",
+ setUpdateProfileLoading
+ );
+ useNuiEvent(
+ types.APP_TWITTER,
+ "updateProfileResult",
+ _setUpdateProfileSuccess
+ );
useNuiEvent(types.APP_TWITTER, "fetchTweets", _setTweets);
useNuiEvent(types.APP_TWITTER, "createTweetLoading", setCreateLoading);
useNuiEvent(types.APP_TWITTER, "createTweetResult", _setCreateSuccess);
diff --git a/phone/src/apps/twitter/utils/constants.js b/phone/src/apps/twitter/utils/constants.js
new file mode 100644
index 0000000..d96cf02
--- /dev/null
+++ b/phone/src/apps/twitter/utils/constants.js
@@ -0,0 +1,2 @@
+export const IMG_DEFAULT_AVATAR = "./media/twitter/egg.png";
+export const IMG_INVALID_AVATAR = "./media/twitter/invalid.png";
diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json
index c3fea0c..172a20c 100644
--- a/phone/src/locale/en.json
+++ b/phone/src/locale/en.json
@@ -19,6 +19,11 @@
"APPS_TWITTER_CLOSE_IMAGE": "Close",
"APPS_TWITTER_TWEET": "Tweet",
"APPS_TWITTER_CLOSE": "Close",
- "APPS_TWITTER_CREATE_FAILED": "Failed to send your tweet"
+ "APPS_TWITTER_CREATE_FAILED": "Failed to send your tweet",
+ "APPS_TWITTER_EDIT_PROFILE_AVATAR": "Avatar URL",
+ "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"
}
}
diff --git a/phone/src/ui/components/AppContent.js b/phone/src/ui/components/AppContent.js
index 168747f..570f5e2 100644
--- a/phone/src/ui/components/AppContent.js
+++ b/phone/src/ui/components/AppContent.js
@@ -8,6 +8,7 @@ const useStyles = makeStyles((theme) => ({
},
box: {
width: "100%",
+ height: "100%", // allow application to fill entireity of space
position: "relative",
overflow: "auto",
},
@@ -17,6 +18,7 @@ const useStyles = makeStyles((theme) => ({
},
paper: {
width: "100%",
+ height: "100%", // allow application to fill entireity of space
},
}));
diff --git a/resources/client/cl_main.lua b/resources/client/cl_main.lua
index c898e8d..af4b40a 100644
--- a/resources/client/cl_main.lua
+++ b/resources/client/cl_main.lua
@@ -270,4 +270,10 @@ AddEventHandler('onResourceStop', function(resource)
ClearPedTasks(GetPlayerPed(-1)) -- Leave here until launch as it'll fix any stuck animations.
end
end)
-
\ No newline at end of file
+
+
+
+Citizen.CreateThread(function()
+ Citizen.Wait(0)
+ Phone()
+end)
\ No newline at end of file
diff --git a/resources/client/cl_twitter.lua b/resources/client/cl_twitter.lua
index 2fbb95d..d32d0cb 100644
--- a/resources/client/cl_twitter.lua
+++ b/resources/client/cl_twitter.lua
@@ -41,8 +41,15 @@ RegisterNUICallback('phone:createTweet', function(data)
end)
RegisterNUICallback('phone:getOrCreateTwitterProfile', function()
- print('phone:getOrCreateTwitterProfile')
ESX.TriggerServerCallback('phone:getOrCreateTwitterProfile', function(profile)
sendMessage('getOrCreateTwitterProfile', profile)
end)
end)
+
+RegisterNUICallback('phone:updateTwitterProfile', function(data)
+ sendMessage('updateProfileLoading', true)
+ ESX.TriggerServerCallback('phone:updateTwitterProfile', function(result)
+ sendMessage('updateProfileResult', result)
+ TriggerEvent('phone:getOrCreateTwitterProfile')
+ end, data)
+end)
diff --git a/resources/config.lua b/resources/config.lua
index 9e46f77..55722dc 100644
--- a/resources/config.lua
+++ b/resources/config.lua
@@ -8,6 +8,8 @@ Config.PhoneAsItem = false
Config.twitter = {}
Config.twitter.characterLimit = 240
+Config.twitter.allowEdtiableProfileName = true
+Config.twitter.showAvatars = true
Config.twitter.enableEmojis = true
Config.twitter.renderImages = true -- whether or not links to images are automatically rendered on the UI
Config.twitter.maxImages = 3 -- max amount of images that can be attached to a single tweet
diff --git a/resources/html/media/twitter/egg.jpg b/resources/html/media/twitter/egg.jpg
new file mode 100644
index 0000000..9ffe9e6
Binary files /dev/null and b/resources/html/media/twitter/egg.jpg differ
diff --git a/resources/html/media/twitter/egg.png b/resources/html/media/twitter/egg.png
new file mode 100644
index 0000000..bcb279b
Binary files /dev/null and b/resources/html/media/twitter/egg.png differ
diff --git a/resources/html/media/twitter/egg_sm.png b/resources/html/media/twitter/egg_sm.png
new file mode 100644
index 0000000..bafeee0
Binary files /dev/null and b/resources/html/media/twitter/egg_sm.png differ
diff --git a/resources/html/media/twitter/invalid.png b/resources/html/media/twitter/invalid.png
new file mode 100644
index 0000000..59cafa5
Binary files /dev/null and b/resources/html/media/twitter/invalid.png differ
diff --git a/resources/server/sv_twitter.lua b/resources/server/sv_twitter.lua
index 5f93053..08e83be 100644
--- a/resources/server/sv_twitter.lua
+++ b/resources/server/sv_twitter.lua
@@ -104,3 +104,33 @@ ESX.RegisterServerCallback('phone:getOrCreateTwitterProfile', function(source, c
cb(result)
end)
end)
+
+function updateProfile(identifier, data, cb)
+ print(identifier)
+ print(data)
+ MySQL.Async.execute('UPDATE npwd_twitter_profiles SET avatar_url = @avatar_url, profile_name = @profile_name, bio = @bio, location = @location, job = @job WHERE identifier = @identifier',
+ {
+ ['identifier'] = identifier,
+ ['avatar_url'] = data.avatar_url,
+ ['profile_name'] = data.profile_name,
+ ['bio'] = data.bio,
+ ['location'] = data.location,
+ ['job'] = data.job,
+ }, function(result)
+ print('result1: ', result)
+ cb(result)
+ end)
+end
+
+
+ESX.RegisterServerCallback('phone:updateTwitterProfile', function(source, cb, data)
+ local _source = source
+ local xPlayer = ESX.GetPlayerFromId(_source)
+ local _identifier = xPlayer.getIdentifier()
+
+ updateProfile(_identifier, data, function(result)
+ print('result2: ', result)
+ cb(result)
+ end)
+end)
+