import React, { Component } from "react"; import PropTypes from "prop-types"; import { connect } from "react-redux"; import { clearStats, workspaceName } from "../actions/workspaceActions"; import * as Blockly from "blockly/core"; import { createNameId } from "mnemonic-id"; import WorkspaceStats from "./Workspace/WorkspaceStats"; import WorkspaceFunc from "./Workspace/WorkspaceFunc"; import BlocklyWindow from "./Blockly/BlocklyWindow"; import CodeViewer from "./CodeViewer"; import TrashcanButtons from "./Workspace/TrashcanButtons"; // import HintTutorialExists from "./Tutorial/HintTutorialExists"; import DeviceSelection from "./DeviceSelection"; import Grid from "@material-ui/core/Grid"; import IconButton from "@material-ui/core/IconButton"; import Tooltip from "@material-ui/core/Tooltip"; import { withStyles } from "@material-ui/core/styles"; import { faCode } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import TooltipViewer from "./TooltipViewer"; import Dialog from "./Dialog"; // import Autosave from "./Workspace/AutoSave"; const styles = (theme) => ({ codeOn: { backgroundColor: theme.palette.primary.main, color: theme.palette.primary.contrastText, "&:hover": { backgroundColor: theme.palette.primary.contrastText, color: theme.palette.primary.main, border: `1px solid ${theme.palette.secondary.main}`, }, }, codeOff: { backgroundColor: theme.palette.primary.contrastText, color: theme.palette.primary.main, border: `1px solid ${theme.palette.secondary.main}`, "&:hover": { backgroundColor: theme.palette.primary.main, color: theme.palette.primary.contrastText, }, }, }); class Home extends Component { constructor(props) { super(props); this.state = { codeOn: true, snackbar: false, type: "", key: "", message: "", open: true, initialXml: localStorage.getItem("autoSaveXML"), }; } componentDidMount() { if (this.props.platform === true) { this.setState({ codeOn: false }); } this.setState({ stats: window.localStorage.getItem("stats") }); if (!this.props.project) { this.props.workspaceName(createNameId()); } if (this.props.message && this.props.message.id === "GET_SHARE_FAIL") { this.setState({ snackbar: true, key: Date.now(), message: `Das angefragte geteilte Projekt konnte nicht gefunden werden.`, type: "error", }); } } componentDidUpdate(props) { /* Resize and reposition all of the workspace chrome (toolbox, trash, scrollbars etc.) This should be called when something changes that requires recalculating dimensions and positions of the trash, zoom, toolbox, etc. (e.g. window resize). */ const workspace = Blockly.getMainWorkspace(); Blockly.svgResize(workspace); } componentWillUnmount() { this.props.clearStats(); this.props.workspaceName(null); } toggleDialog = () => { this.setState({ open: !this.state }); }; onChangeCheckbox = (e) => { if (e.target.checked) { window.localStorage.setItem("ota", e.target.checked); } else { window.localStorage.removeItem("ota"); } }; onChange = () => { this.setState({ codeOn: !this.state.codeOn }); const workspace = Blockly.getMainWorkspace(); // https://github.com/google/blockly/blob/master/core/blockly.js#L314 if (workspace.trashcan && workspace.trashcan.flyout) { workspace.trashcan.flyout.hide(); // in case of resize, the trash flyout does not reposition } }; render() { return (
{this.props.statistics ? (
) : null}
{/* */}
this.onChange()} >
{this.props.project ? ( ) : ( )}
{this.state.codeOn ? ( ) : null}
{/* */} {this.props.platform ? (
{Blockly.Msg.tabletDialog_text}
{Blockly.Msg.tabletDialog_more}{" "} https://sensebox.de/app
) : null}
); } } Home.propTypes = { clearStats: PropTypes.func.isRequired, workspaceName: PropTypes.func.isRequired, message: PropTypes.object.isRequired, statistics: PropTypes.bool.isRequired, platform: PropTypes.bool.isRequired, }; const mapStateToProps = (state) => ({ message: state.message, statistics: state.general.statistics, platform: state.general.platform, }); export default connect(mapStateToProps, { clearStats, workspaceName })( withStyles(styles, { withTheme: true })(Home) );