From 8000cc3d3f45619347b700a95ebe803ae8b21e4e Mon Sep 17 00:00:00 2001 From: Kire Date: Tue, 16 Mar 2021 18:40:36 -0400 Subject: [PATCH] added UI for choosing a default profile name --- .../components/modal/MessageModal.tsx | 2 +- .../apps/twitter/components/TwitterApp.tsx | 11 ++- .../profile/DefaultProfilePrompt.tsx | 78 +++++++++++++++++++ phone/src/locale/en.json | 1 + 4 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 phone/src/apps/twitter/components/profile/DefaultProfilePrompt.tsx diff --git a/phone/src/apps/messages/components/modal/MessageModal.tsx b/phone/src/apps/messages/components/modal/MessageModal.tsx index debf82b..1aef3bc 100644 --- a/phone/src/apps/messages/components/modal/MessageModal.tsx +++ b/phone/src/apps/messages/components/modal/MessageModal.tsx @@ -157,7 +157,7 @@ export const MessageModal = () => { ) : null} {!activeMessageGroup?.isGroupChat && - getDisplayByNumber(targetNumber) == targetNumber ? ( + getDisplayByNumber(targetNumber) === targetNumber ? ( diff --git a/phone/src/apps/twitter/components/TwitterApp.tsx b/phone/src/apps/twitter/components/TwitterApp.tsx index aea19f1..18fcbc0 100644 --- a/phone/src/apps/twitter/components/TwitterApp.tsx +++ b/phone/src/apps/twitter/components/TwitterApp.tsx @@ -20,6 +20,7 @@ import { useProfile } from '../hooks/useProfile'; import ProfilePrompt from './profile/ProfilePrompt'; import InjectDebugData from '../../../os/debug/InjectDebugData'; import { TwitterThemeProvider } from '../providers/TwitterThemeProvider'; +import DefaultProfilePrompt from './profile/DefaultProfilePrompt'; const useStyles = makeStyles(() => ({ backgroundModal: { @@ -42,12 +43,15 @@ export const TwitterApp = () => { // 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()); + let promptProfileName = profile && (!profile.profile_name || !profile.profile_name.trim()); + promptProfileName = true; const openModal = () => setModalVisible(true); const handlePageChange = (e, page) => setActivePage(page); const showTweetButton = !promptProfileName && activePage === 0; + const defaultProfileNames = ['test_user', '123-456-7890']; + return ( @@ -56,7 +60,10 @@ export const TwitterApp = () => { {promptProfileName ? ( - + ) : ( diff --git a/phone/src/apps/twitter/components/profile/DefaultProfilePrompt.tsx b/phone/src/apps/twitter/components/profile/DefaultProfilePrompt.tsx new file mode 100644 index 0000000..50db3fb --- /dev/null +++ b/phone/src/apps/twitter/components/profile/DefaultProfilePrompt.tsx @@ -0,0 +1,78 @@ +import React, { useState } from 'react'; +import { makeStyles } from '@material-ui/core/styles'; +import InputLabel from '@material-ui/core/InputLabel'; +import MenuItem from '@material-ui/core/MenuItem'; +import FormControl from '@material-ui/core/FormControl'; +import Select from '@material-ui/core/Select'; +import { useTranslation } from 'react-i18next'; + +import Nui from '../../../../os/nui-events/utils/Nui'; +import { useProfile } from '../../hooks/useProfile'; +import ProfileUpdateButton from '../buttons/ProfileUpdateButton'; + +interface IProps { + defaultProfileNames: string[]; + updateEvent: string; +} + +const useStyles = makeStyles((theme) => ({ + root: { + position: 'relative', + width: '100%', + height: '100%', + padding: '15px', + }, + formControl: { + // margin: theme.spacing(1), + width: '100%', + }, +})); + +export function DefaultProfilePrompt({ defaultProfileNames, updateEvent }: 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): void => { + setProfileName(event.target.value); + }; + + return ( +
+ + + {t('APPS_TWITTER_EDIT_DEFAULT_PROFILE_NAME')} + + + + +
+ ); +} + +export default DefaultProfilePrompt; diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json index 106fdb9..3722dff 100644 --- a/phone/src/locale/en.json +++ b/phone/src/locale/en.json @@ -77,6 +77,7 @@ "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_DEFAULT_PROFILE_NAME": "Choose Profile Name", "APPS_TWITTER_EDIT_PROFILE_BIO": "Bio", "APPS_TWITTER_EDIT_PROFILE_LOCATION": "Location", "APPS_TWITTER_EDIT_PROFILE_JOB": "Job",