diff --git a/phone/src/Phone.js b/phone/src/Phone.js index 0b77e0c..1af3a73 100644 --- a/phone/src/Phone.js +++ b/phone/src/Phone.js @@ -5,6 +5,7 @@ import { Route } from "react-router-dom"; import { useSettings } from "./apps/settings/hooks/useSettings"; import MessageIcon from "@material-ui/icons/Email"; +import Nui from "./os/nui-events/utils/Nui" import { HomeApp } from "./apps/home/components/Home"; import { ThemeProvider } from "@material-ui/core"; import { useInitKeyboard } from "./os/keyboard/hooks/useKeyboard"; diff --git a/phone/src/apps/twitter/components/AddTweetModal.js b/phone/src/apps/twitter/components/AddTweetModal.js index 673970e..c6d6ea4 100644 --- a/phone/src/apps/twitter/components/AddTweetModal.js +++ b/phone/src/apps/twitter/components/AddTweetModal.js @@ -15,6 +15,7 @@ import ImagePrompt from "./images/ImagePrompt"; import TweetMessage from "./tweet/TweetMessage"; import ControlButtons from "./buttons/ControlButtons"; import IconButtons from "./buttons/IconButtons"; +import { usePhone } from "../../../os/phone/hooks/usePhone"; const useStyles = makeStyles((theme) => ({ root: { @@ -54,6 +55,7 @@ const useStyles = makeStyles((theme) => ({ export const AddTweetModal = () => { const classes = useStyles(); const { message, setMessage, modalVisible, setModalVisible } = useModal(); + const { config } = usePhone(); const [showEmoji, setShowEmoji] = useState(false); const [showImagePrompt, setShowImagePrompt] = useState(false); @@ -89,7 +91,9 @@ export const AddTweetModal = () => { }, []); const submitTweet = () => { - if (message.trim().length === 0) return; + const cleanedMessage = message.trim(); + if (cleanedMessage.length === 0) return; + if (cleanedMessage.length > config.twitter.characterLimit) return; const data = { message, @@ -123,7 +127,7 @@ export const AddTweetModal = () => { withValidImage(cleanedLink, () => setImages([...images, image])); setShowImagePrompt(false); - setImages([]); + setLink('') }; const removeImage = (id) => setImages(images.filter((image) => id !== image.id)); @@ -146,6 +150,8 @@ export const AddTweetModal = () => { setMessage(message.concat(emojiObject.native)); }; + if (!config) return null; + return ( - )} + {enableEmojis && ( + )} ); }; diff --git a/phone/src/apps/twitter/components/profile/Profile.js b/phone/src/apps/twitter/components/profile/Profile.js index b8b6ecd..f14690c 100644 --- a/phone/src/apps/twitter/components/profile/Profile.js +++ b/phone/src/apps/twitter/components/profile/Profile.js @@ -7,6 +7,7 @@ import { useProfile } from "../../hooks/useProfile"; import Avatar from "../Avatar"; import ProfileField from "./ProfileField"; import ProfileUpdateButton from "../buttons/ProfileUpdateButton"; +import { usePhone } from "../../../../os/phone/hooks/usePhone"; const useStyles = makeStyles((theme) => ({ root: { @@ -24,6 +25,8 @@ export function Profile() { const classes = useStyles(); const { t } = useTranslation(); const { profile } = useProfile(); + const { config } = usePhone(); + // note that this assumes we are defensively checking // that profile is not null in a parent above this component. @@ -47,19 +50,26 @@ export function Profile() { Nui.send("phone:updateTwitterProfile", data); }; + // fetching the config is an asynchronous call so defend against it + if (!config) return null; + + const { enableAvatars, allowEdtiableProfileName } = config.twitter; + return (
- + {enableAvatars && }
({ root: { @@ -70,6 +71,12 @@ export const Tweet = (tweet) => { } = tweet; const classes = useStyles(); const { t } = useTranslation(); + const { config } = usePhone(); + + console.log(config); + + if (!config) return null; + const { enableAvatars, enableImages } = config.twitter; // this is a workaround to transfer string new lines and returns that // are stored into the database into html for the UI to render @@ -77,11 +84,13 @@ export const Tweet = (tweet) => { return ( - - - - - + {enableAvatars && ( + + + + + + )}
{`@${profile_name}`}
@@ -98,7 +107,7 @@ export const Tweet = (tweet) => { className={classes.message} dangerouslySetInnerHTML={{ __html: formattedMessage }} /> - + {enableImages && }