import React from 'react'; import PropTypes from 'prop-types'; import TranslatedComponent from './TranslatedComponent'; import ShortenUrl from '../utils/ShortenUrl'; /** * Permalink modal */ export default class ModalPermalink extends TranslatedComponent { static propTypes = { url: PropTypes.string.isRequired }; /** * Constructor * @param {Object} props React Component properties */ constructor(props) { super(props); this.state = { shortenedUrl: 'Shortening...' }; } /** * Shorten URL on mount */ componentWillMount() { ShortenUrl(this.props.url, (shortenedUrl) => this.setState({ shortenedUrl }), (error) => this.setState({ shortenedUrl: 'Error - ' + error }) ); } /** * Render the modal * @return {React.Component} Modal Content */ render() { let translate = this.context.language.translate; return