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 "emoji-mart/css/emoji-mart.css";
import { useProfile } from "../hooks/useProfile";
import ProfilePrompt from "./profile/ProfilePrompt";
const useStyles = makeStyles(() => ({
backgroundModal: {
@@ -59,9 +60,14 @@ export const TwitterApp = () => {
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 handlePageChange = (e, page) => setActivePage(page);
const showTweetButton = activePage === 0;
const showTweetButton = !promptProfileName && activePage === 0;
return (
<AppWrapper id="twitter-app">
@@ -69,18 +75,24 @@ export const TwitterApp = () => {
<div className={modalVisible ? classes.backgroundModal : null} />
<TwitterTitle />
<AppContent>
<Switch>
<Route path="/twitter" exact component={TweetListContainer} />
<Route path="/twitter/search" component={TwitterSearch} />
<Route path="/twitter/profile" component={TwitterProfile} />
</Switch>
{promptProfileName ? (
<ProfilePrompt />
) : (
<Switch>
<Route path="/twitter" exact component={TweetListContainer} />
<Route path="/twitter/search" component={TwitterSearch} />
<Route path="/twitter/profile" component={TwitterProfile} />
</Switch>
)}
</AppContent>
{showTweetButton && <TweetButton openModal={openModal} />}
<AlertBar />
<BottomNavigation
activePage={activePage}
handleChange={handlePageChange}
/>
{!promptProfileName && (
<BottomNavigation
activePage={activePage}
handleChange={handlePageChange}
/>
)}
</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
const formattedMessage = message.replace(/\n\r?/g, "<br />");
const profileName = profile_name ? `@${profile_name}` : "";
return (
<ListItem className={classes.root} divider>
{enableAvatars && (
@@ -91,7 +93,7 @@ export const Tweet = (tweet) => {
)}
<div className={classes.content}>
<div className={classes.primary}>
<div className={classes.profile}>{`@${profile_name}`}</div>
<div className={classes.profile}>{profileName}</div>
<Typography
className={classes.date}
component="div"