mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
text -> message
This commit is contained in:
1 parent
3d8bd2b334
commit
0789f69e2f
3 files changed
+28
-22
No files matched your search
@@ -12,7 +12,7 @@ import "./emoji.css";
|
|||||||
import EmojiSelect from "./EmojiSelect";
|
import EmojiSelect from "./EmojiSelect";
|
||||||
import ImageDisplay from "./ImageDisplay";
|
import ImageDisplay from "./ImageDisplay";
|
||||||
import ImagePrompt from "./ImagePrompt";
|
import ImagePrompt from "./ImagePrompt";
|
||||||
import TweetText from "./TweetText";
|
import TweetMessage from "./TweetMessage";
|
||||||
import ControlButtons from "./ControlButtons";
|
import ControlButtons from "./ControlButtons";
|
||||||
import IconButtons from "./IconButtons";
|
import IconButtons from "./IconButtons";
|
||||||
import AddTweetStatus from "./AddTweetStatus";
|
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 }) => {
|
export const AddTweetModal = ({ visible, handleClose }) => {
|
||||||
|
const classes = useStyles();
|
||||||
const [showEmoji, setShowEmoji] = useState(false);
|
const [showEmoji, setShowEmoji] = useState(false);
|
||||||
const [showImagePrompt, setShowImagePrompt] = useState(false);
|
const [showImagePrompt, setShowImagePrompt] = useState(false);
|
||||||
const [image, setimage] = useState("");
|
const [image, setimage] = useState("");
|
||||||
|
|
||||||
const [text, setText] = useState("");
|
const [message, setMessage] = useState("");
|
||||||
const [images, setImages] = useState(IMAGES);
|
const [images, setImages] = useState([]);
|
||||||
const classes = useStyles();
|
|
||||||
|
|
||||||
const reset = () => {
|
const reset = () => {
|
||||||
setShowImagePrompt(null);
|
setShowImagePrompt(null);
|
||||||
@@ -82,7 +76,7 @@ export const AddTweetModal = ({ visible, handleClose }) => {
|
|||||||
|
|
||||||
setimage("");
|
setimage("");
|
||||||
setImages([]);
|
setImages([]);
|
||||||
setText("");
|
setMessage("");
|
||||||
};
|
};
|
||||||
|
|
||||||
const _handleClose = () => {
|
const _handleClose = () => {
|
||||||
@@ -109,17 +103,22 @@ export const AddTweetModal = ({ visible, handleClose }) => {
|
|||||||
|
|
||||||
const submitTweet = () => {
|
const submitTweet = () => {
|
||||||
const data = {
|
const data = {
|
||||||
message: text,
|
message,
|
||||||
images: images.join(IMAGE_DELIMITER),
|
images: images && images.length > 0 ? images.join(IMAGE_DELIMITER) : "",
|
||||||
realUser: "testUser",
|
realUser: "testUser",
|
||||||
};
|
};
|
||||||
Nui.send("phone:createTweet", data);
|
Nui.send("phone:createTweet", data);
|
||||||
_handleClose();
|
_handleClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleTextChange = (e) => setText(e.target.value);
|
const handleMessageChange = (e) => setMessage(e.target.value);
|
||||||
|
|
||||||
const addImage = () => {
|
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]));
|
withValidImage(image, () => setImages([...images, image]));
|
||||||
|
|
||||||
setShowImagePrompt(false);
|
setShowImagePrompt(false);
|
||||||
@@ -137,8 +136,11 @@ export const AddTweetModal = ({ visible, handleClose }) => {
|
|||||||
setImages("");
|
setImages("");
|
||||||
setShowEmoji(!showEmoji);
|
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 (
|
return (
|
||||||
@@ -147,14 +149,14 @@ export const AddTweetModal = ({ visible, handleClose }) => {
|
|||||||
<Button className={classes.close} onClick={_handleClose}>
|
<Button className={classes.close} onClick={_handleClose}>
|
||||||
<CloseIcon color="action" />
|
<CloseIcon color="action" />
|
||||||
</Button>
|
</Button>
|
||||||
<TweetText text={text} handleChange={handleTextChange} />
|
<TweetMessage message={message} handleChange={handleMessageChange} />
|
||||||
<AddTweetStatus />
|
<AddTweetStatus />
|
||||||
<ImagePrompt
|
<ImagePrompt
|
||||||
visible={showImagePrompt}
|
visible={showImagePrompt}
|
||||||
value={image}
|
value={image}
|
||||||
handleChange={handleimageChange}
|
handleChange={handleimageChange}
|
||||||
/>
|
/>
|
||||||
<EmojiSelect visible={showEmoji} onEmojiClick={handleEmojiClick} />
|
<EmojiSelect visible={showEmoji} onEmojiClick={handleSelectEmoji} />
|
||||||
<ImageDisplay
|
<ImageDisplay
|
||||||
visible={!showEmoji && images.length > 0}
|
visible={!showEmoji && images.length > 0}
|
||||||
images={images}
|
images={images}
|
||||||
|
|||||||
+3
-3
@@ -17,12 +17,12 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const TweetText = ({ text, handleChange }) => {
|
export const TweetMessage = ({ message, handleChange }) => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
return (
|
return (
|
||||||
<TextField
|
<TextField
|
||||||
value={text}
|
value={message}
|
||||||
inputProps={{ className: classes.textFieldInput }}
|
inputProps={{ className: classes.textFieldInput }}
|
||||||
className={classes.textField}
|
className={classes.textField}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
@@ -32,4 +32,4 @@ export const TweetText = ({ text, handleChange }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default TweetText;
|
export default TweetMessage;
|
||||||
@@ -5,8 +5,12 @@
|
|||||||
// here we'll use to join and split these strings
|
// here we'll use to join and split these strings
|
||||||
export const IMAGE_DELIMITER = "||!||";
|
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) {
|
export function withValidImage(link, onSuccess) {
|
||||||
// only add the media if it's a valid URL
|
|
||||||
const image = new Image();
|
const image = new Image();
|
||||||
image.onload = onSuccess;
|
image.onload = onSuccess;
|
||||||
image.onerror = () => {
|
image.onerror = () => {
|
||||||
|
|||||||
Reference in new issue
Block a user