@@ -3,21 +3,31 @@ import Centered from '@codesandbox/common/lib/components/flex/Centered';
33import Fullscreen from '@codesandbox/common/lib/components/flex/Fullscreen' ;
44import Padding from '@codesandbox/common/lib/components/spacing/Padding' ;
55import { getSandboxName } from '@codesandbox/common/lib/utils/get-sandbox-name' ;
6- import { inject , observer } from 'app/componentConnectors' ;
76import { Skeleton } from 'app/components/Skeleton' ;
87import { Title } from 'app/components/Title' ;
8+ import { useOvermind } from 'app/overmind' ;
99import { GithubIntegration } from 'app/pages/common/GithubIntegration' ;
1010import { Navigation } from 'app/pages/common/Navigation' ;
1111import { NotFound } from 'app/pages/common/NotFound' ;
1212import { QuickActions } from 'app/pages/Sandbox/QuickActions' ;
13- import React from 'react' ;
14- import Helmet from 'react-helmet' ;
13+ import React , { useEffect } from 'react' ;
14+ import { Helmet } from 'react-helmet' ;
1515import { Link } from 'react-router-dom' ;
1616
1717import Editor from './Editor' ;
1818
19- class SandboxPage extends React . Component {
20- UNSAFE_componentWillMount ( ) {
19+ interface Props {
20+ match : {
21+ params : {
22+ id : string ;
23+ } ;
24+ } ;
25+ }
26+
27+ export const Sandbox : React . FC < Props > = ( { match } ) => {
28+ const { state, actions } = useOvermind ( ) ;
29+
30+ useEffect ( ( ) => {
2131 if ( window . screen . availWidth < 800 ) {
2232 if ( ! document . location . search . includes ( 'from-embed' ) ) {
2333 const addedSign = document . location . search ? '&' : '?' ;
@@ -26,45 +36,26 @@ class SandboxPage extends React.Component {
2636 addedSign +
2737 'codemirror=1' ;
2838 } else {
29- this . props . signals . preferences . codeMirrorForced ( ) ;
39+ actions . preferences . codeMirrorForced ( ) ;
3040 }
3141 }
3242
33- this . fetchSandbox ( ) ;
34- }
35-
36- disconnectLive ( ) {
37- if ( this . props . store . live . isLive ) {
38- this . props . signals . live . onNavigateAway ( { } ) ;
39- }
40- }
41-
42- componentWillUnmount ( ) {
43- this . disconnectLive ( ) ;
44- this . props . signals . editor . onNavigateAway ( { } ) ;
45- }
46-
47- fetchSandbox = ( ) => {
48- const { id } = this . props . match . params ;
49-
50- this . props . signals . editor . sandboxChanged ( { id } ) ;
51- } ;
52-
53- componentDidUpdate ( prevProps ) {
54- if ( prevProps . match . params . id !== this . props . match . params . id ) {
55- this . disconnectLive ( ) ;
56- this . fetchSandbox ( ) ;
57- }
58- }
43+ actions . editor . sandboxChanged ( { id : match . params . id } ) ;
44+ } , [ actions . editor , actions . preferences , match . params , match . params . id ] ) ;
5945
60- getContent ( ) {
61- const { store } = this . props ;
46+ useEffect (
47+ ( ) => ( ) => {
48+ actions . live . onNavigateAway ( ) ;
49+ } ,
50+ [ actions . live ]
51+ ) ;
6252
63- const { hasLogIn } = store ;
53+ function getContent ( ) {
54+ const { hasLogIn } = state ;
6455
65- if ( store . editor . error ) {
66- const isGithub = this . props . match . params . id . includes ( 'github' ) ;
67- const hasPrivateAccess = store . user && store . user . integrations . github ;
56+ if ( state . editor . error ) {
57+ const isGithub = match . params . id . includes ( 'github' ) ;
58+ const hasPrivateAccess = state . user && state . user . integrations . github ;
6859
6960 return (
7061 < >
@@ -79,7 +70,7 @@ class SandboxPage extends React.Component {
7970 Something went wrong
8071 </ div >
8172 < Title style = { { fontSize : '1.25rem' , marginBottom : 0 } } >
82- { store . editor . error }
73+ { state . editor . error }
8374 </ Title >
8475 < br />
8576 < div style = { { display : 'flex' , maxWidth : 400 , width : '100%' } } >
@@ -113,11 +104,11 @@ class SandboxPage extends React.Component {
113104 ) ;
114105 }
115106
116- if ( store . editor . notFound ) {
107+ if ( state . editor . notFound ) {
117108 return < NotFound /> ;
118109 }
119110
120- if ( store . editor . isLoading || ! store . editor . currentSandbox ) {
111+ if ( state . editor . isLoading || ! state . editor . currentSandbox ) {
121112 return (
122113 < >
123114 < Skeleton
@@ -139,50 +130,44 @@ class SandboxPage extends React.Component {
139130 return null ;
140131 }
141132
142- render ( ) {
143- const { match, store } = this . props ;
144-
145- const content = this . getContent ( ) ;
146-
147- if ( content ) {
148- return (
149- < Fullscreen >
150- < Padding
151- style = { {
152- display : 'flex' ,
153- flexDirection : 'column' ,
154- width : '100vw' ,
155- height : '100vh' ,
156- } }
157- margin = { 1 }
158- >
159- { store . editor . isLoading ? null : (
160- < Navigation title = "Sandbox Editor" />
161- ) }
162- < Centered
163- style = { { flex : 1 , width : '100%' , height : '100%' } }
164- horizontal
165- vertical
166- >
167- { content }
168- </ Centered >
169- </ Padding >
170- </ Fullscreen >
171- ) ;
172- }
173-
174- const sandbox = store . editor . currentSandbox ;
133+ const content = getContent ( ) ;
175134
135+ if ( content ) {
176136 return (
177- < >
178- < Helmet >
179- < title > { getSandboxName ( sandbox ) } - CodeSandbox</ title >
180- </ Helmet >
181- < Editor match = { match } />
182- < QuickActions />
183- </ >
137+ < Fullscreen >
138+ < Padding
139+ style = { {
140+ display : 'flex' ,
141+ flexDirection : 'column' ,
142+ width : '100vw' ,
143+ height : '100vh' ,
144+ } }
145+ margin = { 1 }
146+ >
147+ { state . editor . isLoading ? null : (
148+ < Navigation title = "Sandbox Editor" />
149+ ) }
150+ < Centered
151+ style = { { flex : 1 , width : '100%' , height : '100%' } }
152+ horizontal
153+ vertical
154+ >
155+ { content }
156+ </ Centered >
157+ </ Padding >
158+ </ Fullscreen >
184159 ) ;
185160 }
186- }
187161
188- export default inject ( 'signals' , 'store' ) ( observer ( SandboxPage ) ) ;
162+ const sandbox = state . editor . currentSandbox ;
163+
164+ return (
165+ < >
166+ < Helmet >
167+ < title > { getSandboxName ( sandbox ) } - CodeSandbox</ title >
168+ </ Helmet >
169+ < Editor />
170+ < QuickActions />
171+ </ >
172+ ) ;
173+ } ;
0 commit comments