Skip to content

Commit 323215b

Browse files
authored
Merge pull request codesandbox#1 from codesandbox/pr-christianalfoni-2816
Broken import
2 parents ae990d4 + 8fb810e commit 323215b

File tree

42 files changed

+574
-418
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+574
-418
lines changed

packages/app/config/build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ const staticAssets = [
3333
from: isDev
3434
? 'standalone-packages/codesandbox-browserfs/build'
3535
: 'standalone-packages/codesandbox-browserfs/dist',
36-
to: 'static/browserfs4',
36+
to: 'static/browserfs5',
3737
},
3838
// For caching purposes
3939
{
4040
from: isDev
4141
? 'standalone-packages/codesandbox-browserfs/build'
4242
: 'standalone-packages/codesandbox-browserfs/dist',
43-
to: 'static/browserfs3',
43+
to: 'static/browserfs4',
4444
},
4545
];
4646

packages/app/src/app/components/CodeEditor/Monaco/workers/linter/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Linter from 'eslint/lib/linter';
33
import monkeypatch from './monkeypatch-babel-eslint';
44

55
self.importScripts(
6-
`${process.env.CODESANDBOX_HOST}/static/browserfs4/browserfs.min.js`
6+
`${process.env.CODESANDBOX_HOST}/static/browserfs5/browserfs.min.js`
77
);
88

99
/* eslint-disable global-require */

packages/app/src/app/components/Preview/DevTools/Terminal/index.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1+
import './styles.css';
2+
3+
import { listen } from 'codesandbox-api';
14
import React from 'react';
5+
import PlusIcon from 'react-icons/lib/md/add';
26
import { withTheme } from 'styled-components';
3-
import { listen } from 'codesandbox-api';
4-
57
import uuid from 'uuid';
6-
import PlusIcon from 'react-icons/lib/md/add';
7-
8-
import './styles.css';
98

109
import { Shell } from './Shell';
1110
import { TerminalComponent } from './Shell/Term';
1211
import { ShellTabs } from './ShellTabs';
13-
1412
import { ShellT, TerminalWithFit } from './types';
1513
import { DevToolProps } from '..';
1614

@@ -34,6 +32,7 @@ class DevToolTerminal extends React.Component<
3432
};
3533

3634
term: TerminalWithFit;
35+
messageQueue: any[];
3736
listener: () => void;
3837
node?: HTMLElement;
3938
timeout?: number;
@@ -46,9 +45,17 @@ class DevToolTerminal extends React.Component<
4645

4746
setTerminal = (terminal: TerminalWithFit) => {
4847
this.term = terminal;
48+
49+
this.messageQueue.forEach(this.handleMessage);
50+
this.messageQueue.length = 0;
4951
};
5052

5153
handleMessage = (data: any) => {
54+
if (!this.term) {
55+
this.messageQueue.push(data);
56+
return;
57+
}
58+
5259
if (data.type === 'terminal:message') {
5360
this.term.write(data.data);
5461

packages/app/src/app/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
</script>
4949
<!-- End Google Tag Manager -->
5050
<!-- <script async src="//cdn.headwayapp.co/widget.js"></script> -->
51-
<script src="<%= webpackConfig.output.publicPath %>static/browserfs4/browserfs<%=process.env.NODE_ENV
51+
<script src="<%= webpackConfig.output.publicPath %>static/browserfs5/browserfs<%=process.env.NODE_ENV
5252
=== 'development' ? '' : '.min'%>.js"
5353
type="text/javascript"></script>
5454

packages/app/src/app/overmind/actions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ type ModalName =
7373
| 'preferences'
7474
| 'privacyServerWarning'
7575
| 'share'
76+
| 'searchDependencies'
7677
| 'signInForTemplates';
7778
export const modalOpened: Action<{ modal: ModalName; message?: string }> = (
7879
{ state, effects },

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

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ import {
2828
transformModule,
2929
} from '../utils/sandbox';
3030
import apiFactory, { Api, ApiConfig } from './apiFactory';
31+
import {
32+
SandboxAPIResponse,
33+
IModuleAPIResponse,
34+
IDirectoryAPIResponse,
35+
} from './types';
3136

3237
let api: Api;
3338

@@ -67,7 +72,7 @@ export default {
6772
return api.get(`/dependencies/${name}@latest`);
6873
},
6974
async getSandbox(id: string): Promise<Sandbox> {
70-
const sandbox = await api.get<Sandbox>(`/sandboxes/${id}`);
75+
const sandbox = await api.get<SandboxAPIResponse>(`/sandboxes/${id}`);
7176

7277
// We need to add client side properties for tracking
7378
return transformSandbox(sandbox);
@@ -77,13 +82,13 @@ export default {
7782
? `/sandboxes/fork/${id}`
7883
: `/sandboxes/${id}/fork`;
7984

80-
const sandbox = await api.post<Sandbox>(url, body || {});
85+
const sandbox = await api.post<SandboxAPIResponse>(url, body || {});
8186

8287
return transformSandbox(sandbox);
8388
},
8489
createModule(sandboxId: string, module: Module): Promise<Module> {
8590
return api
86-
.post(`/sandboxes/${sandboxId}/modules`, {
91+
.post<IModuleAPIResponse>(`/sandboxes/${sandboxId}/modules`, {
8792
module: {
8893
title: module.title,
8994
directoryShortid: module.directoryShortid,
@@ -93,14 +98,19 @@ export default {
9398
})
9499
.then(transformModule);
95100
},
96-
deleteModule(sandboxId: string, moduleShortid: string): Promise<void> {
97-
return api.delete(`/sandboxes/${sandboxId}/modules/${moduleShortid}`);
101+
async deleteModule(sandboxId: string, moduleShortid: string): Promise<void> {
102+
await api.delete<IModuleAPIResponse>(
103+
`/sandboxes/${sandboxId}/modules/${moduleShortid}`
104+
);
98105
},
99106
saveModuleCode(sandboxId: string, module: Module): Promise<Module> {
100107
return api
101-
.put(`/sandboxes/${sandboxId}/modules/${module.shortid}`, {
102-
module: { code: module.code },
103-
})
108+
.put<IModuleAPIResponse>(
109+
`/sandboxes/${sandboxId}/modules/${module.shortid}`,
110+
{
111+
module: { code: module.code },
112+
}
113+
)
104114
.then(transformModule);
105115
},
106116
saveModules(sandboxId: string, modules: Module[]) {
@@ -131,14 +141,14 @@ export default {
131141
});
132142
},
133143
savePrivacy(sandboxId: string, privacy: 0 | 1 | 2) {
134-
return api.patch(`/sandboxes/${sandboxId}/privacy`, {
144+
return api.patch<SandboxAPIResponse>(`/sandboxes/${sandboxId}/privacy`, {
135145
sandbox: {
136146
privacy,
137147
},
138148
});
139149
},
140150
saveFrozen(sandboxId: string, isFrozen: boolean) {
141-
return api.put(`/sandboxes/${sandboxId}`, {
151+
return api.put<SandboxAPIResponse>(`/sandboxes/${sandboxId}`, {
142152
sandbox: {
143153
is_frozen: isFrozen,
144154
},
@@ -176,9 +186,12 @@ export default {
176186
);
177187
},
178188
saveModuleTitle(sandboxId: string, moduleShortid: string, title: string) {
179-
return api.put(`/sandboxes/${sandboxId}/modules/${moduleShortid}`, {
180-
module: { title },
181-
});
189+
return api.put<IModuleAPIResponse>(
190+
`/sandboxes/${sandboxId}/modules/${moduleShortid}`,
191+
{
192+
module: { title },
193+
}
194+
);
182195
},
183196
getPopularSandboxes(date: string): Promise<PopularSandboxes> {
184197
return api.get(`/sandboxes/popular?start_date=${date}`);
@@ -202,7 +215,7 @@ export default {
202215
title: string
203216
): Promise<Directory> {
204217
return api
205-
.post(`/sandboxes/${sandboxId}/directories`, {
218+
.post<IDirectoryAPIResponse>(`/sandboxes/${sandboxId}/directories`, {
206219
directory: {
207220
title,
208221
directoryShortid,
@@ -215,16 +228,19 @@ export default {
215228
moduleShortid: string,
216229
directoryShortid: string
217230
) {
218-
return api.put(`/sandboxes/${sandboxId}/modules/${moduleShortid}`, {
219-
module: { directoryShortid },
220-
});
231+
return api.put<IDirectoryAPIResponse>(
232+
`/sandboxes/${sandboxId}/modules/${moduleShortid}`,
233+
{
234+
module: { directoryShortid },
235+
}
236+
);
221237
},
222238
saveDirectoryDirectory(
223239
sandboxId: string,
224240
sourceDirectoryShortid: string,
225241
targetDirectoryShortId: string
226242
) {
227-
return api.put(
243+
return api.put<IDirectoryAPIResponse>(
228244
`/sandboxes/${sandboxId}/directories/${sourceDirectoryShortid}`,
229245
{
230246
directory: { directoryShortid: targetDirectoryShortId },
@@ -241,9 +257,12 @@ export default {
241257
directoryShortid: string,
242258
title: string
243259
) {
244-
return api.put(`/sandboxes/${sandboxId}/directories/${directoryShortid}`, {
245-
directory: { title },
246-
});
260+
return api.put<IDirectoryAPIResponse>(
261+
`/sandboxes/${sandboxId}/directories/${directoryShortid}`,
262+
{
263+
directory: { title },
264+
}
265+
);
247266
},
248267
getUploads(): Promise<UploadedFilesInfo> {
249268
return api.get('/users/current_user/uploads');
@@ -271,13 +290,14 @@ export default {
271290
modules,
272291
directories,
273292
})) as {
274-
modules: Module[];
275-
directories: Directory[];
293+
modules: IModuleAPIResponse[];
294+
directories: IDirectoryAPIResponse[];
276295
};
277296

278-
data.modules = data.modules.map(transformModule);
279-
data.directories = data.directories.map(transformDirectory);
280-
return data;
297+
return {
298+
modules: data.modules.map(transformModule),
299+
directories: data.directories.map(transformDirectory),
300+
};
281301
},
282302
createGit(
283303
sandboxId: string,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Sandbox } from '@codesandbox/common/lib/types';
2+
3+
export interface IModuleAPIResponse {
4+
id: string;
5+
shortid: string;
6+
code: string | null;
7+
directoryShortid: string | null;
8+
isBinary: boolean;
9+
sourceId: string;
10+
title: string;
11+
insertedAt: string;
12+
updatedAt: string;
13+
}
14+
15+
export interface IDirectoryAPIResponse {
16+
id: string;
17+
shortid: string;
18+
directoryShortid: string | null;
19+
sourceId: string;
20+
title: string;
21+
insertedAt: string;
22+
updatedAt: string;
23+
}
24+
25+
export type SandboxAPIResponse = Omit<Sandbox, 'environmentVariables'> & {
26+
modules: IModuleAPIResponse[];
27+
directories: IDirectoryAPIResponse[];
28+
};

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import {
77
Module,
88
Directory,
99
RoomInfo,
10-
Sandbox,
1110
LiveMessageEvent,
11+
Sandbox,
1212
} from '@codesandbox/common/lib/types';
1313
import { getTextOperation } from '@codesandbox/common/lib/utils/diff';
1414
import clientsFactory from './clients';
1515
import { transformSandbox } from '../utils/sandbox';
16+
import { SandboxAPIResponse } from '../api/types';
1617

1718
type Options = {
1819
onApplyOperation(args: { moduleShortid: string; operation: any }): void;
@@ -21,12 +22,16 @@ type Options = {
2122

2223
type JoinChannelResponse = {
2324
sandboxId: string;
24-
sandbox: Sandbox;
25+
sandbox: SandboxAPIResponse;
2526
moduleState: object;
2627
liveUserId: string;
2728
roomInfo: RoomInfo;
2829
};
2930

31+
type JoinChannelTransformedResponse = JoinChannelResponse & {
32+
sandbox: Sandbox;
33+
};
34+
3035
declare global {
3136
interface Window {
3237
socket: any;
@@ -102,16 +107,17 @@ export default {
102107
.receive('error', resp => reject(resp));
103108
});
104109
},
105-
joinChannel(roomId: string): Promise<JoinChannelResponse> {
110+
joinChannel(roomId: string): Promise<JoinChannelTransformedResponse> {
106111
channel = this.getSocket().channel(`live:${roomId}`, {});
107112

108113
return new Promise((resolve, reject) => {
109114
channel
110115
.join()
111116
.receive('ok', resp => {
112117
const result = camelizeKeys(resp) as JoinChannelResponse;
118+
// @ts-ignore
113119
result.sandbox = transformSandbox(result.sandbox);
114-
resolve(result);
120+
resolve(result as JoinChannelTransformedResponse);
115121
})
116122
.receive('error', resp => reject(camelizeKeys(resp)));
117123
});

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1+
import { Module } from '@codesandbox/common/lib/types';
2+
13
const getKey = (id, moduleShortid) => `recover:${id}:${moduleShortid}:code`;
24

35
export default {
4-
save(currentId, version, module, code, savedCode) {
6+
save(
7+
currentId: string,
8+
version: number,
9+
module: Module,
10+
code: string,
11+
savedCode: string | null
12+
) {
513
try {
614
localStorage.setItem(
715
getKey(currentId, module.shortid),
@@ -18,15 +26,15 @@ export default {
1826
}
1927
},
2028

21-
remove(currentId, module) {
29+
remove(currentId: string, module: Module) {
2230
try {
2331
localStorage.removeItem(getKey(currentId, module.shortid));
2432
} catch (e) {
2533
// Too bad
2634
}
2735
},
2836

29-
clearSandbox(currentId) {
37+
clearSandbox(currentId: string) {
3038
try {
3139
Object.keys(localStorage)
3240
.filter(key => key.startsWith(`recover:${currentId}`))
@@ -38,7 +46,7 @@ export default {
3846
}
3947
},
4048

41-
getRecoverList(currentId, modules) {
49+
getRecoverList(currentId: string, modules: Module[]) {
4250
const localKeys = Object.keys(localStorage).filter(key =>
4351
key.startsWith(`recover:${currentId}`)
4452
);

0 commit comments

Comments
 (0)