clientjs/packages/dashboard-components/src/ui/IssoThread.jsx
author ymh <ymh.work@gmail.com>
Fri, 14 Sep 2018 17:57:34 +0200
changeset 0 5f4fcbc80b37
child 3 7af67d500dd5
permissions -rw-r--r--
Create new repository to host all dashboard developments This project contains the commons components and all the dashboard instances

import React, { Component } from 'react';
import PropTypes from 'prop-types';

import { insertScript, removeScript } from '../utils';

import './IssoThread.scss';

export default class IssoThread extends Component {
  static propTypes = {
    pathname: PropTypes.string,
    issoId: PropTypes.string.isRequired,
    discussionUrl: PropTypes.string.isRequired,
    messageId: PropTypes.string,
  }

  static defaultProps = {
    pathname: '',
    messageId: '',
  };


  componentWillMount() {
  }

  componentDidMount() {
    const { discussionUrl, pathname } = this.props;
    const jsFile = process.env.NODE_ENV === 'production' ? 'embed.js' : 'embed.dev.js';
    insertScript(
      `${discussionUrl}js/${jsFile}`,
      'isso-js',
      document.body,
      {
        'data-isso-base-location': `#${pathname}/`,
        'data-isso-vote': false,
      },
    );
  }

  componentWillUnmount() {
    removeScript('isso-js', document.body);
  }

  render() {
    const { issoId, messageId } = this.props;
    return <section id="isso-thread" ref={(el) => { this.el = el; }} data-isso-id={issoId} data-isso-target-message={messageId} />;
  }
}