From e13e630cd6e4fc0b1ff92098a28a770794c7bb9a Mon Sep 17 00:00:00 2001 From: gabrhr <73925454+gabrhr@users.noreply.github.com> Date: Wed, 20 Apr 2022 10:19:29 -0500 Subject: =?UTF-8?q?A=C3=B1adir=20plantilla?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Base para front --- .../app/components/SocialMedia/WritePost.js | 169 +++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 front/odiparpack/app/components/SocialMedia/WritePost.js (limited to 'front/odiparpack/app/components/SocialMedia/WritePost.js') diff --git a/front/odiparpack/app/components/SocialMedia/WritePost.js b/front/odiparpack/app/components/SocialMedia/WritePost.js new file mode 100644 index 0000000..3452aea --- /dev/null +++ b/front/odiparpack/app/components/SocialMedia/WritePost.js @@ -0,0 +1,169 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import classNames from 'classnames'; +import Dropzone from 'react-dropzone'; +import { withStyles } from '@material-ui/core/styles'; +import PhotoCamera from '@material-ui/icons/PhotoCamera'; +import Send from '@material-ui/icons/Send'; +import ActionDelete from '@material-ui/icons/Delete'; +import dummy from 'ba-api/dummyContents'; +import { IconButton, Fab, MenuItem, FormControl, Avatar, Paper, Select, Tooltip } from '@material-ui/core'; +import styles from './jss/writePost-jss'; + + +function isImage(file) { + const fileName = file.name || file.path; + const suffix = fileName.substr(fileName.indexOf('.') + 1).toLowerCase(); + if (suffix === 'jpg' || suffix === 'jpeg' || suffix === 'bmp' || suffix === 'png') { + return true; + } + return false; +} + +class WritePost extends React.Component { + constructor(props) { + super(props); + this.state = { + privacy: 'public', + files: [], + message: '' + }; + this.onDrop = this.onDrop.bind(this); + } + + onDrop(filesVal) { + const { files } = this.state; + let oldFiles = files; + const filesLimit = 2; + oldFiles = oldFiles.concat(filesVal); + if (oldFiles.length > filesLimit) { + console.log('Cannot upload more than ' + filesLimit + ' items.'); + } else { + this.setState({ files: filesVal }); + } + } + + handleRemove(file, fileIndex) { + const thisFiles = this.state.files; + // This is to prevent memory leaks. + window.URL.revokeObjectURL(file.preview); + + thisFiles.splice(fileIndex, 1); + this.setState({ files: thisFiles }); + } + + handleChange = event => { + this.setState({ privacy: event.target.value }); + }; + + handleWrite = event => { + this.setState({ message: event.target.value }); + }; + + handlePost = (message, files, privacy) => { + // Submit Post to reducer + this.props.submitPost(message, files, privacy); + // Reset all fields + this.setState({ + privacy: 'public', + files: [], + message: '' + }); + } + + render() { + const { classes } = this.props; + let dropzoneRef; + const { privacy, files, message } = this.state; + const acceptedFiles = ['image/jpeg', 'image/png', 'image/bmp']; + const fileSizeLimit = 3000000; + const deleteBtn = (file, index) => ( +