11// @flow
22import React from 'react' ;
33import styled from 'styled-components' ;
4- import { Prompt } from 'react-router-dom' ;
4+ import { Prompt , Switch , Route , Redirect } from 'react-router-dom' ;
55import { bindActionCreators } from 'redux' ;
66import { connect } from 'react-redux' ;
77import { preferencesSelector } from 'app/store/preferences/selectors' ;
@@ -31,6 +31,7 @@ type Props = {
3131 moduleActions : typeof moduleActionCreators ,
3232 sandboxActions : typeof sandboxActionCreators ,
3333 userActions : typeof userActionCreators ,
34+ resizing : boolean ,
3435} ;
3536
3637type State = {
@@ -40,7 +41,7 @@ type State = {
4041const FullSize = styled . div `
4142 height: 100%;
4243 width: 100%;
43- pointer-events: ${ props => props . inactive ? 'none' : 'all '} ;
44+ ${ props => props . inactive && 'pointer-events: none '} ;
4445` ;
4546
4647const mapStateToProps = state => ( {
@@ -100,6 +101,7 @@ class EditorPreview extends React.PureComponent {
100101 preferences,
101102 userActions,
102103 user,
104+ match,
103105 } = this . props ;
104106
105107 const { modules, directories } = sandbox ;
@@ -129,7 +131,13 @@ class EditorPreview extends React.PureComponent {
129131 ) ;
130132
131133 const PreviewPane = (
132- < FullSize inactive = { this . state . resizing } >
134+ < FullSize
135+ style = { {
136+ pointerEvents : this . state . resizing || this . props . resizing
137+ ? 'none'
138+ : 'all' ,
139+ } }
140+ >
133141 < Preview
134142 sandboxId = { sandbox . id }
135143 bundle = { sandbox . dependencyBundle }
@@ -146,20 +154,10 @@ class EditorPreview extends React.PureComponent {
146154 </ FullSize >
147155 ) ;
148156
149- const Both = (
150- < SplitPane
151- onDragStarted = { this . startResizing }
152- onDragFinished = { this . stopResizing }
153- split = "vertical"
154- defaultSize = "50%"
155- minSize = { 360 }
156- primary = "second"
157- paneStyle = { { height : '100%' } }
158- >
159- { EditorPane }
160- { PreviewPane }
161- </ SplitPane >
162- ) ;
157+ const editorEnabled = match . isExact ||
158+ location . pathname . endsWith ( '/editor' ) ;
159+ const previewEnabled = match . isExact ||
160+ location . pathname . endsWith ( '/fullscreen' ) ;
163161
164162 return (
165163 < FullSize >
@@ -173,10 +171,33 @@ class EditorPreview extends React.PureComponent {
173171 sandboxActions = { sandboxActions }
174172 userActions = { userActions }
175173 user = { user }
174+ match = { match }
176175 />
177- { sandbox . showEditor && ! sandbox . showPreview && EditorPane }
178- { ! sandbox . showEditor && sandbox . showPreview && PreviewPane }
179- { sandbox . showEditor && sandbox . showPreview && Both }
176+ < SplitPane
177+ onDragStarted = { this . startResizing }
178+ onDragFinished = { this . stopResizing }
179+ split = "vertical"
180+ defaultSize = "50%"
181+ minSize = { 360 }
182+ primary = "second"
183+ paneStyle = { { height : '100%' } }
184+ pane1Style = { { display : editorEnabled ? 'block' : 'none' } }
185+ pane2Style = { {
186+ display : previewEnabled ? 'block' : 'none' ,
187+ minWidth : location . pathname . endsWith ( '/fullscreen' )
188+ ? '100%'
189+ : 'inherit' ,
190+ } }
191+ >
192+ { EditorPane }
193+ { PreviewPane }
194+ </ SplitPane >
195+ < Switch >
196+ < Route path = { match . url } exact />
197+ < Route path = { `${ match . url } /fullscreen` } />
198+ < Route path = { `${ match . url } /editor` } />
199+ < Redirect to = { match . url } />
200+ </ Switch >
180201 </ FullSize >
181202 ) ;
182203 }
0 commit comments