import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { shareProject } from '../../actions/projectActions'; import { clearMessages } from '../../actions/messageActions'; import moment from 'moment'; import Dialog from '../Dialog'; import Snackbar from '../Snackbar'; import { Link } from 'react-router-dom'; import { withStyles } from '@material-ui/core/styles'; import IconButton from '@material-ui/core/IconButton'; import Tooltip from '@material-ui/core/Tooltip'; import Typography from '@material-ui/core/Typography'; import { faShareAlt, faCopy } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import * as Blockly from 'blockly/core'; const styles = (theme) => ({ button: { backgroundColor: theme.palette.primary.main, color: theme.palette.primary.contrastText, width: '40px', height: '40px', '&:hover': { backgroundColor: theme.palette.primary.main, color: theme.palette.primary.contrastText, } }, link: { color: theme.palette.primary.main, textDecoration: 'none', '&:hover': { color: theme.palette.primary.main, textDecoration: 'underline' } } }); class WorkspaceFunc extends Component { constructor(props) { super(props); this.inputRef = React.createRef(); this.state = { snackbar: false, type: '', key: '', message: '', title: '', content: '', open: false, id: '', }; } componentDidUpdate(props) { if (this.props.message !== props.message) { if (this.props.message.id === 'SHARE_SUCCESS' && (!this.props.multiple || this.props.message.status === this.props.project._id)) { this.setState({ share: true, open: true, title: Blockly.Msg.messages_SHARE_SUCCESS, id: this.props.message.status }); } else if (this.props.message.id === 'SHARE_FAIL' && (!this.props.multiple || this.props.message.status === this.props.project._id)) { this.setState({ snackbar: true, key: Date.now(), message: Blockly.Msg.messages_SHARE_FAIL, type: 'error' }); window.scrollTo(0, 0); } } } componentWillUnmount() { this.props.clearMessages(); } toggleDialog = () => { this.setState({ open: !this.state, title: '', content: '' }); } shareBlocks = () => { if (this.props.projectType === 'project' && this.props.project.shared) { // project is already shared this.setState({ open: true, title: Blockly.Msg.messages_SHARE_SUCCESS, id: this.props.project._id }); } else { this.props.shareProject(this.props.name || this.props.project.title, this.props.projectType, this.props.project ? this.props.project._id : undefined); } } render() { return (