File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed
client/modules/IDE/components Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ import mime from 'mime' ;
2
+ import PropTypes from 'prop-types' ;
3
+ import React from 'react' ;
4
+ import styled from 'styled-components' ;
5
+
6
+ const Audio = styled . audio `
7
+ width: 90%;
8
+ margin: 30px 5%;
9
+ ` ;
10
+
11
+ const Image = styled . img `
12
+ max-width: 100%;
13
+ height: auto;
14
+ ` ;
15
+
16
+ const Video = styled . video `
17
+ max-width: 100%;
18
+ height: auto;
19
+ ` ;
20
+
21
+ function AssetPreview ( { url, name } ) {
22
+ const contentType = mime . getType ( url ) ;
23
+ const type = contentType ?. split ( '/' ) [ 0 ] ;
24
+
25
+ switch ( type ) {
26
+ case 'image' :
27
+ return < Image src = { url } alt = { `Preview of file ${ name } ` } /> ;
28
+ case 'audio' :
29
+ // eslint-disable-next-line jsx-a11y/media-has-caption
30
+ return < Audio src = { url } controls preload = "metadata" /> ;
31
+ case 'video' :
32
+ return (
33
+ // eslint-disable-next-line jsx-a11y/media-has-caption
34
+ < Video controls preload = "metadata" >
35
+ < source src = { url } type = { contentType } />
36
+ </ Video >
37
+ ) ;
38
+ default :
39
+ return null ;
40
+ }
41
+ }
42
+
43
+ AssetPreview . propTypes = {
44
+ url : PropTypes . string . isRequired ,
45
+ name : PropTypes . string . isRequired
46
+ } ;
47
+
48
+ export default AssetPreview ;
Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ import '../../../utils/htmlmixed';
44
44
import '../../../utils/p5-javascript' ;
45
45
import Timer from '../components/Timer' ;
46
46
import EditorAccessibility from '../components/EditorAccessibility' ;
47
+ import AssetPreview from './AssetPreview' ;
47
48
import { metaKey } from '../../../utils/metaKey' ;
48
49
import './show-hint' ;
49
50
import * as hinter from '../../../utils/p5-hinter' ;
@@ -532,6 +533,9 @@ class Editor extends React.Component {
532
533
} }
533
534
className = { editorHolderClass }
534
535
/>
536
+ { this . props . file . url ? (
537
+ < AssetPreview url = { this . props . file . url } name = { this . props . file . name } />
538
+ ) : null }
535
539
< EditorAccessibility lintMessages = { this . props . lintMessages } />
536
540
</ section >
537
541
) ;
You can’t perform that action at this time.
0 commit comments