diff --git a/app/src/components/NewPost.js b/app/src/components/NewPost.js new file mode 100644 index 0000000..59d79bc --- /dev/null +++ b/app/src/components/NewPost.js @@ -0,0 +1,175 @@ +import React, { Component } from 'react'; +import { connect } from 'react-redux'; + +import { Grid, Form, TextArea, Button, Icon, Divider } from 'semantic-ui-react' + +import TimeAgo from 'react-timeago'; +import UserAvatar from 'react-user-avatar'; +import ReactMarkdown from 'react-markdown'; + +/*import { createPost } from '../redux/actions/transactionsMonitorActions';*/ + +class NewPost extends Component { + constructor(props, context) { + super(props); + + this.handleInputChange = this.handleInputChange.bind(this); + this.handlePreviewToggle = this.handlePreviewToggle.bind(this); + this.validateAndPost = this.validateAndPost.bind(this); + + this.newPostOuterRef = React.createRef(); + + this.state = { + postSubjectInput: this.props.subject ? this.props.subject : "", + postContentInput: '', + postSubjectInputEmptySubmit: false, + postContentInputEmptySubmit: false, + previewEnabled: false, + previewDate: "" + }; + } + + async validateAndPost() { + if (this.state.postSubjectInput === '' || this.state.postContentInput === ''){ + this.setState({ + postSubjectInputEmptySubmit: this.state.postSubjectInput === '', + postContentInputEmptySubmit: this.state.postContentInput === '' + }); + return; + } + + /*this.props.store.dispatch( + createPost(this.props.topicID, + { + postSubject: this.state.postSubjectInput, + postMessage: this.state.postContentInput + } + ) + );*/ + this.props.onPostCreated(); + } + + handleInputChange(event) { + this.setState({[event.target.name]: event.target.value}); + } + + handlePreviewToggle() { + this.setState((prevState, props) => ({ + previewEnabled: !prevState.previewEnabled, + previewDate: this.getDate() + })); + } + + getDate() { + const currentdate = new Date(); + return ((currentdate.getMonth() + 1) + " " + + currentdate.getDate() + ", " + + currentdate.getFullYear() + ", " + + currentdate.getHours() + ":" + + currentdate.getMinutes() + ":" + + currentdate.getSeconds()); + } + + render() { + return ( +
+ + #{this.props.postIndex} + + + + + + + +
+
+ {this.props.user.username} + + {this.state.previewEnabled && + + } + +
+
+ + {this.state.previewEnabled && + ("Subject: " + this.state.postSubjectInput) + } + +
+
+
+ +
+
+ +