Skip to content

Commit f199b12

Browse files
christianalfoniCompuIves
authored andcommitted
Overmind refactor round 3: Run with Overmind (codesandbox#2308)
* moved PR code * Use localstorage for Overmind check and update Overmind * fix typing * fix types and executor on adding npm packages * fix tabs and changed modules on saving code * reactions and more editor namespace checks * several fixes * return object instead of null * Take a path on getState * more signals verified * fixed some issues * gone through profile, fixed other master related bugs as well * fix linting and typing * hide delete on liked sandboxes * more namespaces tested * preferences and other small fixes * netlify working now * Working on LIVE, still more to test * More live fixes etc * update overmind version * fix typing and linting issues * Update packages/app/src/app/overmind/factories.ts Co-Authored-By: Michaël De Boey <[email protected]> * bug fixes, more testing * Update packages/app/src/app/index.js Co-Authored-By: Michaël De Boey <[email protected]> * cleanup and type fix * add missing extensions * fixing general actions * fix updating payment details * fix server issues * Fix addedFileToSandbox * show overmind logo when active * Fixed some bugs * fix typing issue * Fix vscode import * Remove usage of useStore and useSignals * Fix linting issue * Add commmit script * Fixed joining live room * Fixed live issues * refactor * Fix creating module * Fix creating directory
1 parent 6645d71 commit f199b12

File tree

134 files changed

+2616
-1647
lines changed

Some content is hidden

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

134 files changed

+2616
-1647
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"url": "https://github.com/codesandbox/codesandbox-client"
99
},
1010
"scripts": {
11+
"commit": "concurrently \"yarn typecheck\" \"yarn lint\" && git commit -m",
1112
"build": "cross-env NODE_OPTIONS=\"--max-old-space-size=4096\" yarn build:deps && yarn build:prod",
1213
"build:prod": "cross-env NODE_OPTIONS=\"--max-old-space-size=4096\" lerna run build --scope homepage --stream && lerna run build --scope app --stream && lerna run copy-assets --scope app --stream",
1314
"build:embed": "lerna run build:embed --scope app --stream && gulp",

packages/app/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@
214214
"normalizr": "^3.2.3",
215215
"onigasm": "^2.2.1",
216216
"ot": "^0.0.15",
217-
"overmind": "^19.0.1",
217+
"overmind": "^19.1.1",
218218
"overmind-devtools": "^19.0.0",
219-
"overmind-react": "^19.0.0",
219+
"overmind-react": "^20.1.1",
220220
"phoenix": "^1.3.0",
221221
"postcss": "^6.0.9",
222222
"postcss-selector-parser": "^2.2.3",

packages/app/src/app/componentConnectors.ts

100644100755
Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,38 @@
1+
import { json } from 'overmind';
12
import { inject as mobxInject, observer as mobxObserver } from 'mobx-react';
23
import { observer as mobxHooksObserver } from 'mobx-react-lite';
34
import { connect } from './overmind';
45

5-
const isOvermind = location.search.includes('overmind=true');
6+
const isOvermind = localStorage.getItem('overmind') === 'true';
67

78
export const inject: any = isOvermind
89
? () => component => component
9-
: mobxInject;
10+
: (...injects) => mobxInject('reaction', ...injects);
1011

1112
export const observer: any = isOvermind ? connect : mobxObserver;
1213

1314
export const hooksObserver: any = isOvermind ? connect : mobxHooksObserver;
1415

1516
export const Observer = isOvermind
16-
? inject('store', 'signals')(
17-
connect(({ store, signals, children }: any) =>
18-
children({ store, signals })
19-
)
17+
? connect(({ store, signals, reaction, children }: any) =>
18+
children({ store, signals, reaction })
2019
)
2120
: inject('store', 'signals')(
22-
observer(({ store, signals, children }: any) =>
23-
children({ store, signals })
21+
observer(({ store, signals, reaction, children }: any) =>
22+
children({ store, signals, reaction })
2423
)
2524
);
25+
26+
export const clone = isOvermind
27+
? json
28+
: obj => {
29+
if (obj.toJSON) {
30+
return obj.toJSON();
31+
}
32+
33+
if (obj.toJS) {
34+
return obj.toJS();
35+
}
36+
37+
return obj;
38+
};

packages/app/src/app/components/CodeEditor/VSCode/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ import { getTextOperation } from '@codesandbox/common/lib/utils/diff';
2727
// @ts-ignore
2828
import LinterWorker from 'worker-loader?publicPath=/&name=monaco-linter.[hash:8].worker.js!../Monaco/workers/linter';
2929
/* eslint-enable import/no-webpack-loader-syntax */
30-
30+
import { clone } from 'app/componentConnectors';
3131
import eventToTransform from '../Monaco/event-to-transform';
3232
import MonacoEditorComponent, { EditorAPI } from './MonacoReactComponent';
3333
import { Container, GlobalStyles } from './elements';
3434
import getSettings from '../Monaco/settings';
3535

3636
import { Props, Editor } from '../types';
3737
import getMode from '../Monaco/mode';
38+
3839
import {
3940
lineAndColumnToIndex,
4041
indexToLineAndColumn,
@@ -698,7 +699,7 @@ export class VSCode extends React.Component<Props> implements Editor {
698699
};
699700

700701
applyOperations = (operations: { [moduleShortid: string]: any }) => {
701-
const operationsJSON = operations.toJSON();
702+
const operationsJSON = operations.toJSON ? operations.toJSON() : operations;
702703

703704
Object.keys(operationsJSON).forEach(moduleShortid => {
704705
const operation = TextOperation.fromJSON(operationsJSON[moduleShortid]);
@@ -1119,8 +1120,7 @@ export class VSCode extends React.Component<Props> implements Editor {
11191120
<Configuration
11201121
onChange={this.props.onChange}
11211122
// Copy the object, we don't want mutations in the component
1122-
// @ts-ignore
1123-
currentModule={currentModule.toJSON()}
1123+
currentModule={clone(currentModule)}
11241124
config={config}
11251125
sandbox={this.sandbox}
11261126
{...extraProps}

packages/app/src/app/components/SandboxList/SandboxList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ export const SandboxList: React.FC<ISandboxListProps> = ({
7373
<StatBody>{s.likeCount}</StatBody>
7474
<StatBody>{s.viewCount}</StatBody>
7575
<StatBody>{s.forkCount}</StatBody>
76-
{isCurrentUser && (
76+
{isCurrentUser && onDelete ? (
7777
<DeleteBody>
7878
<DeleteSandboxButton id={s.id} onDelete={onDelete} />
7979
</DeleteBody>
80-
)}
80+
) : null}
8181
</SandboxRow>
8282
);
8383
})}

packages/app/src/app/index.js

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { render } from 'react-dom';
33
import { ThemeProvider } from 'styled-components';
44
import { Router } from 'react-router-dom';
55
import { ApolloProvider } from 'react-apollo';
6+
import { reaction } from 'mobx';
67
import { ApolloProvider as HooksProvider } from '@apollo/react-hooks';
78
import { Provider } from 'mobx-react';
89
import _debug from '@codesandbox/common/lib/utils/debug';
@@ -33,7 +34,7 @@ import { Routes as App } from './pages';
3334
import { Provider as OvermindProvider } from './overmind/Provider';
3435
import './split-pane.css';
3536
import { getTypeFetcher } from './vscode/extensionHostWorker/common/type-downloader';
36-
37+
import overmindLogo from './overmind.png';
3738
import { vscode } from './vscode';
3839
import {
3940
initializeThemeCache,
@@ -123,7 +124,11 @@ async function boot(state, signals, overmind) {
123124
render(
124125
<Signals.Provider value={signals}>
125126
<Store.Provider value={state}>
126-
<Provider store={state} signals={signals}>
127+
<Provider
128+
store={state}
129+
signals={signals}
130+
reaction={(cbA, cbB) => reaction(() => cbA(state), cbB)}
131+
>
127132
<ApolloProvider client={client}>
128133
<OvermindProvider value={overmind}>
129134
<HooksProvider client={client}>
@@ -154,20 +159,51 @@ async function initialize() {
154159
let state = null;
155160
let overmind = null;
156161

157-
if (location.search.includes('overmind=true')) {
162+
window.useOvermind = useIt => {
163+
if (typeof useIt === 'undefined') {
164+
return localStorage.getItem('overmind');
165+
}
166+
167+
localStorage.setItem('overmind', JSON.stringify(useIt));
168+
location.reload(true);
169+
170+
return useIt;
171+
};
172+
173+
if (localStorage.getItem('overmind') === 'true') {
158174
await Promise.all([import('overmind'), import('./overmind')]).then(
159175
modules => {
160176
const createOvermind = modules[0].createOvermind;
161177
const config = modules[1].config;
162178

163179
overmind = createOvermind(config, {
164-
devtools: 'localhost:3032',
180+
devtools:
181+
window.opener && window.opener !== window && !window.chrome
182+
? false
183+
: 'localhost:3031',
184+
name: 'CodeSandbox',
165185
logProxies: true,
166186
});
167187

168-
getState = () => overmind.state;
188+
getState = path =>
189+
path
190+
? path.split('.').reduce((aggr, key) => aggr[key], overmind.state)
191+
: overmind.state;
169192
getSignal = path =>
170193
path.split('.').reduce((aggr, key) => aggr[key], overmind.actions);
194+
195+
const logoContainer = document.createElement('div');
196+
logoContainer.style.position = 'fixed';
197+
logoContainer.style.bottom = '30px';
198+
logoContainer.style.left = '10px';
199+
logoContainer.style.zIndex = '999999';
200+
logoContainer.style.width = '40px';
201+
logoContainer.style.height = '40px';
202+
logoContainer.style.borderRadius = '3px';
203+
logoContainer.style.backgroundImage = `url(${overmindLogo})`;
204+
logoContainer.style.backgroundSize = 'cover';
205+
logoContainer.style.backgroundSize = 'cover';
206+
document.body.appendChild(logoContainer);
171207
}
172208
);
173209
} else {
@@ -195,6 +231,9 @@ async function initialize() {
195231
getSignal = controller.getSignal.bind(controller);
196232
}
197233

234+
window.getState = getState;
235+
window.getSignal = getSignal;
236+
198237
// Configures BrowserFS to use the LocalStorage file system.
199238
window.BrowserFS.configure(
200239
{

packages/app/src/app/overmind.png

55.9 KB
Loading

packages/app/src/app/overmind/Provider.ts

100644100755
File mode changed.

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

100644100755
Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { Action, AsyncAction } from '.';
22
import * as internalActions from './internalActions';
33
import { withLoadApp } from './factories';
4-
import { NotificationType } from '@codesandbox/common/lib/utils/notifications';
4+
import {
5+
NotificationType,
6+
convertTypeToStatus,
7+
} from '@codesandbox/common/lib/utils/notifications';
58

69
export const internal = internalActions;
710

@@ -21,6 +24,29 @@ export const cliMounted: AsyncAction = withLoadApp(
2124
}
2225
);
2326

27+
export const notificationAdded: Action<{
28+
title: string;
29+
notificationType: NotificationType;
30+
timeAlive: number;
31+
}> = ({ effects }, { title, notificationType, timeAlive }) => {
32+
effects.notificationToast.add({
33+
message: title,
34+
status: convertTypeToStatus(notificationType),
35+
timeAlive: timeAlive * 1000,
36+
});
37+
};
38+
39+
export const notificationRemoved: Action<{
40+
id: number;
41+
}> = ({ state }, { id }) => {
42+
const notifications = state.notifications;
43+
const notificationToRemoveIndex = notifications.findIndex(
44+
notification => notification.id === id
45+
);
46+
47+
state.notifications.splice(notificationToRemoveIndex, 1);
48+
};
49+
2450
export const forceRender: Action = ({ state }) => {
2551
state.editor.forceRender++;
2652
};
@@ -135,7 +161,7 @@ export const requestAuthorisation: AsyncAction = async ({ actions }) => {
135161

136162
export const signInGithubClicked: AsyncAction = async ({ state, actions }) => {
137163
state.isLoadingGithub = true;
138-
await actions.internal.signIn({ useExtraScopes: false });
164+
await actions.internal.signIn({ useExtraScopes: true });
139165
state.isLoadingGithub = false;
140166
};
141167

@@ -200,9 +226,7 @@ export const refetchSandboxInfo: AsyncAction = async ({
200226
state.live.isTeam = Boolean(sandbox.team);
201227
}
202228

203-
await actions.live.internal.initialize();
229+
await actions.live.internal.initialize(sandbox.roomId);
204230
}
205-
} else {
206-
actions.files.internal.recoverFiles();
207231
}
208232
};

0 commit comments

Comments
 (0)