mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 06:28:51 +00:00
working callbacks and status updates on user interaction with the database
This commit is contained in:
1 parent
1157906def
commit
585eb43f4e
18 files changed
+139
-63
No files matched your search
@@ -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",
|
||||
|
||||
@@ -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 = () => {
|
||||
<CloseIcon color="action" />
|
||||
</Button>
|
||||
<TweetMessage message={message} handleChange={handleMessageChange} />
|
||||
<AddTweetStatus />
|
||||
<ImagePrompt
|
||||
visible={showImagePrompt}
|
||||
value={link}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
import React, { useEffect } from "react";
|
||||
import { useRecoilState } from "recoil";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { useTweetStatus } from "../hooks/useTweetStatus";
|
||||
|
||||
const HIDE_SUCCESS_TIMEOUT = 5000;
|
||||
|
||||
function AddTweetStatus() {
|
||||
const { isSuccessful } = useTweetStatus();
|
||||
const { t } = useTranslation();
|
||||
|
||||
// on the "true" case the tweet was created and the user should
|
||||
// see their tweet at the top of the list, so there's no need
|
||||
// to directly prompt them that it was successful.
|
||||
if (isSuccessful === null || isSuccessful === true) return null;
|
||||
|
||||
return <div>{t("APPS_TWITTER_CREATE_FAILED")}</div>;
|
||||
}
|
||||
|
||||
export default AddTweetStatus;
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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()}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -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 = () => {
|
||||
<TwitterTitle />
|
||||
<AppContent>{component}</AppContent>
|
||||
{showTweetButton && <TweetButton openModal={openModal} />}
|
||||
<AlertBar />
|
||||
<BottomNavigation
|
||||
activePage={activePage}
|
||||
handleChange={handlePageChange}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import React from "react";
|
||||
import MuiAlert from "@material-ui/lab/Alert";
|
||||
|
||||
export function Alert(props) {
|
||||
return <MuiAlert elevation={6} variant="filled" {...props} />;
|
||||
}
|
||||
|
||||
export default Alert;
|
||||
@@ -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 (
|
||||
<Snackbar
|
||||
autoHideDuration={ALERT_TIMEOUT}
|
||||
className={classes.root}
|
||||
open={open}
|
||||
onClose={handleClose}
|
||||
>
|
||||
<Alert onClose={handleClose} severity={severity}>
|
||||
{message}
|
||||
</Alert>
|
||||
</Snackbar>
|
||||
);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
.emoji-mart {
|
||||
margin: 0px 15px 8px 15px !important;
|
||||
width: calc(100% - 30px) !important;
|
||||
}
|
||||
|
||||
.emoji-mart-bar {
|
||||
display: none;
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -30,7 +30,7 @@ export const twitterState = {
|
||||
default: false,
|
||||
}),
|
||||
updateProfileSuccess: atom({
|
||||
key: "createTweetSuccess",
|
||||
key: "updateProfileSuccess",
|
||||
default: null,
|
||||
}),
|
||||
};
|
||||
@@ -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 };
|
||||
};
|
||||
@@ -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 };
|
||||
};
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user