diff --git a/phone/package.json b/phone/package.json
index 0633562..0cb66ac 100644
--- a/phone/package.json
+++ b/phone/package.json
@@ -6,6 +6,7 @@
"@babel/polyfill": "^7.4.4",
"@material-ui/core": "^4.11.0",
"@material-ui/icons": "^4.9.1",
+ "@material-ui/lab": "^4.0.0-alpha.56",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
diff --git a/phone/src/apps/twitter/components/AddTweetModal.js b/phone/src/apps/twitter/components/AddTweetModal.js
index cd1623c..e1b7af2 100644
--- a/phone/src/apps/twitter/components/AddTweetModal.js
+++ b/phone/src/apps/twitter/components/AddTweetModal.js
@@ -15,7 +15,6 @@ import ImagePrompt from "./ImagePrompt";
import TweetMessage from "./TweetMessage";
import ControlButtons from "./ControlButtons";
import IconButtons from "./IconButtons";
-import AddTweetStatus from "./AddTweetStatus";
const useStyles = makeStyles((theme) => ({
root: {
@@ -169,7 +168,6 @@ export const AddTweetModal = () => {
-
{t("APPS_TWITTER_CREATE_FAILED")};
-}
-
-export default AddTweetStatus;
diff --git a/phone/src/apps/twitter/components/EmojiSelect.js b/phone/src/apps/twitter/components/EmojiSelect.js
index 9bdd44c..fe4fa6d 100644
--- a/phone/src/apps/twitter/components/EmojiSelect.js
+++ b/phone/src/apps/twitter/components/EmojiSelect.js
@@ -1,9 +1,6 @@
import React, { memo } from "react";
import { Picker } from "emoji-mart";
-import "./emoji.css";
-import "emoji-mart/css/emoji-mart.css";
-
export const EmojiSelect = ({ visible, onEmojiClick }) => {
if (!visible) return null;
diff --git a/phone/src/apps/twitter/components/TweetMessage.js b/phone/src/apps/twitter/components/TweetMessage.js
index 4d086e9..6db54d0 100644
--- a/phone/src/apps/twitter/components/TweetMessage.js
+++ b/phone/src/apps/twitter/components/TweetMessage.js
@@ -28,7 +28,7 @@ export const TweetMessage = ({ message, handleChange }) => {
className={classes.textField}
onChange={handleChange}
multiline
- placeholder={t("APPS_TWITTER_PLACEHOLDER")}
+ placeholder={t("APPS_TWITTER_TWEET_MESSAGE_PLACEHOLDER")}
inputRef={(input) => input && input.focus()}
/>
);
diff --git a/phone/src/apps/twitter/components/TwitterApp.js b/phone/src/apps/twitter/components/TwitterApp.js
index 24bb597..8b42384 100644
--- a/phone/src/apps/twitter/components/TwitterApp.js
+++ b/phone/src/apps/twitter/components/TwitterApp.js
@@ -7,14 +7,16 @@ import { AppContent } from "../../../ui/components/AppContent";
import TweetListContainer from "./TweetListContainer";
import AddTweetModal from "./AddTweetModal";
import { AppLoader } from "../../../ui/components/AppLoader";
+import { useModal } from "../hooks/useModal";
+import { useProfile } from "../hooks/useProfile";
import TweetButton from "./TweetButton";
import TwitterTitle from "./TwitterTitle";
import BottomNavigation from "./BottomNavigation";
import TwitterProfile from "./profile/TwitterProfile";
-import { useProfile } from "../hooks/useProfile";
+import AlertBar from "./alerts/AlertBar";
import "./twitter.css";
-import { useModal } from "../hooks/useModal";
+import "emoji-mart/css/emoji-mart.css";
const useStyles = makeStyles((theme) => ({
backgroundModal: {
@@ -56,7 +58,6 @@ 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
@@ -77,6 +78,7 @@ export const TwitterApp = () => {
{component}
{showTweetButton && }
+
;
+}
+
+export default Alert;
diff --git a/phone/src/apps/twitter/components/alerts/AlertBar.js b/phone/src/apps/twitter/components/alerts/AlertBar.js
new file mode 100644
index 0000000..b6b0022
--- /dev/null
+++ b/phone/src/apps/twitter/components/alerts/AlertBar.js
@@ -0,0 +1,72 @@
+import React, { useEffect, useState } from "react";
+import { useTranslation } from "react-i18next";
+import Snackbar from "@material-ui/core/Snackbar";
+import { makeStyles } from "@material-ui/core/styles";
+
+import { useProfile } from "../../hooks/useProfile";
+import { useTweetStatus } from "../../hooks/useTweetStatus";
+import Alert from "./Alert";
+
+const useStyles = makeStyles((theme) => ({
+ root: {
+ width: "100%",
+ bottom: "60px",
+ },
+}));
+
+const ALERT_TIMEOUT = 4000;
+
+export default function AlertBar() {
+ const classes = useStyles();
+ const { t } = useTranslation();
+ const { updateSuccessful, setUpdateSuccessful } = useProfile();
+ const { isSuccessful, setIsSuccessful } = useTweetStatus();
+ const [severity, setSeverity] = useState(null);
+ const [open, setOpen] = useState(null);
+ const [message, setMessage] = useState(null);
+
+ const handleClose = (event, reason) => {
+ setOpen(false);
+ setUpdateSuccessful(null);
+ setIsSuccessful(null);
+ };
+
+ useEffect(() => {
+ console.log(
+ "isSuccessful: ",
+ isSuccessful,
+ " updateSuccessful: ",
+ updateSuccessful
+ );
+ if (isSuccessful === true) {
+ setOpen(true);
+ setSeverity("success");
+ setMessage(t("APPS_TWITTER_CREATE_SUCCESS"));
+ } else if (isSuccessful === false) {
+ setOpen(true);
+ setSeverity("error");
+ setMessage(t("APPS_TWITTER_CREATE_FAILED"));
+ } else if (updateSuccessful === true) {
+ setOpen(true);
+ setSeverity("success");
+ setMessage(t("APPS_TWITTER_EDIT_PROFILE_SUCCESS"));
+ } else if (updateSuccessful === false) {
+ setOpen(true);
+ setSeverity("error");
+ setMessage(t("APPS_TWITTER_EDIT_PROFILE_FAILURE"));
+ }
+ }, [updateSuccessful, isSuccessful]);
+
+ return (
+
+
+ {message}
+
+
+ );
+}
diff --git a/phone/src/apps/twitter/components/emoji.css b/phone/src/apps/twitter/components/emoji.css
deleted file mode 100644
index 5e8187d..0000000
--- a/phone/src/apps/twitter/components/emoji.css
+++ /dev/null
@@ -1,8 +0,0 @@
-.emoji-mart {
- margin: 0px 15px 8px 15px !important;
- width: calc(100% - 30px) !important;
-}
-
-.emoji-mart-bar {
- display: none;
-}
diff --git a/phone/src/apps/twitter/components/profile/TwitterProfile.js b/phone/src/apps/twitter/components/profile/TwitterProfile.js
index 819d5f9..da9efaf 100644
--- a/phone/src/apps/twitter/components/profile/TwitterProfile.js
+++ b/phone/src/apps/twitter/components/profile/TwitterProfile.js
@@ -37,7 +37,6 @@ export function TwitterProfile() {
const [job, handleJobChange] = useState(profile.job || "");
const handleUpdate = () => {
- console.log("Update database");
const data = {
avatar_url: avatarUrl,
profile_name: name,
diff --git a/phone/src/apps/twitter/components/twitter.css b/phone/src/apps/twitter/components/twitter.css
index d837773..c543c1b 100644
--- a/phone/src/apps/twitter/components/twitter.css
+++ b/phone/src/apps/twitter/components/twitter.css
@@ -24,3 +24,19 @@ some of the Material UI primary theme settings */
#twitter-app .Mui-focused:after {
border-bottom-color: #00acee !important;
}
+
+/*
+override position of the snackbar so that it appears
+within the phone rather than on the game UI */
+#twitter-app .MuiSnackbar-root {
+ position: absolute;
+}
+
+.emoji-mart {
+ margin: 0px 15px 8px 15px !important;
+ width: calc(100% - 30px) !important;
+}
+
+.emoji-mart-bar {
+ display: none;
+}
diff --git a/phone/src/apps/twitter/hooks/state.js b/phone/src/apps/twitter/hooks/state.js
index a6d4798..627ff6d 100644
--- a/phone/src/apps/twitter/hooks/state.js
+++ b/phone/src/apps/twitter/hooks/state.js
@@ -30,7 +30,7 @@ export const twitterState = {
default: false,
}),
updateProfileSuccess: atom({
- key: "createTweetSuccess",
+ key: "updateProfileSuccess",
default: null,
}),
};
diff --git a/phone/src/apps/twitter/hooks/useProfile.js b/phone/src/apps/twitter/hooks/useProfile.js
index 66a062c..4916a54 100644
--- a/phone/src/apps/twitter/hooks/useProfile.js
+++ b/phone/src/apps/twitter/hooks/useProfile.js
@@ -1,9 +1,11 @@
-import { useRecoilValue } from "recoil";
+import { useRecoilValue, useRecoilState } from "recoil";
import { twitterState } from "./state";
export const useProfile = () => {
const profile = useRecoilValue(twitterState.profile);
const updateInProgress = useRecoilValue(twitterState.updateProfileLoading);
- const updateSuccessful = useRecoilValue(twitterState.updateProfileSuccess);
- return { profile, updateInProgress, updateSuccessful };
+ const [updateSuccessful, setUpdateSuccessful] = useRecoilState(
+ twitterState.updateProfileSuccess
+ );
+ return { profile, updateInProgress, updateSuccessful, setUpdateSuccessful };
};
diff --git a/phone/src/apps/twitter/hooks/useTweetStatus.js b/phone/src/apps/twitter/hooks/useTweetStatus.js
index 323928a..ac686a6 100644
--- a/phone/src/apps/twitter/hooks/useTweetStatus.js
+++ b/phone/src/apps/twitter/hooks/useTweetStatus.js
@@ -1,9 +1,11 @@
-import { useRecoilValue } from "recoil";
+import { useRecoilValue, useRecoilState } from "recoil";
import { twitterState } from "./state";
export const useTweetStatus = () => {
const isLoading = useRecoilValue(twitterState.createTweetLoading);
- const isSuccessful = useRecoilValue(twitterState.createTweetSuccess);
- return { isLoading, isSuccessful };
+ const [isSuccessful, setIsSuccessful] = useRecoilState(
+ twitterState.createTweetSuccess
+ );
+ return { isLoading, isSuccessful, setIsSuccessful };
};
diff --git a/phone/src/apps/twitter/hooks/useTwitterService.js b/phone/src/apps/twitter/hooks/useTwitterService.js
index 7bd8e84..abda7f6 100644
--- a/phone/src/apps/twitter/hooks/useTwitterService.js
+++ b/phone/src/apps/twitter/hooks/useTwitterService.js
@@ -44,12 +44,13 @@ export const useTwitterService = () => {
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
+ console.log("got: ", isSuccessful);
+ setUpdateProfileSuccess(isSuccessful);
setUpdateProfileLoading(false); // on any result we should set loading to false
};
const _setCreateSuccess = (isSuccessful) => {
- setCreateSuccess(isSuccessful === 1);
+ setCreateSuccess(isSuccessful);
setCreateLoading(false);
};
diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json
index fb2541c..90fb6d6 100644
--- a/phone/src/locale/en.json
+++ b/phone/src/locale/en.json
@@ -13,18 +13,21 @@
"APPS_SETTINGS_OPTIONS_WALLPAPER": "Wallpaper",
"APPS_SETTINGS_OPTIONS_FRAME": "Frame",
"APPS_TWITTER": "Twitter",
- "APPS_TWITTER_PLACEHOLDER": "What's happening?",
+ "APPS_TWITTER_TWEET": "Tweet",
+ "APPS_TWITTER_TWEET_MESSAGE_PLACEHOLDER": "What's happening?",
"APPS_TWITTER_IMAGE_PLACEHOLDER": "A link to your image or gif",
"APPS_TWITTER_SUBMIT_IMAGE": "Add Media",
"APPS_TWITTER_CLOSE_IMAGE": "Close",
- "APPS_TWITTER_TWEET": "Tweet",
"APPS_TWITTER_CLOSE": "Close",
+ "APPS_TWITTER_CREATE_SUCCESS": "Successfully sent 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",
+ "APPS_TWITTER_EDIT_PROFILE_SUCCESS": "Successfully updated your profile",
+ "APPS_TWITTER_EDIT_PROFILE_FAILURE": "Failed to update your profile",
"APPS_TWITTER_TIME_JUST_NOW": "Just now",
"APPS_TWITTER_TIME_MINUTES": "m",
"APPS_TWITTER_TIME_HOURS": "h",
diff --git a/phone/yarn.lock b/phone/yarn.lock
index 7cdfbc1..cfb397d 100644
--- a/phone/yarn.lock
+++ b/phone/yarn.lock
@@ -1470,6 +1470,17 @@
dependencies:
"@babel/runtime" "^7.4.4"
+"@material-ui/lab@^4.0.0-alpha.56":
+ version "4.0.0-alpha.56"
+ resolved "https://registry.yarnpkg.com/@material-ui/lab/-/lab-4.0.0-alpha.56.tgz#ff63080949b55b40625e056bbda05e130d216d34"
+ integrity sha512-xPlkK+z/6y/24ka4gVJgwPfoCF4RCh8dXb1BNE7MtF9bXEBLN/lBxNTK8VAa0qm3V2oinA6xtUIdcRh0aeRtVw==
+ dependencies:
+ "@babel/runtime" "^7.4.4"
+ "@material-ui/utils" "^4.10.2"
+ clsx "^1.0.4"
+ prop-types "^15.7.2"
+ react-is "^16.8.0"
+
"@material-ui/styles@^4.10.0":
version "4.10.0"
resolved "https://registry.yarnpkg.com/@material-ui/styles/-/styles-4.10.0.tgz#2406dc23aa358217aa8cc772e6237bd7f0544071"
diff --git a/resources/server/sv_twitter.lua b/resources/server/sv_twitter.lua
index 2c3a57c..982f8e3 100644
--- a/resources/server/sv_twitter.lua
+++ b/resources/server/sv_twitter.lua
@@ -1,11 +1,5 @@
ESX = nil
-function printO(o)
- for key, value in pairs(o) do
- print(key, value)
- end
-end
-
TriggerEvent('esx:getSharedObject', function(obj)
ESX = obj
end)
@@ -39,10 +33,10 @@ ESX.RegisterServerCallback('phone:createTweet', function(source, cb, data)
local xPlayer = ESX.GetPlayerFromId(_source)
local _identifier = xPlayer.getIdentifier()
- MySQL.Async.execute([[
+ MySQL.Async.transaction({[[
INSERT INTO npwd_twitter_tweets (`identifier`, `realUser`, `message`, `images`)
VALUES (@identifier, @realUser, @message, @images)
- ]],
+ ]]},
{
identifier = _identifier,
realUser = data.realUser,
@@ -132,11 +126,11 @@ ESX.RegisterServerCallback('phone:getOrCreateTwitterProfile', function(source, c
end)
end)
-function updateProfile(identifier, data, cb)
- MySQL.Async.execute([[
+function updateTwitterProfile(identifier, data, cb)
+ MySQL.Async.transaction({[[
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,
@@ -150,13 +144,12 @@ function updateProfile(identifier, data, cb)
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)
+ updateTwitterProfile(_identifier, data, function(result)
cb(result)
end)
end)