import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import * as Blockly from 'blockly/core'; import IconButton from '@material-ui/core/IconButton'; import Tooltip from '@material-ui/core/Tooltip'; import { withStyles } from '@material-ui/core/styles'; import { faTimes, faTrash } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; const styles = (theme) => ({ closeTrash: { '&:hover': { backgroundColor: 'transparent', color: theme.palette.primary.main, } }, deleteTrash: { '&:hover': { backgroundColor: 'transparent', color: theme.palette.primary.main, } } }); class TrashcanButtons extends Component { state = { closeTrashFlyout: false } componentDidUpdate(previousProps, previousState) { const workspace = Blockly.getMainWorkspace(); const contentsIsOpen = workspace.trashcan.contentsIsOpen(); if (previousState.closeTrashFlyout !== contentsIsOpen) { this.setState({ closeTrashFlyout: contentsIsOpen }); } } closeTrashcan = () => { this.setState({ closeTrashFlyout: false }); const workspace = Blockly.getMainWorkspace(); // https://github.com/google/blockly/blob/master/core/blockly.js#L314 workspace.trashcan.flyout.hide(); }; clearTrashcan = () => { this.setState({ closeTrashFlyout: false }); const workspace = Blockly.getMainWorkspace(); // https://developers.google.com/blockly/reference/js/Blockly.Trashcan#emptyContents workspace.trashcan.emptyContents(); } render() { return ( this.state.closeTrashFlyout ?