|
|
@ -3,6 +3,7 @@ import React, { Component } from 'react'; |
|
|
|
import PropTypes from 'prop-types'; |
|
|
|
import uuidv4 from 'uuid/v4'; |
|
|
|
|
|
|
|
import TimeAgo from 'react-timeago'; |
|
|
|
import UserAvatar from 'react-user-avatar'; |
|
|
|
import ReactMarkdown from 'react-markdown'; |
|
|
|
|
|
|
@ -18,6 +19,9 @@ class NewPost extends Component { |
|
|
|
this.validateAndPost = this.validateAndPost.bind(this); |
|
|
|
this.pushToDatabase = this.pushToDatabase.bind(this); |
|
|
|
|
|
|
|
this.newPostOuterRef = React.createRef(); |
|
|
|
this.subjectInputRef = React.createRef(); |
|
|
|
|
|
|
|
this.transactionProgressText = []; |
|
|
|
this.drizzle = context.drizzle; |
|
|
|
|
|
|
@ -84,7 +88,7 @@ class NewPost extends Component { |
|
|
|
|
|
|
|
render() { |
|
|
|
return ( |
|
|
|
<div className="post card"> |
|
|
|
<div className="post" ref={this.newPostOuterRef}> |
|
|
|
{this.state.creatingPost && <div id="overlay"> |
|
|
|
<div id="overlay-content"> |
|
|
|
<p><i className="fas fa-spinner fa-3x fa-spin"></i></p> |
|
|
@ -93,25 +97,37 @@ class NewPost extends Component { |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
} |
|
|
|
<div className="post-header"> |
|
|
|
<div className="row"> |
|
|
|
<div className="col s1"> |
|
|
|
<UserAvatar |
|
|
|
size="40" |
|
|
|
className="inline user-avatar" |
|
|
|
src={this.props.user.avatarUrl} |
|
|
|
name={this.props.user.username}/> |
|
|
|
<p className="inline no-margin"> |
|
|
|
<strong>{this.props.user.username}<br/>Subject: {this.state.postSubjectInput}</strong> |
|
|
|
</p> |
|
|
|
<div className="post-info"> |
|
|
|
<span></span> |
|
|
|
<span>#{this.props.postIndex}</span> |
|
|
|
src={this.props.avatarUrl} |
|
|
|
name={this.props.user.username} |
|
|
|
/> |
|
|
|
</div> |
|
|
|
<div className="col s11"> |
|
|
|
<div> |
|
|
|
<div className="stretch-space-between"> |
|
|
|
<strong><span>{this.props.user.username}</span></strong> |
|
|
|
<span className="grey-text text-darken-2"> |
|
|
|
{this.state.previewEnabled && |
|
|
|
<TimeAgo date={this.state.previewDate}/> |
|
|
|
}{this.state.previewEnabled && ","} #{this.props.postIndex} |
|
|
|
</span> |
|
|
|
</div> |
|
|
|
<div className="stretch-space-between"> |
|
|
|
<strong><span> |
|
|
|
{this.state.previewEnabled && |
|
|
|
("Subject: " + this.state.postSubjectInput) |
|
|
|
} |
|
|
|
</span></strong> |
|
|
|
</div> |
|
|
|
<hr/> |
|
|
|
<div className="post-content"> |
|
|
|
<div> |
|
|
|
<form className="topic-form"> |
|
|
|
{this.state.previewEnabled |
|
|
|
? <ReactMarkdown source={this.state.postContentInput} className="markdownPreview" /> |
|
|
|
? <ReactMarkdown source={this.state.postContentInput} |
|
|
|
className="markdownPreview" /> |
|
|
|
: [ |
|
|
|
<input key={"postSubjectInput"} |
|
|
|
name={"postSubjectInput"} |
|
|
@ -120,6 +136,7 @@ class NewPost extends Component { |
|
|
|
value={this.state.postSubjectInput} |
|
|
|
placeholder="Subject" |
|
|
|
id="postSubjectInput" |
|
|
|
ref={this.subjectInputRef} |
|
|
|
onChange={this.handleInputChange} />, |
|
|
|
<textarea key={"postContentInput"} |
|
|
|
name={"postContentInput"} |
|
|
@ -129,23 +146,28 @@ class NewPost extends Component { |
|
|
|
onChange={this.handleInputChange} /> |
|
|
|
]} |
|
|
|
<button key="submit" |
|
|
|
className="btn waves-effect waves-teal white black-text" |
|
|
|
type="button" |
|
|
|
onClick={this.validateAndPost}> |
|
|
|
Post |
|
|
|
<i className="material-icons right">send</i>Post |
|
|
|
</button> |
|
|
|
<button className="margin-left-small" |
|
|
|
<button className="waves-effect waves-orange btn white black-text margin-left-small" |
|
|
|
type="button" |
|
|
|
onClick={this.handlePreviewToggle}> |
|
|
|
{this.state.previewEnabled ? "Edit" : "Preview"} |
|
|
|
<span>{this.state.previewEnabled ? "Edit" : "Preview"}</span> |
|
|
|
</button> |
|
|
|
<button className="margin-left-small" |
|
|
|
<button className="btn red margin-left-small" |
|
|
|
type="button" |
|
|
|
onClick={this.props.onCancelClick}> |
|
|
|
Cancel |
|
|
|
<span>Cancel</span> |
|
|
|
</button> |
|
|
|
</form> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div className="divider"></div> |
|
|
|
</div> |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
@ -298,6 +320,16 @@ class NewPost extends Component { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
componentDidUpdate(prevProps, prevState){ |
|
|
|
if (!this.state.previewEnabled && prevState.previewEnabled){ |
|
|
|
this.newPostOuterRef.current.scrollIntoView(true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
componentDidMount(){ |
|
|
|
this.newPostOuterRef.current.scrollIntoView(true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
NewPost.contextTypes = { |
|
|
|