diff --git a/client/modules/IDE/components/SketchList.jsx b/client/modules/IDE/components/SketchList.jsx index 2237227766..e9666fae4a 100644 --- a/client/modules/IDE/components/SketchList.jsx +++ b/client/modules/IDE/components/SketchList.jsx @@ -24,6 +24,7 @@ import getConfig from '../../../utils/getConfig'; import ArrowUpIcon from '../../../images/sort-arrow-up.svg'; import ArrowDownIcon from '../../../images/sort-arrow-down.svg'; +import ExamplePreview from '../../User/components/ExamplePreview'; const ROOT_URL = getConfig('API_URL'); @@ -35,7 +36,8 @@ class SketchListRowBase extends React.Component { super(props); this.state = { renameOpen: false, - renameValue: props.sketch.name + renameValue: props.sketch.name, + preview: false }; this.renameInput = React.createRef(); } @@ -144,6 +146,15 @@ class SketchListRowBase extends React.Component { > {this.props.t('SketchList.DropdownAddToCollection')} + { + this.setState({ + preview: !this.state.preview + }); + }} + > + Preview + {/* @@ -194,6 +205,18 @@ class SketchListRowBase extends React.Component { {formatDateCell(sketch.updatedAt, mobile)} {this.renderDropdown()} + {this.state.preview && ( + + + + this.setState({ preview: !this.state.preview }) + } + sketch={this.props.sketch} + /> + + + )} ); } diff --git a/client/modules/User/components/ExamplePreview.jsx b/client/modules/User/components/ExamplePreview.jsx new file mode 100644 index 0000000000..9bb6da3231 --- /dev/null +++ b/client/modules/User/components/ExamplePreview.jsx @@ -0,0 +1,74 @@ +import React, { useMemo, useState } from 'react'; +import PropTypes from 'prop-types'; +import EmbedFrame from '../../Preview/EmbedFrame'; + +function ExamplePreview({ sketch, setSketch }) { + const [hover, setHover] = useState(false); + const sketchHeight = useMemo(() => { + const jsFile = (sketch?.files || []).find( + (file) => file.name === 'sketch.js' + ); + return jsFile?.content?.match(/createCanvas\(\d+, ?(\d+)/)[1]; + }, [sketch]); + + const { files = [] } = sketch; + + return ( + + {files.length > 0 ? ( + <> + +
+ +
+ + ) : ( +
loading
+ )} +
+ ); +} + +ExamplePreview.propTypes = { + sketch: PropTypes.shape({ + files: PropTypes.arrayOf( + PropTypes.shape({ + name: PropTypes.string.isRequired, + content: PropTypes.string + }) + ) + }).isRequired, + setSketch: PropTypes.func.isRequired +}; + +export default ExamplePreview;