updated profile_name to be required on app load

This commit is contained in:
erik-sn committed 2020-10-04 10:22:18 -04:00
1 parent 44622b8d8a
commit 04ada722f5
6 files changed
+89 -15

No files matched your search

+22 -10
View File
@@ -18,6 +18,7 @@ import TwitterSearch from "./TwitterSearch";
import "./twitter.css"; import "./twitter.css";
import "emoji-mart/css/emoji-mart.css"; import "emoji-mart/css/emoji-mart.css";
import { useProfile } from "../hooks/useProfile"; import { useProfile } from "../hooks/useProfile";
import ProfilePrompt from "./profile/ProfilePrompt";
const useStyles = makeStyles(() => ({ const useStyles = makeStyles(() => ({
backgroundModal: { backgroundModal: {
@@ -59,9 +60,14 @@ export const TwitterApp = () => {
return () => window.clearTimeout(timeout); return () => window.clearTimeout(timeout);
}, []); }, []);
// before any other action can be taken by the user we force
// them have a profile name
const promptProfileName =
profile && (!profile.profile_name || !profile.profile_name.trim());
const openModal = () => setModalVisible(true); const openModal = () => setModalVisible(true);
const handlePageChange = (e, page) => setActivePage(page); const handlePageChange = (e, page) => setActivePage(page);
const showTweetButton = activePage === 0; const showTweetButton = !promptProfileName && activePage === 0;
return ( return (
<AppWrapper id="twitter-app"> <AppWrapper id="twitter-app">
@@ -69,18 +75,24 @@ export const TwitterApp = () => {
<div className={modalVisible ? classes.backgroundModal : null} /> <div className={modalVisible ? classes.backgroundModal : null} />
<TwitterTitle /> <TwitterTitle />
<AppContent> <AppContent>
<Switch> {promptProfileName ? (
<Route path="/twitter" exact component={TweetListContainer} /> <ProfilePrompt />
<Route path="/twitter/search" component={TwitterSearch} /> ) : (
<Route path="/twitter/profile" component={TwitterProfile} /> <Switch>
</Switch> <Route path="/twitter" exact component={TweetListContainer} />
<Route path="/twitter/search" component={TwitterSearch} />
<Route path="/twitter/profile" component={TwitterProfile} />
</Switch>
)}
</AppContent> </AppContent>
{showTweetButton && <TweetButton openModal={openModal} />} {showTweetButton && <TweetButton openModal={openModal} />}
<AlertBar /> <AlertBar />
<BottomNavigation {!promptProfileName && (
activePage={activePage} <BottomNavigation
handleChange={handlePageChange} activePage={activePage}
/> handleChange={handlePageChange}
/>
)}
</AppWrapper> </AppWrapper>
); );
}; };
@@ -0,0 +1,49 @@
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 ProfileField from "./ProfileField";
import ProfileUpdateButton from "../buttons/ProfileUpdateButton";
const useStyles = makeStyles((theme) => ({
root: {
position: "relative",
width: "100%",
height: "100%",
padding: "15px",
},
spacer: {
height: "8px",
},
}));
export function ProfilePrompt() {
const classes = useStyles();
const { t } = useTranslation();
const { profile } = useProfile();
const [name, handleNameChange] = useState(profile.profile_name || "");
const handleUpdate = () => {
const data = {
...profile,
profile_name: name,
};
Nui.send("phone:updateTwitterProfile", data);
};
return (
<div className={classes.root}>
<ProfileField
label={t("APPS_TWITTER_EDIT_PROFILE_NAME")}
value={name}
handleChange={handleNameChange}
allowChange
/>
<ProfileUpdateButton handleClick={handleUpdate} />
</div>
);
}
export default ProfilePrompt;
@@ -80,6 +80,8 @@ export const Tweet = (tweet) => {
// are stored into the database into html for the UI to render // are stored into the database into html for the UI to render
const formattedMessage = message.replace(/\n\r?/g, "<br />"); const formattedMessage = message.replace(/\n\r?/g, "<br />");
const profileName = profile_name ? `@${profile_name}` : "";
return ( return (
<ListItem className={classes.root} divider> <ListItem className={classes.root} divider>
{enableAvatars && ( {enableAvatars && (
@@ -91,7 +93,7 @@ export const Tweet = (tweet) => {
)} )}
<div className={classes.content}> <div className={classes.content}>
<div className={classes.primary}> <div className={classes.primary}>
<div className={classes.profile}>{`@${profile_name}`}</div> <div className={classes.profile}>{profileName}</div>
<Typography <Typography
className={classes.date} className={classes.date}
component="div" component="div"
+13 -3
View File
@@ -21,7 +21,6 @@ end
RegisterNetEvent('phone:fetchTweets') RegisterNetEvent('phone:fetchTweets')
AddEventHandler('phone:fetchTweets', function() AddEventHandler('phone:fetchTweets', function()
print('RegisterNetEvent: phone:fetchTweets')
ESX.TriggerServerCallback('phone:fetchTweets', function(tweets) ESX.TriggerServerCallback('phone:fetchTweets', function(tweets)
sendTwitterMessage('fetchTweets', tweets) sendTwitterMessage('fetchTweets', tweets)
end) end)
@@ -29,7 +28,6 @@ end)
RegisterNetEvent('phone:fetchTweetsFiltered') RegisterNetEvent('phone:fetchTweetsFiltered')
AddEventHandler('phone:fetchTweetsFiltered', function(searchValue) AddEventHandler('phone:fetchTweetsFiltered', function(searchValue)
print('fetchTweetsFiltered', searchValue)
ESX.TriggerServerCallback('phone:fetchTweetsFiltered', function(tweets) ESX.TriggerServerCallback('phone:fetchTweetsFiltered', function(tweets)
sendTwitterMessage('fetchTweetsFiltered', tweets) sendTwitterMessage('fetchTweetsFiltered', tweets)
end, searchValue) end, searchValue)
@@ -54,10 +52,22 @@ RegisterNUICallback('phone:createTweet', function(data)
end, data) end, data)
end) end)
RegisterNUICallback('phone:getOrCreateTwitterProfile', function()
function getOrCreateTwitterProfile()
ESX.TriggerServerCallback('phone:getOrCreateTwitterProfile', function(profile) ESX.TriggerServerCallback('phone:getOrCreateTwitterProfile', function(profile)
sendTwitterMessage('getOrCreateTwitterProfile', profile) sendTwitterMessage('getOrCreateTwitterProfile', profile)
end) end)
end
-- called directly from the UI on app load
RegisterNUICallback('phone:getOrCreateTwitterProfile', function()
getOrCreateTwitterProfile()
end)
-- called during subsequent updates
RegisterNetEvent('phone:getOrCreateTwitterProfile')
AddEventHandler('phone:getOrCreateTwitterProfile', function()
getOrCreateTwitterProfile()
end) end)
RegisterNUICallback('phone:updateTwitterProfile', function(data) RegisterNUICallback('phone:updateTwitterProfile', function(data)
+1 -1
View File
@@ -23,7 +23,7 @@ Config.DestroyPhoneReCheck = 3 --MINUTES /// WIll wait the check for x MINUTES a
--Twitter --Twitter
------ ------
Config.twitter = {} Config.twitter = {}
Config.twitter.generateProfileNameFromUsers = true -- if the player's profile name should be generated from the users.first_name and users.last_name table Config.twitter.generateProfileNameFromUsers = false -- if the player's profile name should be generated from the users.first_name and users.last_name table
Config.twitter.characterLimit = 240 -- character limit on tweet messages Config.twitter.characterLimit = 240 -- character limit on tweet messages
Config.twitter.allowEdtiableProfileName = true -- whether or not players can edit their profile names Config.twitter.allowEdtiableProfileName = true -- whether or not players can edit their profile names
-- Config.twitter.enableLikes = true -- whether or not players can like other player's tweets and that they are visible -- Config.twitter.enableLikes = true -- whether or not players can like other player's tweets and that they are visible
+1
View File
@@ -77,6 +77,7 @@ function getProfile(identifier, cb)
MySQL.Async.fetchAll([[ MySQL.Async.fetchAll([[
SELECT * FROM npwd_twitter_profiles SELECT * FROM npwd_twitter_profiles
WHERE identifier = @identifier WHERE identifier = @identifier
LIMIT 1
]], ]],
{ identifier = identifier }, { identifier = identifier },
function(result) function(result)