11import React from 'react' ;
2- import Preview from 'app/src/app/components/Preview' ;
32import { Spring , animated , Transition } from 'react-spring/renderprops' ;
43import { camelizeKeys } from 'humps' ;
54
5+ import Preview from '../Preview' ;
66import { profileUrl , protocolAndHost } from '../../utils/url-generator' ;
77import getIcon from '../../templates/icons' ;
8+ import { TemplateType } from '../../templates' ;
89
910import {
1011 Container ,
@@ -17,6 +18,7 @@ import {
1718 StyledStats ,
1819 SandboxPreviewImage ,
1920} from './elements' ;
21+ import { Sandbox } from '../../types' ;
2022
2123const SandboxIcon = ( { template } ) => {
2224 const Icon = getIcon ( template ) ;
@@ -28,14 +30,55 @@ const SandboxIcon = ({ template }) => {
2830 ) ;
2931} ;
3032
31- export default class FeaturedSandbox extends React . PureComponent {
32- state = {
33+ export type SandboxType = {
34+ id : string ;
35+ } ;
36+
37+ export type SingleSandboxProps = {
38+ sandbox : Sandbox ;
39+ } ;
40+
41+ export type MultipleSandboxProps = {
42+ featuredSandboxes : {
43+ title : string ;
44+ description : string ;
45+ sandboxId : string ;
46+ template : TemplateType ;
47+ } [ ] ;
48+ sandboxId : string ;
49+ } ;
50+
51+ export type FeaturedSandboxProps = ( SingleSandboxProps &
52+ MultipleSandboxProps ) & {
53+ title : string ;
54+ description : string ;
55+ height ?: number ;
56+ pickSandbox : (
57+ args : {
58+ id : string ;
59+ title : string ;
60+ description : string ;
61+ screenshotUrl : string ;
62+ }
63+ ) => void ;
64+ } ;
65+
66+ export type FeaturedSandboxState = {
67+ sandbox : Sandbox | undefined ;
68+ showPreview : boolean ;
69+ } ;
70+
71+ export default class FeaturedSandbox extends React . PureComponent <
72+ FeaturedSandboxProps ,
73+ FeaturedSandboxState
74+ > {
75+ state : FeaturedSandboxState = {
3376 sandbox : undefined ,
3477 showPreview : false ,
3578 } ;
3679 fetchedSandboxes = { } ;
3780
38- fetchSandbox = id => {
81+ fetchSandbox = ( id : string ) => {
3982 if ( this . fetchedSandboxes [ id ] ) {
4083 return Promise . resolve ( this . fetchedSandboxes [ id ] ) ;
4184 }
@@ -60,7 +103,7 @@ export default class FeaturedSandbox extends React.PureComponent {
60103 componentDidMount ( ) {
61104 if ( this . props . sandboxId ) {
62105 this . fetchSandbox ( this . props . sandboxId ) . then ( sandbox => {
63- this . setState ( { sandbox } ) ;
106+ this . setState ( { sandbox : camelizeKeys ( sandbox ) as Sandbox } ) ;
64107 this . setUpPreview ( ) ;
65108 } ) ;
66109 } else {
@@ -74,7 +117,7 @@ export default class FeaturedSandbox extends React.PureComponent {
74117 } ) ;
75118 } ;
76119
77- async componentWillReceiveProps ( nextProps ) {
120+ async componentWillReceiveProps ( nextProps : FeaturedSandboxProps ) {
78121 if ( nextProps . sandboxId !== this . props . sandboxId ) {
79122 this . fetchSandbox ( nextProps . sandboxId ) . then ( sandbox => {
80123 this . setState ( { sandbox } ) ;
@@ -87,13 +130,14 @@ export default class FeaturedSandbox extends React.PureComponent {
87130 id : this . state . sandbox . id ,
88131 title : this . props . title ,
89132 description : this . props . description ,
90- screenshotUrl : this . state . sandbox . screenshot_url ,
133+ screenshotUrl : this . state . sandbox . screenshotUrl ,
91134 } ) ;
92135 } ;
93136
94137 render ( ) {
95- const { sandbox = this . props . sandbox || null } = this . state ;
138+ const { sandbox = this . props . sandbox } = this . state ;
96139 const { title, description, height } = this . props ;
140+
97141 return (
98142 < Container height = { height } >
99143 < SandboxContainer role = "button" onClick = { this . toggleOpen } >
@@ -108,9 +152,9 @@ export default class FeaturedSandbox extends React.PureComponent {
108152 { style => (
109153 < StyledStats
110154 style = { style }
111- viewCount = { sandbox . view_count }
112- likeCount = { sandbox . like_count }
113- forkCount = { sandbox . fork_count }
155+ viewCount = { sandbox . viewCount }
156+ likeCount = { sandbox . likeCount }
157+ forkCount = { sandbox . forkCount }
114158 />
115159 ) }
116160 </ Spring >
@@ -129,7 +173,7 @@ export default class FeaturedSandbox extends React.PureComponent {
129173 < a href = { profileUrl ( sandbox . author . username ) } >
130174 < Author
131175 username = { sandbox . author . username }
132- avatarUrl = { sandbox . author . avatar_url }
176+ avatarUrl = { sandbox . author . avatarUrl }
133177 />
134178 </ a >
135179 ) }
@@ -156,7 +200,7 @@ export default class FeaturedSandbox extends React.PureComponent {
156200 height : '100%' ,
157201 width : '100%' ,
158202 backgroundColor : 'white' ,
159- backgroundImage : `url(${ sandbox && sandbox . screenshot_url } )` ,
203+ backgroundImage : `url(${ sandbox && sandbox . screenshotUrl } )` ,
160204 backgroundRepeat : 'no-repeat' ,
161205 backgroundPositionX : 'center' ,
162206 transform : 'scale(1.025, 1.025)' ,
@@ -168,7 +212,7 @@ export default class FeaturedSandbox extends React.PureComponent {
168212 </ div >
169213 ) : (
170214 < Transition
171- items = { this . state . showPreview }
215+ items = { this . state . showPreview as any }
172216 from = { { flex : 1 , opacity : 1 } }
173217 enter = { { opacity : 1 , flex : 1 } }
174218 leave = { {
@@ -187,11 +231,24 @@ export default class FeaturedSandbox extends React.PureComponent {
187231 ? style => (
188232 < animated . div style = { style } >
189233 < Preview
190- sandbox = { camelizeKeys ( sandbox ) }
191- settings = { { } }
192- template = { sandbox . template }
234+ sandbox = { sandbox }
235+ settings = { {
236+ autoCompleteEnabled : true ,
237+ autoDownloadTypes : false ,
238+ codeMirror : false ,
239+ clearConsoleEnabled : true ,
240+ fontSize : 15 ,
241+ lineHeight : 1.4 ,
242+ lintEnabled : false ,
243+ vimMode : false ,
244+ tabWidth : 2 ,
245+ enableLigatures : true ,
246+ forceRefresh : false ,
247+ experimentVSCode : true ,
248+ prettierConfig : false ,
249+ zenMode : true ,
250+ } }
193251 isInProjectView
194- noDelay
195252 />
196253 </ animated . div >
197254 )
@@ -212,7 +269,7 @@ export default class FeaturedSandbox extends React.PureComponent {
212269 width : '100%' ,
213270 backgroundColor : 'white' ,
214271 backgroundImage : `url(${ sandbox &&
215- sandbox . screenshot_url } )`,
272+ sandbox . screenshotUrl } )`,
216273 backgroundRepeat : 'no-repeat' ,
217274 backgroundPositionX : 'center' ,
218275 transform : 'scale(1.025, 1.025)' ,
0 commit comments