Skip to content

Commit ea9beca

Browse files
Merge branch 'master' into vscodeeffect
2 parents 61075ec + 8c60188 commit ea9beca

File tree

39 files changed

+489
-164
lines changed

39 files changed

+489
-164
lines changed

.eslintrc

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,7 @@
2727
"import/no-cycle": "warn",
2828
"react/prop-types": 0,
2929
"arrow-parens": 0,
30-
"prefer-destructuring": [
31-
"error",
32-
{
33-
"VariableDeclarator": {
34-
"array": false,
35-
"object": true
36-
},
37-
"AssignmentExpression": {
38-
"array": false,
39-
"object": false
40-
}
41-
}
42-
],
30+
"prefer-destructuring": 0,
4331
"no-async-promise-executor": "warn",
4432
"import/prefer-default-export": 0,
4533
"class-methods-use-this": 0,

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@
8585
"husky": "^2.2.0",
8686
"lerna": "^3.16.4",
8787
"lint-staged": "^9.2.5",
88-
"prettier": "1.18.2",
88+
"prettier": "1.19.0",
8989
"pretty-quick": "^1.10.0",
90-
"typescript": "3.7.1-rc",
90+
"typescript": "3.7.2",
9191
"username": "^5.1.0"
9292
},
9393
"husky": {

packages/app/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157
"overmind": "^20.1.0-1572182984474",
158158
"overmind-devtools": "^19.0.0",
159159
"overmind-react": "^21.1.0-1572182984474",
160-
"phoenix": "^1.3.0",
160+
"phoenix": "^1.4.11",
161161
"postcss": "^6.0.9",
162162
"postcss-selector-parser": "^2.2.3",
163163
"posthtml": "^0.11.3",
@@ -309,7 +309,7 @@
309309
"terser": "^4.1.4",
310310
"terser-webpack-plugin": "^1.4.1",
311311
"thread-loader": "^2.1.2",
312-
"typescript": "3.7.1-rc",
312+
"typescript": "3.7.2",
313313
"url-loader": "1.0.1",
314314
"webpack": "^4.36.1",
315315
"webpack-bundle-analyzer": "^2.13.1",

packages/app/scripts/start.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const { staticAssets } = require('../config/build');
2020

2121
// Tools like Cloud9 rely on this.
2222
var DEFAULT_PORT = process.env.PORT || 3000;
23+
const PROXY_DOMAIN = 'https://codesandbox.io';
2324
var compiler;
2425
var handleCompile;
2526
var compileStart;
@@ -214,6 +215,7 @@ function addMiddleware(devServer, index) {
214215
rewrites: [{ from: /\/embed/, to: '/embed.html' }],
215216
})
216217
);
218+
let wsProxy;
217219
if (process.env.LOCAL_SERVER) {
218220
devServer.use(
219221
cors({
@@ -226,10 +228,21 @@ function addMiddleware(devServer, index) {
226228
credentials: true,
227229
})
228230
);
231+
wsProxy = proxy({
232+
target: PROXY_DOMAIN.replace('https', 'wss'),
233+
changeOrigin: true,
234+
ws: true,
235+
autoRewrite: true,
236+
protocolRewrite: true,
237+
onProxyReqWs(proxyReq, req, socket, options, head) {
238+
proxyReq.setHeader('Origin', PROXY_DOMAIN);
239+
},
240+
});
241+
devServer.use('/socket', wsProxy);
229242
devServer.use(
230243
'/api',
231244
proxy({
232-
target: 'https://codesandbox.io',
245+
target: PROXY_DOMAIN,
233246
changeOrigin: true,
234247
})
235248
);
@@ -246,6 +259,8 @@ function addMiddleware(devServer, index) {
246259
// Finally, by now we have certainly resolved the URL.
247260
// It may be /index.html, so let the dev server try serving it again.
248261
devServer.use(devServer.middleware);
262+
263+
return { wsProxy };
249264
}
250265

251266
function runDevServer(port, protocol, index) {
@@ -273,7 +288,7 @@ function runDevServer(port, protocol, index) {
273288
});
274289

275290
// Our custom middleware proxies requests to /index.html or a remote API.
276-
addMiddleware(devServer, index);
291+
const { wsProxy } = addMiddleware(devServer, index);
277292

278293
// Launch WebpackDevServer.
279294
devServer.listen(port, err => {
@@ -285,6 +300,10 @@ function runDevServer(port, protocol, index) {
285300
console.log(chalk.cyan('Starting the development server...'));
286301
openBrowser(port, protocol);
287302
});
303+
304+
if (wsProxy) {
305+
devServer.listeningApp.on('upgrade', wsProxy.upgrade);
306+
}
288307
}
289308

290309
function run(port) {

packages/app/src/app/overmind/effects/live/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ export default {
7575
},
7676
connect() {
7777
if (!_socket) {
78-
_socket = new Socket(`wss://${location.host}/socket`, {
78+
const protocol = process.env.LOCAL_SERVER ? 'ws' : 'wss';
79+
_socket = new Socket(`${protocol}://${location.host}/socket`, {
7980
params: {
8081
guardian_token: provideJwtToken(),
8182
},

packages/app/src/app/overmind/effects/zeit.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,31 @@ type Options = {
1212
getToken(): string;
1313
};
1414

15+
interface Object {
16+
[key: string]: string;
17+
}
18+
19+
interface ApiData {
20+
builds: Object[];
21+
config?: Object;
22+
deploymentType?: string;
23+
env?: Object;
24+
files: File[];
25+
forceNew?: boolean;
26+
name: string;
27+
public: boolean;
28+
regions: string[];
29+
routes: Object[];
30+
scope?: string;
31+
version: number;
32+
}
33+
34+
interface File {
35+
data: string;
36+
encoding?: string;
37+
file: string;
38+
}
39+
1540
export default (() => {
1641
let _options: Options;
1742

@@ -133,7 +158,7 @@ export default (() => {
133158
async function getApiData(contents: any, sandbox: Sandbox) {
134159
const template = getTemplate(sandbox.template);
135160

136-
let apiData: any = {
161+
let apiData: Partial<ApiData> = {
137162
files: [],
138163
};
139164
let packageJSON: any = {};
@@ -159,7 +184,7 @@ async function getApiData(contents: any, sandbox: Sandbox) {
159184
nowJSON = packageJSON.now;
160185
}
161186

162-
const nowDefaults: any = {
187+
const nowDefaults: Pick<ApiData, 'name' | 'public'> = {
163188
name: `csb-${sandbox.id}`,
164189
public: true,
165190
};
@@ -174,7 +199,7 @@ async function getApiData(contents: any, sandbox: Sandbox) {
174199
packageJSON.name = nowJSON.name || nowDefaults.name;
175200

176201
apiData.name = nowJSON.name || nowDefaults.name;
177-
apiData.deploymentType = nowJSON.type || nowDefaults.type;
202+
apiData.deploymentType = nowJSON.type;
178203
apiData.public = nowJSON.public || nowDefaults.public;
179204

180205
// if now v2 we need to tell now the version, builds and routes
@@ -217,7 +242,7 @@ async function getApiData(contents: any, sandbox: Sandbox) {
217242
// if person added some files but no package.json
218243
if (
219244
filePath === 'package.json' &&
220-
!apiData.files.find(f => f.name === 'package.json')
245+
!apiData.files.find(f => f.file === 'package.json')
221246
) {
222247
apiData.files.push({
223248
file: 'package.json',

packages/app/src/app/pages/Profile/Showcase/SandboxInfo/elements.js renamed to packages/app/src/app/pages/Profile/Showcase/SandboxInfo/elements.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import styled from 'styled-components';
21
import delayEffect from '@codesandbox/common/lib/utils/animation/delay-effect';
32
import { Link } from 'react-router-dom';
3+
import styled from 'styled-components';
4+
45
import { LikeHeart } from 'app/pages/common/LikeHeart';
56

67
export const Container = styled.div`
@@ -18,7 +19,6 @@ export const Container = styled.div`
1819
`;
1920

2021
export const Title = styled.h1`
21-
font-weight: 400;
2222
margin: 0;
2323
padding: 0;
2424
box-sizing: border-box;

packages/app/src/app/pages/Profile/Showcase/SandboxInfo/index.js renamed to packages/app/src/app/pages/Profile/Showcase/SandboxInfo/index.tsx

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
1-
import React from 'react';
1+
import Row from '@codesandbox/common/lib/components/flex/Row';
2+
import { Sandbox } from '@codesandbox/common/lib/types';
23
import { getSandboxName } from '@codesandbox/common/lib/utils/get-sandbox-name';
34
import { sandboxUrl } from '@codesandbox/common/lib/utils/url-generator';
4-
import Row from '@codesandbox/common/lib/components/flex/Row';
5+
import React, { FunctionComponent } from 'react';
6+
57
import { Stat } from 'app/components/Stat';
6-
import SvgButton from './play-button.svg';
8+
import { useOvermind } from 'app/overmind';
9+
710
import {
811
Container,
9-
Title,
10-
Like,
1112
Description,
12-
Stats,
13+
Like,
1314
PlayButtonContainer,
15+
Stats,
16+
Title,
1417
} from './elements';
18+
import SvgButton from './play-button.svg';
19+
20+
type Props = {
21+
sandbox: Sandbox;
22+
};
23+
export const SandboxInfo: FunctionComponent<Props> = ({ sandbox }) => {
24+
const {
25+
state: { isLoggedIn },
26+
} = useOvermind();
1527

16-
function SandboxInfo({ sandbox, isLoggedIn }) {
1728
return (
1829
<Container>
1930
<Row alignItems="center">
@@ -22,21 +33,24 @@ function SandboxInfo({ sandbox, isLoggedIn }) {
2233
{isLoggedIn ? <Like sandbox={sandbox} /> : null}
2334
</Title>
2435
</Row>
36+
2537
<Row alignItems="flex-start">
2638
<div style={{ flex: 6 }}>
2739
<Description>{sandbox.description}</Description>
2840
</div>
41+
2942
<Stats>
3043
<PlayButtonContainer to={sandboxUrl({ id: sandbox.id })}>
3144
<img alt="edit" src={SvgButton} />
3245
</PlayButtonContainer>
46+
3347
<Stat name="likes" count={sandbox.likeCount} />
48+
3449
<Stat name="views" count={sandbox.viewCount} />
50+
3551
<Stat name="forks" count={sandbox.forkCount} />
3652
</Stats>
3753
</Row>
3854
</Container>
3955
);
40-
}
41-
42-
export default SandboxInfo;
56+
};

packages/app/src/app/pages/Profile/Showcase/index.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
import React from 'react';
1+
import React, { FunctionComponent } from 'react';
22
import { useOvermind } from 'app/overmind';
33

44
import Column from '@codesandbox/common/lib/components/flex/Column';
55
import Centered from '@codesandbox/common/lib/components/flex/Centered';
66
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
77
import { Button } from '@codesandbox/common/lib/components/Button';
88

9-
import SandboxInfo from './SandboxInfo';
9+
import { SandboxInfo } from './SandboxInfo';
1010
import ShowcasePreview from '../../common/ShowcasePreview';
1111

1212
import { ErrorTitle } from './elements';
1313

14-
export const Showcase: React.FC<{}> = () => {
14+
export const Showcase: FunctionComponent = () => {
1515
const {
1616
state: {
1717
profile,
1818
profile: { isLoadingProfile },
1919
preferences: { settings },
20-
isLoggedIn,
2120
},
2221
actions: {
2322
profile: { selectSandboxClicked },
@@ -62,13 +61,15 @@ export const Showcase: React.FC<{}> = () => {
6261
</Button>
6362
)}
6463
</Margin>
64+
6565
<Margin top={2} style={{ width: '100%' }}>
6666
<Column alignItems="initial">
6767
<div style={{ flex: 2 }}>
6868
<ShowcasePreview sandbox={sandbox} settings={settings} />
6969
</div>
70+
7071
<div style={{ flex: 1 }}>
71-
<SandboxInfo sandbox={sandbox} isLoggedIn={isLoggedIn} />
72+
<SandboxInfo sandbox={sandbox} />
7273
</div>
7374
</Column>
7475
</Margin>

packages/app/src/embed/components/Actions/elements.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import styled from 'styled-components';
22
import css from '@styled-system/css';
33
import { HeartIconSVG, ReloadIconSVG, NewWindowIconSVG } from './icons';
44

5-
// TODO: Check if we still need previewVisible
65
export const Container = styled.div(props =>
76
css({
87
position: 'absolute',
@@ -16,7 +15,7 @@ export const Container = styled.div(props =>
1615
},
1716

1817
// 28 is the height of console
19-
bottom: props.isDragging ? -32 : props.previewVisible ? 28 + 16 : 16,
18+
bottom: props.isDragging ? -32 : props.offsetBottom ? 28 + 16 : 16,
2019
opacity: props.isDragging ? 0 : 1,
2120
transitionProperty: 'opacity, bottom',
2221
transitionDuration: theme =>

0 commit comments

Comments
 (0)