From 0789f69e2ff884a02a02423f153d2251bf66e4c9 Mon Sep 17 00:00:00 2001 From: erik-sn Date: Fri, 25 Sep 2020 03:07:28 -0400 Subject: [PATCH] text -> message --- .../apps/twitter/components/AddTweetModal.js | 38 ++++++++++--------- .../{TweetText.js => TweetMessage.js} | 6 +-- phone/src/apps/twitter/utils/images.js | 6 ++- 3 files changed, 28 insertions(+), 22 deletions(-) rename phone/src/apps/twitter/components/{TweetText.js => TweetMessage.js} (86%) diff --git a/phone/src/apps/twitter/components/AddTweetModal.js b/phone/src/apps/twitter/components/AddTweetModal.js index 696b8ad..a40204c 100644 --- a/phone/src/apps/twitter/components/AddTweetModal.js +++ b/phone/src/apps/twitter/components/AddTweetModal.js @@ -12,7 +12,7 @@ import "./emoji.css"; import EmojiSelect from "./EmojiSelect"; import ImageDisplay from "./ImageDisplay"; import ImagePrompt from "./ImagePrompt"; -import TweetText from "./TweetText"; +import TweetMessage from "./TweetMessage"; import ControlButtons from "./ControlButtons"; import IconButtons from "./IconButtons"; import AddTweetStatus from "./AddTweetStatus"; @@ -61,20 +61,14 @@ const useStyles = makeStyles((theme) => ({ }, })); -const IMAGES = [ - "https://assets.simpleviewinc.com/simpleview/image/upload/c_limit,h_1200,q_75,w_1200/v1/clients/boston/c07044da_9483_4fd5_8e37_5b75513dcc80_6b058b6f-7bdc-4f11-b217-4561c07901f3.jpg", - "https://www.hiusa.org/wp-content/uploads/2020/04/Aerial-View-Boston-Osman-Rana-Unsplash-1000x550-compressor-778x446.jpg", - "https://www.mccarter.com/wp-content/uploads/2019/10/Location-Boston.png", -]; - export const AddTweetModal = ({ visible, handleClose }) => { + const classes = useStyles(); const [showEmoji, setShowEmoji] = useState(false); const [showImagePrompt, setShowImagePrompt] = useState(false); const [image, setimage] = useState(""); - const [text, setText] = useState(""); - const [images, setImages] = useState(IMAGES); - const classes = useStyles(); + const [message, setMessage] = useState(""); + const [images, setImages] = useState([]); const reset = () => { setShowImagePrompt(null); @@ -82,7 +76,7 @@ export const AddTweetModal = ({ visible, handleClose }) => { setimage(""); setImages([]); - setText(""); + setMessage(""); }; const _handleClose = () => { @@ -109,17 +103,22 @@ export const AddTweetModal = ({ visible, handleClose }) => { const submitTweet = () => { const data = { - message: text, - images: images.join(IMAGE_DELIMITER), + message, + images: images && images.length > 0 ? images.join(IMAGE_DELIMITER) : "", realUser: "testUser", }; Nui.send("phone:createTweet", data); _handleClose(); }; - const handleTextChange = (e) => setText(e.target.value); + const handleMessageChange = (e) => setMessage(e.target.value); const addImage = () => { + // it's worth noting that we only perform this validation on + // the client of the user who is submitting the image. When + // other users see this image on their TweetList it will be + // from the database and should already have passed through + // this logic withValidImage(image, () => setImages([...images, image])); setShowImagePrompt(false); @@ -137,8 +136,11 @@ export const AddTweetModal = ({ visible, handleClose }) => { setImages(""); setShowEmoji(!showEmoji); }; - const handleEmojiClick = (emojiObject, e) => { - setText(text.concat(emojiObject.native)); + + // this is when a user clicks on an emoji icon itself (i.e. a smiley face) + // not the emoji icon on the UI + const handleSelectEmoji = (emojiObject, e) => { + setMessage(message.concat(emojiObject.native)); }; return ( @@ -147,14 +149,14 @@ export const AddTweetModal = ({ visible, handleClose }) => { - + - + 0} images={images} diff --git a/phone/src/apps/twitter/components/TweetText.js b/phone/src/apps/twitter/components/TweetMessage.js similarity index 86% rename from phone/src/apps/twitter/components/TweetText.js rename to phone/src/apps/twitter/components/TweetMessage.js index 3d39326..888f1a8 100644 --- a/phone/src/apps/twitter/components/TweetText.js +++ b/phone/src/apps/twitter/components/TweetMessage.js @@ -17,12 +17,12 @@ const useStyles = makeStyles((theme) => ({ }, })); -export const TweetText = ({ text, handleChange }) => { +export const TweetMessage = ({ message, handleChange }) => { const classes = useStyles(); const { t } = useTranslation(); return ( { ); }; -export default TweetText; +export default TweetMessage; diff --git a/phone/src/apps/twitter/utils/images.js b/phone/src/apps/twitter/utils/images.js index 8cd3ebc..a06b0b9 100644 --- a/phone/src/apps/twitter/utils/images.js +++ b/phone/src/apps/twitter/utils/images.js @@ -5,8 +5,12 @@ // here we'll use to join and split these strings export const IMAGE_DELIMITER = "||!||"; +/** + * Validate that the URL successfully loads in the browser + * @param {string} link - a URL we are trying to validate + * @param {func} onSuccess - callback if the link is valid + */ export function withValidImage(link, onSuccess) { - // only add the media if it's a valid URL const image = new Image(); image.onload = onSuccess; image.onerror = () => {