handle all configuration cases

This commit is contained in:
Kire committed 2021-03-22 10:37:10 -04:00
1 parent 8000cc3d3f
commit 97f5c99cc0
12 files changed
+289 -157

No files matched your search

+106 -109
View File
@@ -21,6 +21,9 @@ import ProfilePrompt from './profile/ProfilePrompt';
import InjectDebugData from '../../../os/debug/InjectDebugData';
import { TwitterThemeProvider } from '../providers/TwitterThemeProvider';
import DefaultProfilePrompt from './profile/DefaultProfilePrompt';
import { useRecoilValue } from 'recoil';
import { twitterState } from '../hooks/state';
import { Profile } from '../../../../../typings/twitter';
const useStyles = makeStyles(() => ({
backgroundModal: {
@@ -42,16 +45,13 @@ export const TwitterApp = () => {
const { profile } = useProfile();
// before any other action can be taken by the user we force
// them have a profile name
let promptProfileName = profile && (!profile.profile_name || !profile.profile_name.trim());
promptProfileName = true;
// them have a profile name.
const promptProfileName = !profile || !profile.profile_name || !profile.profile_name.trim();
const openModal = () => setModalVisible(true);
const handlePageChange = (e, page) => setActivePage(page);
const showTweetButton = !promptProfileName && activePage === 0;
const defaultProfileNames = ['test_user', '123-456-7890'];
return (
<TwitterThemeProvider>
<AppWrapper id="twitter-app">
@@ -60,10 +60,7 @@ export const TwitterApp = () => {
<TwitterTitle />
<AppContent>
{promptProfileName ? (
<DefaultProfilePrompt
updateEvent="phone:updateTwitterProfile"
defaultProfileNames={defaultProfileNames}
/>
<ProfilePrompt />
) : (
<Switch>
<Route path="/twitter" exact component={TweetListContainer} />
@@ -81,104 +78,104 @@ export const TwitterApp = () => {
);
};
InjectDebugData([
{
app: 'TWITTER',
method: 'getOrCreateTwitterProfile',
data: {
profile_name: 'Angular_Dev',
bio: 'Angular FTW',
job: 'Googler @ Google',
location: '1600 Amphitheatre Parkway, CA, USA',
avatar_url: 'https://i.tasoagc.dev/i9Ig',
},
},
{
app: 'TWITTER',
method: 'fetchTweets',
data: [
{
id: 59,
message: 'XSS\n<script src="test.js">Test</script>\nBro',
avatar_url: 'http://i.tasoagc.dev/jtKL',
seconds_since_tweet: 500,
isMine: false,
isRetweetedByPlayer: true,
updateAt: '2021-02-08 14:37:46',
visible: 1,
likes: 50000,
profile_name: 'jQuery Main',
images: 'http://i.tasoagc.dev/0xdp',
},
{
id: 2,
message: 'GCPhone will never die',
avatar_url: 'http://i.tasoagc.dev/jtKL',
seconds_since_tweet: 500,
isMine: false,
updateAt: '2021-02-08 14:37:46',
visible: 1,
likes: 50000,
profile_name: 'GCPhone_v9999',
images: 'http://i.tasoagc.dev/0xdp',
},
{
id: 1,
message: 'I love angular',
avatar_url: 'https://i.tasoagc.dev/i9Ig',
seconds_since_tweet: 800,
isMine: true,
updateAt: '2021-02-08 14:37:46',
visible: 1,
likes: 50000,
profile_name: 'Angular_Dev',
images: 'http://i.tasoagc.dev/i9Ig',
},
{
id: 3,
message:
'Anyways uhm... I bought a whole bunch of shungite, rocks, ' +
'do you know what shungite is? Anybody know what shungite is. No, no ' +
'Suge Knight, I think hes locked up in prison.',
avatar_url: 'http://i.tasoagc.dev/0v64',
seconds_since_tweet: 800,
isMine: true,
updateAt: '2021-02-08 14:37:46',
visible: 1,
likes: 50000,
profile_name: 'The_Doc',
},
],
},
]);
// InjectDebugData([
// {
// app: 'TWITTER',
// method: 'getOrCreateTwitterProfile',
// data: {
// profile_name: 'Angular_Dev',
// bio: 'Angular FTW',
// job: 'Googler @ Google',
// location: '1600 Amphitheatre Parkway, CA, USA',
// avatar_url: 'https://i.tasoagc.dev/i9Ig',
// },
// },
// {
// app: 'TWITTER',
// method: 'fetchTweets',
// data: [
// {
// id: 59,
// message: 'XSS\n<script src="test.js">Test</script>\nBro',
// avatar_url: 'http://i.tasoagc.dev/jtKL',
// seconds_since_tweet: 500,
// isMine: false,
// isRetweetedByPlayer: true,
// updateAt: '2021-02-08 14:37:46',
// visible: 1,
// likes: 50000,
// profile_name: 'jQuery Main',
// images: 'http://i.tasoagc.dev/0xdp',
// },
// {
// id: 2,
// message: 'GCPhone will never die',
// avatar_url: 'http://i.tasoagc.dev/jtKL',
// seconds_since_tweet: 500,
// isMine: false,
// updateAt: '2021-02-08 14:37:46',
// visible: 1,
// likes: 50000,
// profile_name: 'GCPhone_v9999',
// images: 'http://i.tasoagc.dev/0xdp',
// },
// {
// id: 1,
// message: 'I love angular',
// avatar_url: 'https://i.tasoagc.dev/i9Ig',
// seconds_since_tweet: 800,
// isMine: true,
// updateAt: '2021-02-08 14:37:46',
// visible: 1,
// likes: 50000,
// profile_name: 'Angular_Dev',
// images: 'http://i.tasoagc.dev/i9Ig',
// },
// {
// id: 3,
// message:
// 'Anyways uhm... I bought a whole bunch of shungite, rocks, ' +
// 'do you know what shungite is? Anybody know what shungite is. No, no ' +
// 'Suge Knight, I think hes locked up in prison.',
// avatar_url: 'http://i.tasoagc.dev/0v64',
// seconds_since_tweet: 800,
// isMine: true,
// updateAt: '2021-02-08 14:37:46',
// visible: 1,
// likes: 50000,
// profile_name: 'The_Doc',
// },
// ],
// },
// ]);
InjectDebugData(
[
{
app: 'TWITTER',
method: 'createTweetBroadcast',
data: {
id: 111,
profile_id: 111,
profile_name: 'Kidz',
isMine: false,
isReported: false,
message: 'I have tweeted this because Im badass',
},
},
{
app: 'TWITTER',
method: 'createTweetBroadcast',
data: {
id: 111,
profile_id: 111,
profile_name: 'ItsChip',
isMine: false,
isReported: false,
message:
'I have tweeted this because Im even more badass... And I need this to be longer so I will continue to write',
},
},
],
3000,
);
// InjectDebugData(
// [
// {
// app: 'TWITTER',
// method: 'createTweetBroadcast',
// data: {
// id: 111,
// profile_id: 111,
// profile_name: 'Kidz',
// isMine: false,
// isReported: false,
// message: 'I have tweeted this because Im badass',
// },
// },
// {
// app: 'TWITTER',
// method: 'createTweetBroadcast',
// data: {
// id: 111,
// profile_id: 111,
// profile_name: 'ItsChip',
// isMine: false,
// isReported: false,
// message:
// 'I have tweeted this because Im even more badass... And I need this to be longer so I will continue to write',
// },
// },
// ],
// 3000,
// );
@@ -11,8 +11,10 @@ import { useProfile } from '../../hooks/useProfile';
import ProfileUpdateButton from '../buttons/ProfileUpdateButton';
interface IProps {
handleUpdate: () => void;
profileName: string;
setProfileName: (name: string) => void;
defaultProfileNames: string[];
updateEvent: string;
}
const useStyles = makeStyles((theme) => ({
@@ -28,25 +30,17 @@ const useStyles = makeStyles((theme) => ({
},
}));
export function DefaultProfilePrompt({ defaultProfileNames, updateEvent }: IProps): JSX.Element {
export function DefaultProfilePrompt({
profileName,
setProfileName,
handleUpdate,
defaultProfileNames,
}: IProps): JSX.Element {
const classes = useStyles();
const { t } = useTranslation();
const { profile } = useProfile();
const hasDefaults = defaultProfileNames.length > 0;
const defaultProfileName = hasDefaults ? defaultProfileNames[0] : '';
const [profileName, setProfileName] = useState(defaultProfileName);
const handleUpdate = () => {
const data = {
...profile,
profile_name: profileName,
};
Nui.send(updateEvent, data);
};
const handleChange = (event: React.ChangeEvent<any>): void => {
event.preventDefault();
setProfileName(event.target.value);
};
@@ -65,8 +59,10 @@ export function DefaultProfilePrompt({ defaultProfileNames, updateEvent }: IProp
}}
>
<option value="" />
{defaultProfileNames.map((profileName) => (
<option value={profileName}>{profileName}</option>
{defaultProfileNames.map((name) => (
<option key={name} value={name}>
{name}
</option>
))}
</Select>
</FormControl>
@@ -5,7 +5,12 @@ import { useTranslation } from 'react-i18next';
import Nui from '../../../../os/nui-events/utils/Nui';
import { useProfile } from '../../hooks/useProfile';
import ProfileField from './ProfileField';
import DefaultProfilePrompt from './DefaultProfilePrompt';
import ProfileUpdateButton from '../buttons/ProfileUpdateButton';
import { useRecoilValue } from 'recoil';
import { twitterState } from '../../hooks/state';
import { useSettings } from '../../../settings/hooks/useSettings';
import { usePhone } from '../../../../os/phone/hooks/usePhone';
const useStyles = makeStyles((theme) => ({
root: {
@@ -23,23 +28,43 @@ export function ProfilePrompt() {
const classes = useStyles();
const { t } = useTranslation();
const { profile } = useProfile();
const defaultProfileNames = useRecoilValue(twitterState.defaultProfileNames);
const [profileName, setProfileName] = useState(profile?.profile_name || '');
const { config } = usePhone();
const [name, handleNameChange] = useState(profile.profile_name || '');
const showDefaultProfileNames = !config.twitter.allowEdtiableProfileName && !profile;
const eventName = showDefaultProfileNames
? 'phone:createTwitterProfile'
: 'phone:updateTwitterProfile';
const handleUpdate = () => {
const data = {
Nui.send(eventName, {
...profile,
profile_name: name,
};
Nui.send('phone:updateTwitterProfile', data);
profile_name: profileName,
});
};
// case where profile doesn't exist, couldn't be created automatically
// and the player is not allowed to edit their own profile name
if (showDefaultProfileNames) {
return (
<DefaultProfilePrompt
profileName={profileName}
defaultProfileNames={defaultProfileNames}
setProfileName={setProfileName}
handleUpdate={handleUpdate}
/>
);
}
// case where profile doesn't exist, couldn't be created automatically
// but the player IS allowed to edit their own profile name
return (
<div className={classes.root}>
<ProfileField
label={t('APPS_TWITTER_EDIT_PROFILE_NAME')}
value={name}
handleChange={handleNameChange}
value={profileName}
handleChange={setProfileName}
allowChange
/>
<ProfileUpdateButton handleClick={handleUpdate} />
+4
View File
@@ -5,6 +5,10 @@ export const twitterState = {
key: 'profile',
default: null,
}),
defaultProfileNames: atom({
key: 'defaultProfileNames',
default: null,
}),
tweets: atom({
key: 'tweets',
default: null,
@@ -59,6 +59,7 @@ export const useTwitterService = () => {
const [currentTweets, setTweets] = useRecoilState(twitterState.tweets);
const setFilteredTweets = useSetRecoilState(twitterState.filteredTweets);
const setCreateLoading = useSetRecoilState(twitterState.createTweetLoading);
const setDefaultProfileNames = useSetRecoilState(twitterState.defaultProfileNames);
const _setTweets = (tweets) => {
setTweets(tweets.map(processTweet));
@@ -83,6 +84,8 @@ export const useTwitterService = () => {
};
useNuiEvent(APP_TWITTER, 'getOrCreateTwitterProfile', setProfile);
useNuiEvent(APP_TWITTER, 'getOrCreateTwitterProfileNull', setDefaultProfileNames);
useNuiEvent(APP_TWITTER, 'phone:createProfileResult', handleAddAlert);
useNuiEvent(APP_TWITTER, 'updateProfileLoading', setUpdateProfileLoading);
useNuiEvent(APP_TWITTER, 'updateProfileResult', handleAddAlert);
useNuiEvent(APP_TWITTER, 'fetchTweets', _setTweets);
+2
View File
@@ -81,6 +81,8 @@
"APPS_TWITTER_EDIT_PROFILE_BIO": "Bio",
"APPS_TWITTER_EDIT_PROFILE_LOCATION": "Location",
"APPS_TWITTER_EDIT_PROFILE_JOB": "Job",
"APPS_TWITTER_CREATE_PROFILE_SUCCESS": "Successfully created your profile",
"APPS_TWITTER_CREATE_PROFILE_FAILURE": "Failed to create your profile",
"APPS_TWITTER_EDIT_PROFILE_SUCCESS": "Successfully updated your profile",
"APPS_TWITTER_EDIT_PROFILE_FAILURE": "Failed to update your profile",
"APPS_TWITTER_RETWEET_EXISTS": "You have already retweeted this tweet!",