mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 06:28:51 +00:00
working media adding and removal
This commit is contained in:
1 parent
e5303436ff
commit
2fc78df59b
5 files changed
+107
-16
No files matched your search
+2
-1
@@ -20,7 +20,8 @@
|
||||
"react-router-dom": "^5.2.0",
|
||||
"react-scripts": "3.4.3",
|
||||
"recoil": "^0.0.10",
|
||||
"styled-components": "^5.1.1"
|
||||
"styled-components": "^5.1.1",
|
||||
"uuid": "^8.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.4.4",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import React, { useState, useCallback } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { makeStyles } from "@material-ui/core/styles";
|
||||
import { Button, Paper } from "@material-ui/core";
|
||||
import InsertPhotoIcon from "@material-ui/icons/InsertPhoto";
|
||||
@@ -42,6 +43,7 @@ const useStyles = makeStyles((theme) => ({
|
||||
display: "flex",
|
||||
flexFlow: "row nowrap",
|
||||
justifyContent: "flex-start",
|
||||
paddingLeft: "5px", // re-align left buttons after overriding material-ui spacing
|
||||
},
|
||||
rightButtons: {
|
||||
display: "flex",
|
||||
@@ -52,6 +54,7 @@ const useStyles = makeStyles((theme) => ({
|
||||
},
|
||||
button: {
|
||||
background: "transparent",
|
||||
minWidth: "45px", // override default material-ui spacing between buttons
|
||||
},
|
||||
buttonHidden: {
|
||||
display: "none",
|
||||
@@ -72,9 +75,42 @@ const useStyles = makeStyles((theme) => ({
|
||||
},
|
||||
}));
|
||||
|
||||
const TEMP_MEDIA = [
|
||||
{
|
||||
id: uuidv4(),
|
||||
mediaType: "image",
|
||||
mediaLink:
|
||||
"http://www.freedigitalphotos.net/images/thumbs/city-10011901.jpg",
|
||||
},
|
||||
{
|
||||
id: uuidv4(),
|
||||
mediaType: "image",
|
||||
mediaLink:
|
||||
"https://images.unsplash.com/photo-1541963463532-d68292c34b19?ixlib=rb-1.2.1&w=1000&q=80",
|
||||
},
|
||||
{
|
||||
id: uuidv4(),
|
||||
mediaType: "image",
|
||||
mediaLink:
|
||||
"https://static01.nyt.com/images/2020/07/17/business/00virus-cities1/00virus-cities1-mediumSquareAt3X.jpg",
|
||||
},
|
||||
{
|
||||
id: uuidv4(),
|
||||
mediaType: "image",
|
||||
mediaLink:
|
||||
"https://image.cnbcfm.com/api/v1/image/105066394-GettyImages-498350103_1.jpg?v=1591858410",
|
||||
},
|
||||
{
|
||||
id: uuidv4(),
|
||||
mediaType: "image",
|
||||
mediaLink:
|
||||
"https://www.cbre.us/-/media/cbre/countryunitedkingdom/images/our-cities/231_what_makes_a_successful_city_image2_1024x576.jpg",
|
||||
},
|
||||
];
|
||||
|
||||
export const AddTweetModal = ({ visible, handleClose }) => {
|
||||
const [text, setText] = useState("");
|
||||
const [media, setMedia] = useState(null);
|
||||
const [media, setMedia] = useState(TEMP_MEDIA);
|
||||
const [mediaType, setMediaType] = useState(null);
|
||||
const [mediaLink, setMediaLink] = useState(null);
|
||||
const classes = useStyles();
|
||||
@@ -84,24 +120,30 @@ export const AddTweetModal = ({ visible, handleClose }) => {
|
||||
: classes.displayNone;
|
||||
|
||||
const submitTweet = () => {
|
||||
const data = { text, ...media };
|
||||
const data = { text, media };
|
||||
|
||||
console.log("submitting tweet");
|
||||
|
||||
console.log(data);
|
||||
};
|
||||
|
||||
const addMedia = useCallback(() => {
|
||||
setMedia({ mediaType, mediaLink });
|
||||
// we add an ID here so that we can have a distinct identifier on the
|
||||
// client before it is added to the database. This ID is NOT what used
|
||||
// or contained in the database.
|
||||
setMedia(media.concat([{ id: uuidv4(), mediaType, mediaLink }]));
|
||||
setMediaType(null);
|
||||
setMediaLink(null);
|
||||
}, [mediaType, mediaLink]);
|
||||
|
||||
const closeMedia = useCallback(() => {
|
||||
const _removeMedia = (id) => setMedia(media.filter((m) => m.id !== id));
|
||||
const removeMedia = useCallback(_removeMedia, [media]);
|
||||
|
||||
const closeMediaPrompt = useCallback(() => {
|
||||
setMediaType(null);
|
||||
setMediaLink(null);
|
||||
}, []);
|
||||
|
||||
console.log(media);
|
||||
return (
|
||||
<div className={showHideClassName}>
|
||||
<Paper className={classes.root}>
|
||||
@@ -115,7 +157,7 @@ export const AddTweetModal = ({ visible, handleClose }) => {
|
||||
handleChange={(e) => setMediaLink(e.target.value)}
|
||||
/>
|
||||
)}
|
||||
{media && <MediaDisplay {...media} />}
|
||||
<MediaDisplay media={media} removeMedia={removeMedia} />
|
||||
<div className={classes.buttonsContainer}>
|
||||
<div className={classes.leftButtons}>
|
||||
<Button
|
||||
@@ -143,7 +185,7 @@ export const AddTweetModal = ({ visible, handleClose }) => {
|
||||
className={classes.closeMedia}
|
||||
variant="contained"
|
||||
color="secondary"
|
||||
onClick={closeMedia}
|
||||
onClick={closeMediaPrompt}
|
||||
>
|
||||
{t("APPS_TWITTER_CLOSE_MEDIA")}
|
||||
</Button>
|
||||
|
||||
@@ -1,32 +1,76 @@
|
||||
import React from "react";
|
||||
import React, { useCallback } from "react";
|
||||
import { IconButton } from "@material-ui/core";
|
||||
import { makeStyles } from "@material-ui/core/styles";
|
||||
import CloseIcon from "@material-ui/icons/Close";
|
||||
import types from "../types";
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
root: {
|
||||
margin: "2px 15px",
|
||||
},
|
||||
mediaImage: {
|
||||
// catch the close button here so it doesn't go all the way up to the modal
|
||||
position: "relative",
|
||||
display: "inline-block",
|
||||
},
|
||||
imgButton: {
|
||||
position: "absolute", // show the close button in the top right of the image
|
||||
top: "2px",
|
||||
right: "5px",
|
||||
backgroundColor: "#000",
|
||||
opacity: 0.7,
|
||||
"&:hover": {
|
||||
// fixes a bug where when the user closes one image material-ui puts
|
||||
// the hover status on the previous image
|
||||
backgroundColor: "#000",
|
||||
},
|
||||
},
|
||||
img: {
|
||||
maxHeight: "125px",
|
||||
maxHeight: "125px", // constrain images so we don't overwhelm the UI
|
||||
maxWidth: "500px",
|
||||
padding: "0px 3px 3px 0px",
|
||||
},
|
||||
}));
|
||||
|
||||
export const Media = ({ mediaType, mediaLink }) => {
|
||||
export const MediaImage = ({ mediaLink, handleClick }) => {
|
||||
const classes = useStyles();
|
||||
return (
|
||||
<div className={classes.mediaImage}>
|
||||
<IconButton
|
||||
className={classes.imgButton}
|
||||
onClick={handleClick}
|
||||
size="small"
|
||||
>
|
||||
<CloseIcon />
|
||||
</IconButton>
|
||||
<img className={classes.img} src={mediaLink} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const Media = ({ id, mediaType, mediaLink, handleClose }) => {
|
||||
switch (mediaType) {
|
||||
case types.IMAGE:
|
||||
case types.GIF:
|
||||
return <img className={classes.img} src={mediaLink} />;
|
||||
return <MediaImage mediaLink={mediaLink} handleClick={handleClose} />;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export const MediaDisplay = (props) => {
|
||||
export const MediaDisplay = ({ media, removeMedia }) => {
|
||||
const classes = useStyles();
|
||||
if (media.length === 0) return null;
|
||||
|
||||
return (
|
||||
<div className={classes.root}>
|
||||
<Media {...props} />
|
||||
{media.map((mediaItem) => (
|
||||
<Media
|
||||
id={mediaItem.id}
|
||||
handleClose={() => removeMedia(mediaItem.id)}
|
||||
{...mediaItem}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -11415,6 +11415,11 @@ uuid@^3.3.2, uuid@^3.4.0:
|
||||
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
|
||||
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==
|
||||
|
||||
uuid@^8.3.0:
|
||||
version "8.3.0"
|
||||
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.0.tgz#ab738085ca22dc9a8c92725e459b1d507df5d6ea"
|
||||
integrity sha512-fX6Z5o4m6XsXBdli9g7DtWgAx+osMsRRZFKma1mIUsLCz6vRvv+pz5VNbyu9UEDzpMWulZfvpgb/cmDXVulYFQ==
|
||||
|
||||
v8-compile-cache@^2.0.3, v8-compile-cache@^2.1.1:
|
||||
version "2.1.1"
|
||||
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.1.1.tgz#54bc3cdd43317bca91e35dcaf305b1a7237de745"
|
||||
|
||||
@@ -9,5 +9,4 @@ Config.PhoneAsItem = false
|
||||
Config.twitter = {}
|
||||
Config.twitter.characterLimit = 240
|
||||
Config.twitter.renderImages = true -- whether or not links to images are automatically rendered on the UI
|
||||
Config.twitter.renderGifs = true -- whether or not links to gifs are automatically rendered on the UI
|
||||
Config.twitter.renderVideos = true -- whether or not links to videos are automatically rendered on the UI
|
||||
Config.twitter.maxImages = 3 -- max amount of images that can be attached to a single tweet
|
||||
Reference in new issue
Block a user