clientjs/packages/dashboard-components/src/ui/IssoThread.jsx
changeset 0 5f4fcbc80b37
child 3 7af67d500dd5
equal deleted inserted replaced
-1:000000000000 0:5f4fcbc80b37
       
     1 import React, { Component } from 'react';
       
     2 import PropTypes from 'prop-types';
       
     3 
       
     4 import { insertScript, removeScript } from '../utils';
       
     5 
       
     6 import './IssoThread.scss';
       
     7 
       
     8 export default class IssoThread extends Component {
       
     9   static propTypes = {
       
    10     pathname: PropTypes.string,
       
    11     issoId: PropTypes.string.isRequired,
       
    12     discussionUrl: PropTypes.string.isRequired,
       
    13     messageId: PropTypes.string,
       
    14   }
       
    15 
       
    16   static defaultProps = {
       
    17     pathname: '',
       
    18     messageId: '',
       
    19   };
       
    20 
       
    21 
       
    22   componentWillMount() {
       
    23   }
       
    24 
       
    25   componentDidMount() {
       
    26     const { discussionUrl, pathname } = this.props;
       
    27     const jsFile = process.env.NODE_ENV === 'production' ? 'embed.js' : 'embed.dev.js';
       
    28     insertScript(
       
    29       `${discussionUrl}js/${jsFile}`,
       
    30       'isso-js',
       
    31       document.body,
       
    32       {
       
    33         'data-isso-base-location': `#${pathname}/`,
       
    34         'data-isso-vote': false,
       
    35       },
       
    36     );
       
    37   }
       
    38 
       
    39   componentWillUnmount() {
       
    40     removeScript('isso-js', document.body);
       
    41   }
       
    42 
       
    43   render() {
       
    44     const { issoId, messageId } = this.props;
       
    45     return <section id="isso-thread" ref={(el) => { this.el = el; }} data-isso-id={issoId} data-isso-target-message={messageId} />;
       
    46   }
       
    47 }