mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +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-router-dom": "^5.2.0",
|
||||||
"react-scripts": "3.4.3",
|
"react-scripts": "3.4.3",
|
||||||
"recoil": "^0.0.10",
|
"recoil": "^0.0.10",
|
||||||
"styled-components": "^5.1.1"
|
"styled-components": "^5.1.1",
|
||||||
|
"uuid": "^8.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/cli": "^7.4.4",
|
"@babel/cli": "^7.4.4",
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import React, { useState, useCallback } from "react";
|
import React, { useState, useCallback } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { v4 as uuidv4 } from "uuid";
|
||||||
import { makeStyles } from "@material-ui/core/styles";
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
import { Button, Paper } from "@material-ui/core";
|
import { Button, Paper } from "@material-ui/core";
|
||||||
import InsertPhotoIcon from "@material-ui/icons/InsertPhoto";
|
import InsertPhotoIcon from "@material-ui/icons/InsertPhoto";
|
||||||
@@ -42,6 +43,7 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
display: "flex",
|
display: "flex",
|
||||||
flexFlow: "row nowrap",
|
flexFlow: "row nowrap",
|
||||||
justifyContent: "flex-start",
|
justifyContent: "flex-start",
|
||||||
|
paddingLeft: "5px", // re-align left buttons after overriding material-ui spacing
|
||||||
},
|
},
|
||||||
rightButtons: {
|
rightButtons: {
|
||||||
display: "flex",
|
display: "flex",
|
||||||
@@ -52,6 +54,7 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
},
|
},
|
||||||
button: {
|
button: {
|
||||||
background: "transparent",
|
background: "transparent",
|
||||||
|
minWidth: "45px", // override default material-ui spacing between buttons
|
||||||
},
|
},
|
||||||
buttonHidden: {
|
buttonHidden: {
|
||||||
display: "none",
|
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 }) => {
|
export const AddTweetModal = ({ visible, handleClose }) => {
|
||||||
const [text, setText] = useState("");
|
const [text, setText] = useState("");
|
||||||
const [media, setMedia] = useState(null);
|
const [media, setMedia] = useState(TEMP_MEDIA);
|
||||||
const [mediaType, setMediaType] = useState(null);
|
const [mediaType, setMediaType] = useState(null);
|
||||||
const [mediaLink, setMediaLink] = useState(null);
|
const [mediaLink, setMediaLink] = useState(null);
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
@@ -84,24 +120,30 @@ export const AddTweetModal = ({ visible, handleClose }) => {
|
|||||||
: classes.displayNone;
|
: classes.displayNone;
|
||||||
|
|
||||||
const submitTweet = () => {
|
const submitTweet = () => {
|
||||||
const data = { text, ...media };
|
const data = { text, media };
|
||||||
|
|
||||||
console.log("submitting tweet");
|
console.log("submitting tweet");
|
||||||
|
|
||||||
console.log(data);
|
console.log(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
const addMedia = useCallback(() => {
|
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);
|
setMediaType(null);
|
||||||
setMediaLink(null);
|
setMediaLink(null);
|
||||||
}, [mediaType, mediaLink]);
|
}, [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);
|
setMediaType(null);
|
||||||
setMediaLink(null);
|
setMediaLink(null);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
console.log(media);
|
||||||
return (
|
return (
|
||||||
<div className={showHideClassName}>
|
<div className={showHideClassName}>
|
||||||
<Paper className={classes.root}>
|
<Paper className={classes.root}>
|
||||||
@@ -115,7 +157,7 @@ export const AddTweetModal = ({ visible, handleClose }) => {
|
|||||||
handleChange={(e) => setMediaLink(e.target.value)}
|
handleChange={(e) => setMediaLink(e.target.value)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{media && <MediaDisplay {...media} />}
|
<MediaDisplay media={media} removeMedia={removeMedia} />
|
||||||
<div className={classes.buttonsContainer}>
|
<div className={classes.buttonsContainer}>
|
||||||
<div className={classes.leftButtons}>
|
<div className={classes.leftButtons}>
|
||||||
<Button
|
<Button
|
||||||
@@ -143,7 +185,7 @@ export const AddTweetModal = ({ visible, handleClose }) => {
|
|||||||
className={classes.closeMedia}
|
className={classes.closeMedia}
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="secondary"
|
color="secondary"
|
||||||
onClick={closeMedia}
|
onClick={closeMediaPrompt}
|
||||||
>
|
>
|
||||||
{t("APPS_TWITTER_CLOSE_MEDIA")}
|
{t("APPS_TWITTER_CLOSE_MEDIA")}
|
||||||
</Button>
|
</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 { makeStyles } from "@material-ui/core/styles";
|
||||||
|
import CloseIcon from "@material-ui/icons/Close";
|
||||||
import types from "../types";
|
import types from "../types";
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
root: {
|
root: {
|
||||||
margin: "2px 15px",
|
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: {
|
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();
|
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) {
|
switch (mediaType) {
|
||||||
case types.IMAGE:
|
case types.IMAGE:
|
||||||
case types.GIF:
|
case types.GIF:
|
||||||
return <img className={classes.img} src={mediaLink} />;
|
return <MediaImage mediaLink={mediaLink} handleClick={handleClose} />;
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const MediaDisplay = (props) => {
|
export const MediaDisplay = ({ media, removeMedia }) => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
if (media.length === 0) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classes.root}>
|
<div className={classes.root}>
|
||||||
<Media {...props} />
|
{media.map((mediaItem) => (
|
||||||
|
<Media
|
||||||
|
id={mediaItem.id}
|
||||||
|
handleClose={() => removeMedia(mediaItem.id)}
|
||||||
|
{...mediaItem}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
</div>
|
</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"
|
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
|
||||||
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==
|
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:
|
v8-compile-cache@^2.0.3, v8-compile-cache@^2.1.1:
|
||||||
version "2.1.1"
|
version "2.1.1"
|
||||||
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.1.1.tgz#54bc3cdd43317bca91e35dcaf305b1a7237de745"
|
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 = {}
|
||||||
Config.twitter.characterLimit = 240
|
Config.twitter.characterLimit = 240
|
||||||
Config.twitter.renderImages = true -- whether or not links to images are automatically rendered on the UI
|
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.maxImages = 3 -- max amount of images that can be attached to a single tweet
|
||||||
Config.twitter.renderVideos = true -- whether or not links to videos are automatically rendered on the UI
|
|
||||||
Reference in new issue
Block a user