first pass at permalink box

This commit is contained in:
Riley Davis
2016-11-11 11:27:39 -07:00
parent 8bf6bea5b9
commit e2735759a6
3 changed files with 99 additions and 0 deletions
@@ -14,6 +14,7 @@ import AuthorName from '../../coral-plugin-author-name/AuthorName';
import {ReplyBox, ReplyButton} from '../../coral-plugin-replies';
import Pym from 'pym.js';
import FlagButton from '../../coral-plugin-flags/FlagButton';
import PermalinkButton from '../../coral-plugin-permalinks/PermalinkButton';
const {addItem, updateItem, postItem, getStream, postAction, appendItemArray} = itemActions;
const {addNotification, clearNotification} = notificationActions;
@@ -130,6 +131,9 @@ class CommentStream extends Component {
<ReplyButton
updateItem={this.props.updateItem}
id={commentId}/>
<PermalinkButton
comment_id={commentId}
asset_id={comment.asset_id}/>
</div>
<ReplyBox
addNotification={this.props.addNotification}
@@ -160,6 +164,10 @@ class CommentStream extends Component {
<ReplyButton
updateItem={this.props.updateItem}
parent_id={reply.parent_id}/>
<PermalinkButton
comment_id={reply.comment_id}
asset_id={reply.comment_id}
/>
</div>
</div>;
})
@@ -0,0 +1,90 @@
import React, {PropTypes} from 'react';
import onClickOutside from 'react-onclickoutside';
const name = 'coral-plugin-permalinks';
class PermalinkButton extends React.Component {
static propTypes = {
asset_id: PropTypes.string.isRequired,
comment_id: PropTypes.string.isRequired
}
constructor (props) {
super(props);
this.state = {popoverOpen: false, copySuccessful: null, copyFailure: null};
this.toggle = this.toggle.bind(this);
this.copyPermalink = this.copyPermalink.bind(this);
}
toggle () {
this.setState({popoverOpen: !this.state.popoverOpen});
}
handleClickOutside () {
this.setState({popoverOpen: false});
}
copyPermalink () {
this.permalinkInput.select();
try {
document.execCommand('copy');
this.setState({copySuccessful: true});
} catch (err) {
this.setState({copyFailure: true});
}
setTimeout(() => {
this.setState({copyFailure: null, copySuccessful: null});
}, 4500);
}
render () {
const publisherUrl = 'http://nytimes.com/';
return (
<div className={`${name}-container`} style={styles}>
<button onClick={this.toggle} className={`${name}-button`}>
<i className={`${name}-icon material-icons`} aria-hidden={true}>link</i>
Permalink
</button>
<div
style={styles.popover(this.state.popoverOpen)}
className={`${name}-popover`}>
<input
type='text'
ref={input => this.permalinkInput = input}
value={`${publisherUrl}${this.props.asset_id}#${this.props.comment_id}`}
onChange={() => {}} />
<button className={`${name}-copy-button`} onClick={this.copyPermalink}>Copy</button>
{
this.state.copySuccessful ? <p>copied to clipboard</p> : null
}
{
this.state.copyFailure
? <p>copying to clipboard not supported in this browser. Use Cmd + C.</p>
: null
}
</div>
</div>
);
}
}
export default onClickOutside(PermalinkButton);
const styles = {
position: 'relative',
popover: active => {
return {
display: active ? 'block' : 'none',
backgroundColor: 'white',
border: '1px solid black',
minWidth: 400,
position: 'absolute',
top: 30,
right: 0,
padding: 5
};
}
};
+1
View File
@@ -103,6 +103,7 @@
"react": "15.3.2",
"react-dom": "15.3.2",
"react-mdl": "^1.7.2",
"react-onclickoutside": "^5.7.1",
"react-redux": "^4.4.5",
"react-router": "^3.0.0",
"redux": "^3.6.0",