Skip to content

Commit aed3846

Browse files
author
Ives van Hoorne
committed
Remove URL based sizes now because of iframe history clash
1 parent 0f5803b commit aed3846

File tree

6 files changed

+67
-69
lines changed

6 files changed

+67
-69
lines changed

src/app/pages/Sandbox/Editor/Content/Header/index.js

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// @flow
22
import React from 'react';
33
import styled from 'styled-components';
4-
import { Link, Route } from 'react-router-dom';
54
import Save from 'react-icons/lib/md/save';
65
import Fork from 'react-icons/lib/go/repo-forked';
76
import Download from 'react-icons/lib/go/cloud-download';
@@ -18,12 +17,7 @@ import Tooltip from 'app/components/Tooltip';
1817
import Action from './Action';
1918
import UserView from './User';
2019
import FeedbackView from './FeedbackView';
21-
import {
22-
newSandboxUrl,
23-
sandboxUrl,
24-
editorSandbox,
25-
fullscreenSandbox,
26-
} from '../../../../../utils/url-generator';
20+
import { newSandboxUrl } from '../../../../../utils/url-generator';
2721

2822
const Container = styled.div`
2923
display: flex;
@@ -132,10 +126,24 @@ export default class Header extends React.PureComponent {
132126
}
133127
};
134128

129+
setEditorView = () => {
130+
const { sandbox, sandboxActions } = this.props;
131+
sandboxActions.setViewMode(sandbox.id, true, false);
132+
};
133+
134+
setMixedView = () => {
135+
const { sandbox, sandboxActions } = this.props;
136+
sandboxActions.setViewMode(sandbox.id, true, true);
137+
};
138+
139+
setPreviewView = () => {
140+
const { sandbox, sandboxActions } = this.props;
141+
sandboxActions.setViewMode(sandbox.id, false, true);
142+
};
143+
135144
render() {
136-
const { sandbox, userActions, user, match } = this.props;
145+
const { sandbox, userActions, user } = this.props;
137146
const canSave = sandbox.modules.some(m => m.isNotSynced);
138-
139147
return (
140148
<Container>
141149
<Left>
@@ -156,42 +164,29 @@ export default class Header extends React.PureComponent {
156164

157165
<Tooltips>
158166
<Tooltip message="Editor view">
159-
<Route
160-
path={`${match.url}/editor`}
161-
children={active => (
162-
<Link to={editorSandbox(sandbox)}>
163-
<ViewIcon active={active.match}>
164-
<EditorIcon />
165-
</ViewIcon>
166-
</Link>
167-
)}
168-
/>
167+
<ViewIcon
168+
onClick={this.setEditorView}
169+
active={sandbox.showEditor && !sandbox.showPreview}
170+
>
171+
<EditorIcon />
172+
</ViewIcon>
169173
</Tooltip>
170174
<Tooltip message="Split view">
171-
<Route
172-
path={`${match.url}/`}
173-
exact
174-
children={active => (
175-
<Link to={sandboxUrl(sandbox)}>
176-
<ViewIcon active={active.match}>
177-
<EditorIcon half />
178-
<PreviewIcon half />
179-
</ViewIcon>
180-
</Link>
181-
)}
182-
/>
175+
<ViewIcon
176+
onClick={this.setMixedView}
177+
active={sandbox.showEditor && sandbox.showPreview}
178+
>
179+
<EditorIcon half />
180+
<PreviewIcon half />
181+
</ViewIcon>
183182
</Tooltip>
184183
<Tooltip message="Preview view">
185-
<Route
186-
path={`${match.url}/fullscreen`}
187-
children={active => (
188-
<Link to={fullscreenSandbox(sandbox)}>
189-
<ViewIcon active={active.match}>
190-
<PreviewIcon />
191-
</ViewIcon>
192-
</Link>
193-
)}
194-
/>
184+
<ViewIcon
185+
onClick={this.setPreviewView}
186+
active={!sandbox.showEditor && sandbox.showPreview}
187+
>
188+
<PreviewIcon />
189+
</ViewIcon>
195190
</Tooltip>
196191
</Tooltips>
197192

src/app/pages/Sandbox/Editor/Content/index.js

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22
import React from 'react';
33
import styled from 'styled-components';
4-
import { Prompt, Switch, Route, Redirect } from 'react-router-dom';
4+
import { Prompt } from 'react-router-dom';
55
import { bindActionCreators } from 'redux';
66
import { connect } from 'react-redux';
77
import { preferencesSelector } from 'app/store/preferences/selectors';
@@ -31,7 +31,6 @@ type Props = {
3131
moduleActions: typeof moduleActionCreators,
3232
sandboxActions: typeof sandboxActionCreators,
3333
userActions: typeof userActionCreators,
34-
resizing: boolean,
3534
};
3635

3736
type State = {
@@ -41,7 +40,7 @@ type State = {
4140
const FullSize = styled.div`
4241
height: 100%;
4342
width: 100%;
44-
${props => props.inactive && 'pointer-events: none'};
43+
pointer-events: ${props => props.inactive ? 'none' : 'all'};
4544
`;
4645

4746
const mapStateToProps = state => ({
@@ -101,7 +100,6 @@ class EditorPreview extends React.PureComponent {
101100
preferences,
102101
userActions,
103102
user,
104-
match,
105103
} = this.props;
106104

107105
const { modules, directories } = sandbox;
@@ -131,13 +129,7 @@ class EditorPreview extends React.PureComponent {
131129
);
132130

133131
const PreviewPane = (
134-
<FullSize
135-
style={{
136-
pointerEvents: this.state.resizing || this.props.resizing
137-
? 'none'
138-
: 'all',
139-
}}
140-
>
132+
<FullSize inactive={this.state.resizing}>
141133
<Preview
142134
sandboxId={sandbox.id}
143135
bundle={sandbox.dependencyBundle}
@@ -154,19 +146,18 @@ class EditorPreview extends React.PureComponent {
154146
</FullSize>
155147
);
156148

157-
const editorEnabled = match.isExact ||
158-
location.pathname.endsWith('/editor');
159-
const previewEnabled = match.isExact ||
160-
location.pathname.endsWith('/fullscreen');
161-
162149
return (
163150
<FullSize>
151+
<Prompt
152+
when={notSynced}
153+
message={() =>
154+
'You have not saved this sandbox, are you sure you want to navigate away?'}
155+
/>
164156
<Header
165157
sandbox={sandbox}
166158
sandboxActions={sandboxActions}
167159
userActions={userActions}
168160
user={user}
169-
match={match}
170161
/>
171162
<SplitPane
172163
onDragStarted={this.startResizing}
@@ -176,23 +167,17 @@ class EditorPreview extends React.PureComponent {
176167
minSize={360}
177168
primary="second"
178169
paneStyle={{ height: '100%' }}
179-
pane1Style={{ display: editorEnabled ? 'block' : 'none' }}
170+
pane1Style={{ display: sandbox.showEditor ? 'block' : 'none' }}
180171
pane2Style={{
181-
display: previewEnabled ? 'block' : 'none',
182-
minWidth: location.pathname.endsWith('/fullscreen')
172+
display: sandbox.showPreview ? 'block' : 'none',
173+
minWidth: sandbox.showPreview && !sandbox.showEditor
183174
? '100%'
184175
: 'inherit',
185176
}}
186177
>
187178
{EditorPane}
188179
{PreviewPane}
189180
</SplitPane>
190-
<Switch>
191-
<Route path={match.url} exact />
192-
<Route path={`${match.url}/fullscreen`} />
193-
<Route path={`${match.url}/editor`} />
194-
<Redirect to={match.url} />
195-
</Switch>
196181
</FullSize>
197182
);
198183
}

src/app/store/entities/sandboxes/actions.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export const SET_EXTERNAL_RESOURCES = 'SET_EXTERNAL_RESOURCES';
8484
export const SET_CURRENT_MODULE = 'SET_CURRENT_MODULE';
8585
export const SET_BUNDLE = 'SET_BUNDLE';
8686
export const SET_PROJECT_VIEW = 'SET_PROJECT_VIEW';
87+
export const SET_VIEW_MODE = 'SET_VIEW_MODE';
8788
export const CREATE_ZIP = 'CREATE_ZIP';
8889

8990
const addModuleToSandbox = (id, moduleId) => ({
@@ -203,6 +204,13 @@ export default {
203204
}
204205
},
205206

207+
setViewMode: (id: string, showEditor: boolean, showPreview: boolean) => ({
208+
type: SET_VIEW_MODE,
209+
id,
210+
showEditor,
211+
showPreview,
212+
}),
213+
206214
setProjectView: (id: string, isInProjectView: boolean) => ({
207215
type: SET_PROJECT_VIEW,
208216
id,

src/app/store/entities/sandboxes/entity.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export type Sandbox = {
2626
error?: string,
2727
processing?: boolean,
2828
},
29+
showEditor: ?boolean,
30+
showPreview: ?boolean,
2931
author: User,
3032
forkedFromSandbox: ?{ title: string, id: string },
3133
};
@@ -42,6 +44,8 @@ export default new schema.Entity(
4244
processStrategy: value => ({
4345
...value,
4446
isInProjectView: true,
47+
showEditor: true,
48+
showPreview: true,
4549
}),
4650
}
4751
);

src/app/store/entities/sandboxes/reducer.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
FETCH_BUNDLE_API_ACTIONS,
1313
SET_SANDBOX_INFO,
1414
SET_PROJECT_VIEW,
15+
SET_VIEW_MODE,
1516
} from './actions';
1617

1718
import { SET_CURRENT_USER, SIGN_OUT } from '../../user/actions';
@@ -25,6 +26,12 @@ type Action = {
2526

2627
function singleSandboxReducer(sandbox, action: Action) {
2728
switch (action.type) {
29+
case SET_VIEW_MODE:
30+
return {
31+
...sandbox,
32+
showEditor: action.showEditor,
33+
showPreview: action.showPreview,
34+
};
2835
case SET_PROJECT_VIEW:
2936
return { ...sandbox, isInProjectView: action.isInProjectView };
3037
case SET_CURRENT_MODULE:
@@ -98,6 +105,7 @@ export default function reducer(state = initialState, action: Action) {
98105
case SET_BUNDLE:
99106
case SET_SANDBOX_INFO:
100107
case SET_PROJECT_VIEW:
108+
case SET_VIEW_MODE:
101109
if (state[action.id]) {
102110
return {
103111
...state,

src/app/utils/url-generator.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ export const protocolAndHost = () => `${location.protocol}//${host()}`;
66

77
export const sandboxUrl = (sandbox: { id: string }) => `/s/${sandbox.id}`;
88
export const newSandboxUrl = () => `/s/new`;
9-
export const fullscreenSandbox = sandbox => `${sandboxUrl(sandbox)}/fullscreen`;
10-
export const editorSandbox = sandbox => `${sandboxUrl(sandbox)}/editor`;
119

1210
export const frameUrl = (append: string = '') =>
1311
`${location.protocol}//sandbox.${host()}/${append}`;

0 commit comments

Comments
 (0)