Skip to content

Commit a00cddf

Browse files
Merge branch 'master' into vscodeeffect
2 parents bc611a4 + c549a8a commit a00cddf

File tree

93 files changed

+2625
-2355
lines changed

Some content is hidden

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

93 files changed

+2625
-2355
lines changed

packages/app/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@
150150
"normalizr": "^3.2.3",
151151
"onigasm": "^2.2.1",
152152
"ot": "^0.0.15",
153-
"overmind": "^19.1.1",
153+
"overmind": "^19.3.0-1569928101550",
154154
"overmind-devtools": "^19.0.0",
155-
"overmind-react": "^20.1.1",
155+
"overmind-react": "^20.3.0-1569928101550",
156156
"phoenix": "^1.3.0",
157157
"postcss": "^6.0.9",
158158
"postcss-selector-parser": "^2.2.3",

packages/app/src/app/components/CodeEditor/CodeMirror/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,13 @@ class CodemirrorEditor extends React.Component<Props, State> implements Editor {
197197
const showAutoComplete = cm => {
198198
if (this.server) {
199199
const filter = new RegExp('[.a-z_$]', 'i');
200+
201+
// TODO: look why one of these values is undefined
200202
if (
203+
cm &&
204+
cm.display &&
205+
cm.display.input &&
206+
cm.display.input.textarea &&
201207
cm.display.input.textarea.value &&
202208
cm.display.input.textarea.value.slice(-1).match(filter)
203209
) {

packages/app/src/app/components/ContextMenu/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,13 @@ export class ContextMenu extends React.PureComponent<Props, State> {
228228
style={{
229229
left: left
230230
? x
231-
: x - (typeof width === 'string' ? 0 : width),
231+
: x - (typeof width === 'string' ? 194 : width),
232232
top: down
233233
? y
234-
: y - (typeof height === 'string' ? 0 : height),
234+
: y -
235+
(typeof height === 'string'
236+
? items.length * 81
237+
: height),
235238
opacity,
236239
height,
237240
}}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,11 @@ export class DevTools extends React.PureComponent<Props, State> {
274274
event: React.MouseEvent & { clientX: number; clientY: number }
275275
) => {
276276
if (!this.state.mouseDown && typeof this.state.height === 'number') {
277+
const { clientY } = event;
277278
unFocus(document, window);
278279
// @ts-ignore
279280
this.setState(state => ({
280-
startY: event.clientY,
281+
startY: clientY,
281282
startHeight: state.height,
282283
mouseDown: true,
283284
}));

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export const sandboxPageMounted: AsyncAction = withLoadApp();
1717

1818
export const searchMounted: AsyncAction = withLoadApp();
1919

20+
export const codesadboxMounted: AsyncAction = withLoadApp();
21+
2022
export const cliMounted: AsyncAction = withLoadApp(
2123
async ({ state, actions }) => {
2224
if (state.user) {
@@ -60,7 +62,19 @@ export const connectionChanged: Action<boolean> = ({ state }, connected) => {
6062
state.connected = connected;
6163
};
6264

63-
export const modalOpened: Action<{ modal: string; message: string }> = (
65+
type ModalName =
66+
| 'deleteDeployment'
67+
| 'feedback'
68+
| 'forkServerModal'
69+
| 'liveSessionEnded'
70+
| 'moveSandbox'
71+
| 'netlifyLogs'
72+
| 'newSandbox'
73+
| 'preferences'
74+
| 'privacyServerWarning'
75+
| 'share'
76+
| 'signInForTemplates';
77+
export const modalOpened: Action<{ modal: ModalName; message?: string }> = (
6478
{ state, effects },
6579
{ modal, message }
6680
) => {
@@ -224,3 +238,21 @@ export const refetchSandboxInfo: AsyncAction = async ({
224238
await actions.editor.internal.initializeLiveSandbox(sandbox);
225239
}
226240
};
241+
242+
export const acceptTeamInvitation: Action<{ teamName: string }> = (
243+
{ effects },
244+
{ teamName }
245+
) => {
246+
effects.analytics.track('Team - Invitation Accepted', {});
247+
248+
effects.notificationToast.success(`Accepted invitation to ${teamName}`);
249+
};
250+
251+
export const rejectTeamInvitation: Action<{ teamName: string }> = (
252+
{ effects },
253+
{ teamName }
254+
) => {
255+
effects.analytics.track('Team - Invitation Accepted', {});
256+
257+
effects.notificationToast.success(`Rejected invitation to ${teamName}`);
258+
};

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

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1+
import { TemplateType } from '@codesandbox/common/lib/templates';
12
import {
23
CurrentUser,
4+
CustomTemplate,
35
Dependency,
4-
Sandbox,
5-
Module,
6-
GitChanges,
7-
EnvironmentVariable,
8-
PopularSandboxes,
9-
SandboxPick,
10-
PickedSandboxes,
11-
UploadedFilesInfo,
126
Directory,
13-
GitInfo,
7+
EnvironmentVariable,
8+
GitChanges,
149
GitCommit,
10+
GitInfo,
1511
GitPr,
12+
Module,
1613
PaymentDetails,
14+
PickedSandboxes,
15+
PopularSandboxes,
1716
Profile,
17+
Sandbox,
18+
SandboxPick,
19+
UploadedFilesInfo,
1820
UserSandbox,
19-
CustomTemplate,
2021
} from '@codesandbox/common/lib/types';
21-
import { TemplateType } from '@codesandbox/common/lib/templates';
2222
import { client } from 'app/graphql/client';
2323
import { LIST_TEMPLATES } from 'app/pages/Dashboard/queries';
24+
25+
import { transformSandbox } from '../utils/sandbox';
2426
import apiFactory, { Api, ApiConfig } from './apiFactory';
2527

2628
let api: Api;
@@ -64,21 +66,16 @@ export default {
6466
const sandbox = await api.get<Sandbox>(`/sandboxes/${id}`);
6567

6668
// We need to add client side properties for tracking
67-
return {
68-
...sandbox,
69-
modules: sandbox.modules.map(module => ({
70-
...module,
71-
savedCode: null,
72-
isNotSynced: false,
73-
})),
74-
};
75-
},
76-
forkSandbox(id: string, body?: unknown): Promise<Sandbox> {
69+
return transformSandbox(sandbox);
70+
},
71+
async forkSandbox(id: string, body?: unknown): Promise<Sandbox> {
7772
const url = id.includes('/')
7873
? `/sandboxes/fork/${id}`
7974
: `/sandboxes/${id}/fork`;
8075

81-
return api.post(url, body || {});
76+
const sandbox = await api.post<Sandbox>(url, body || {});
77+
78+
return transformSandbox(sandbox);
8279
},
8380
createModule(sandboxId: string, module: Module): Promise<Module> {
8481
return api.post(`/sandboxes/${sandboxId}/modules`, {

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

Lines changed: 47 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import { getAbsoluteDependencies } from '@codesandbox/common/lib/utils/dependencies';
2-
import { protocolAndHost } from '@codesandbox/common/lib/utils/url-generator';
3-
42
import { getGlobal } from '@codesandbox/common/lib/utils/global';
5-
import { Module } from '@codesandbox/common/lib/types';
3+
import { protocolAndHost } from '@codesandbox/common/lib/utils/url-generator';
4+
import { json } from 'overmind';
65

76
const global = getGlobal() as Window & { BrowserFS: any };
87

98
const fs = global.BrowserFS.BFSRequire('fs');
109
const SERVICE_URL = 'https://ata-fetcher.cloud/api/v5/typings';
1110

12-
let fileInterval;
1311
let lastMTime = new Date(0);
1412

1513
function sendTypes() {
@@ -101,81 +99,61 @@ async function syncDependencyTypings(
10199
}
102100
}
103101

104-
let getCurrentSandboxId;
105-
let getModulesByPath;
106-
107-
export default {
108-
initialize(options: {
109-
getCurrentSandboxId: () => string;
110-
getModulesByPath: () => {
111-
[path: string]: Module;
112-
};
113-
}) {
114-
getCurrentSandboxId = options.getCurrentSandboxId; // eslint-disable-line prefer-destructuring
115-
getModulesByPath = options.getModulesByPath; // eslint-disable-line prefer-destructuring
116-
},
117-
syncCurrentSandbox() {
118-
if (fileInterval) {
119-
clearInterval(fileInterval);
120-
}
102+
function sendFiles(modulesByPath) {
103+
global.postMessage(
104+
{
105+
$broadcast: true,
106+
$type: 'file-sync',
107+
$data: json(modulesByPath),
108+
},
109+
protocolAndHost()
110+
);
121111

122-
const sendFiles = () => {
123-
if (getCurrentSandboxId()) {
124-
const modulesByPath = getModulesByPath();
125-
126-
global.postMessage(
127-
{
128-
$broadcast: true,
129-
$type: 'file-sync',
130-
$data: modulesByPath,
131-
},
132-
protocolAndHost()
133-
);
112+
try {
113+
fs.stat('/sandbox/package.json', (packageJsonError, stat) => {
114+
if (packageJsonError) {
115+
return;
134116
}
135-
};
136-
137-
fileInterval = setInterval(() => {
138-
sendFiles();
139117

140-
try {
141-
fs.stat('/sandbox/package.json', (packageJsonError, stat) => {
142-
if (packageJsonError) {
143-
return;
118+
if (stat.mtime.toString() !== lastMTime.toString()) {
119+
lastMTime = stat.mtime;
120+
121+
fs.readFile(
122+
'/sandbox/package.json',
123+
async (packageJsonReadError, rv) => {
124+
if (packageJsonReadError) {
125+
console.error(packageJsonReadError);
126+
return;
127+
}
128+
129+
fs.stat('/sandbox/tsconfig.json', (tsConfigError, result) => {
130+
// If tsconfig exists we want to sync the types
131+
syncDependencyTypings(
132+
rv.toString(),
133+
Boolean(tsConfigError) || !result
134+
);
135+
});
144136
}
145-
146-
if (stat.mtime.toString() !== lastMTime.toString()) {
147-
lastMTime = stat.mtime;
148-
149-
fs.readFile(
150-
'/sandbox/package.json',
151-
async (packageJsonReadError, rv) => {
152-
if (packageJsonReadError) {
153-
console.error(packageJsonReadError);
154-
return;
155-
}
156-
157-
fs.stat('/sandbox/tsconfig.json', (tsConfigError, result) => {
158-
// If tsconfig exists we want to sync the types
159-
syncDependencyTypings(
160-
rv.toString(),
161-
Boolean(tsConfigError) || !result
162-
);
163-
});
164-
}
165-
);
166-
}
167-
});
168-
} catch (e) {
169-
// Do nothing
137+
);
170138
}
171-
}, 1000);
139+
});
140+
} catch (e) {
141+
// Do nothing
142+
}
143+
}
172144

173-
// eslint-disable-next-line
145+
export default {
146+
initialize(options: {
147+
onModulesByPathChange: (modulesByPath: any) => void;
148+
getModulesByPath: () => any;
149+
}) {
174150
self.addEventListener('message', evt => {
175151
if (evt.data.$type === 'request-data') {
176152
sendTypes();
177-
sendFiles();
153+
sendFiles(options.getModulesByPath());
178154
}
179155
});
156+
157+
options.onModulesByPathChange(sendFiles);
180158
},
181159
};

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from '@codesandbox/common/lib/types';
1313
import { getTextOperation } from '@codesandbox/common/lib/utils/diff';
1414
import clientsFactory from './clients';
15+
import { transformSandbox } from '../utils/sandbox';
1516

1617
type Options = {
1718
onApplyOperation(args: { moduleShortid: string; operation: any }): void;
@@ -107,9 +108,11 @@ export default {
107108
return new Promise((resolve, reject) => {
108109
channel
109110
.join()
110-
.receive('ok', resp =>
111-
resolve(camelizeKeys(resp) as JoinChannelResponse)
112-
)
111+
.receive('ok', resp => {
112+
const result = camelizeKeys(resp) as JoinChannelResponse;
113+
result.sandbox = transformSandbox(result.sandbox);
114+
resolve(result);
115+
})
113116
.receive('error', resp => reject(camelizeKeys(resp)));
114117
});
115118
},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default (() => {
4343
return response.data;
4444
},
4545
async deploy(file: string, sandbox: Sandbox): Promise<string> {
46-
const userId = _options.getUserId;
46+
const userId = _options.getUserId();
4747
const template = getTemplate(sandbox.template);
4848
const buildCommand = (name: string) => {
4949
if (name === 'styleguidist') {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Sandbox } from '@codesandbox/common/lib/types';
2+
3+
export function transformSandbox(sandbox: Sandbox) {
4+
// We need to add client side properties for tracking
5+
return {
6+
...sandbox,
7+
modules: sandbox.modules.map(module => ({
8+
...module,
9+
savedCode: null,
10+
isNotSynced: false,
11+
errors: [],
12+
corrections: [],
13+
type: 'file' as 'file',
14+
})),
15+
directories: sandbox.directories.map(directory => ({
16+
...directory,
17+
type: 'directory' as 'directory',
18+
})),
19+
};
20+
}

0 commit comments

Comments
 (0)