2017-10-10 11:53:14 -03:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import ReactDisqusComments from 'react-disqus-comments';
|
|
|
|
import config from '../../../gatsby-config';
|
|
|
|
|
|
|
|
class Disqus extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2018-01-21 03:03:59 +03:00
|
|
|
this.state = { toasts: [] };
|
2017-10-10 11:53:14 -03:00
|
|
|
this.notifyAboutComment = this.notifyAboutComment.bind(this);
|
|
|
|
this.onSnackbarDismiss = this.onSnackbarDismiss.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
onSnackbarDismiss() {
|
|
|
|
const [, ...toasts] = this.state.toasts;
|
|
|
|
this.setState({ toasts });
|
|
|
|
}
|
|
|
|
notifyAboutComment() {
|
|
|
|
const toasts = this.state.toasts.slice();
|
|
|
|
toasts.push({ text: 'New comment available!!' });
|
|
|
|
this.setState({ toasts });
|
|
|
|
}
|
|
|
|
render() {
|
|
|
|
const { postNode } = this.props;
|
|
|
|
if (!config.siteMetadata.disqusShortname) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
const post = postNode.frontmatter;
|
|
|
|
const url = config.siteMetadata.url + postNode.fields.slug;
|
|
|
|
return (
|
|
|
|
<ReactDisqusComments
|
|
|
|
shortname={config.siteMetadata.disqusShortname}
|
|
|
|
identifier={post.title}
|
|
|
|
title={post.title}
|
|
|
|
url={url}
|
|
|
|
category_id={post.category_id}
|
|
|
|
onNewComment={this.notifyAboutComment}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Disqus;
|