diff --git a/src/components/ChatRoom.js b/src/components/ChatRoom.js index 0c65d1c..a3dcc8f 100644 --- a/src/components/ChatRoom.js +++ b/src/components/ChatRoom.js @@ -5,9 +5,7 @@ import autoscroll from 'autoscroll-react'; import List from '@material-ui/core/List'; import Divider from '@material-ui/core/Divider'; import Grid from '@material-ui/core/Grid'; -import Button from '@material-ui/core/Button'; import Dropzone from 'react-dropzone'; -import AddCircle from '@material-ui/icons/AddCircle'; import Message from './Message'; import ChatHeader from './ChatHeader'; @@ -15,6 +13,7 @@ import Userlist from './Userlist'; import WhoIsTyping from './WhoIsTyping'; import EmojiPicker from './chatInput/EmojiPicker'; import ChatTextInput from './chatInput/ChatTextInput'; +import FileUploadButton from './chatInput/FileUploadButton'; import { uploadFileAndSend } from '../utils/ipfs'; function onDrop(acceptedFiles, rejectedFiles, ipfs, sendMessage) { @@ -54,16 +53,6 @@ class ChatRoom extends Component { this.setState({ infoPanelActive: !this.state.infoPanelActive }) } - uploadFileDialog() { - this.fileInput.click(); - } - - fileChangedHandler(event) { - const { ipfs, sendMessage } = this.props; - const file = event.target.files[0]; - uploadFileAndSend(ipfs, file, sendMessage); - } - addEmoji(emoji, chatInput, setValue) { setValue('chatInput', `${chatInput}:${emoji.id}:`); NameInput.current.labelNode.focus(); @@ -75,12 +64,6 @@ class ChatRoom extends Component { const messagesHeight = `calc(100vh - ${messagesOffset}px)`; return (
- { this.fileInput = input; }} - onChange={this.fileChangedHandler.bind(this)} - style={{display: 'none'}} - /> { @@ -135,7 +118,7 @@ class ChatRoom extends Component { }) => (
- + keyDownHandler(e, typingEvent, setFieldValue, values.chatInput)} handleBlur={handleBlur} chatInput={values.chatInput || ''} /> this.addEmoji(emoji, values.chatInput, setFieldValue)} /> {errors.chatInput && touched.chatInput && errors.chatInput} diff --git a/src/components/chatInput/FileUploadButton.js b/src/components/chatInput/FileUploadButton.js new file mode 100644 index 0000000..03e86ba --- /dev/null +++ b/src/components/chatInput/FileUploadButton.js @@ -0,0 +1,35 @@ +// TODO: this should be a functional component but for now at least the logic is isolated here +import React, { Fragment, PureComponent } from 'react'; +import Button from '@material-ui/core/Button'; +import AddCircle from '@material-ui/icons/AddCircle'; +import { uploadFileAndSend } from '../../utils/ipfs'; + +class FileUploadButton extends PureComponent { + + uploadFileDialog() { + this.fileInput.click(); + } + + fileChangedHandler(event) { + const { ipfs, sendMessage } = this.props; + const file = event.target.files[0]; + uploadFileAndSend(ipfs, file, sendMessage); + } + + render() { + return ( + + { this.fileInput = input; }} + onChange={this.fileChangedHandler.bind(this)} + style={{display: 'none'}} + /> + + + + ); + } +} + +export default FileUploadButton;