Skip to content

Commit 3855903

Browse files
more refactoring, working on types now
1 parent e488a96 commit 3855903

File tree

107 files changed

+1360
-1422
lines changed

Some content is hidden

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

107 files changed

+1360
-1422
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const VSCode: React.FunctionComponent = () => {
2121
const rootEl = containerEl.current;
2222
const mainContainer = effects.vscode.getEditorElement(
2323
(modulePath: string) => {
24-
const template = getTemplate(state.editor.currentSandbox.template);
24+
const template = getTemplate(state.editor.sandbox.template);
2525
const config = template.configurationFiles[modulePath];
2626

2727
const ui = config && getUI(config.type);
@@ -36,9 +36,9 @@ export const VSCode: React.FunctionComponent = () => {
3636
actions.editor.codeChanged({ code, moduleShortid })
3737
}
3838
// Copy the object, we don't want mutations in the component
39-
currentModule={json(state.editor.currentModule)}
39+
currentModule={json(state.editor.sandbox.currentModule)}
4040
config={config}
41-
sandbox={state.editor.currentSandbox}
41+
sandbox={state.editor.sandbox}
4242
{...(extraProps as any)}
4343
/>
4444
</ThemeProvider>,
@@ -60,9 +60,10 @@ export const VSCode: React.FunctionComponent = () => {
6060
}, [
6161
actions.editor,
6262
effects.vscode,
63-
state.editor.currentModule,
64-
state.editor.currentSandbox,
65-
state.editor.currentSandbox.template,
63+
state.editor.sandbox.currentModule,
64+
state.editor.sandbox,
65+
state.editor.sandbox.template,
66+
state.editor.sandbox.currentModule,
6667
]);
6768

6869
return (

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,22 +224,22 @@ export const refetchSandboxInfo: AsyncAction = async ({
224224
effects,
225225
state,
226226
}) => {
227-
const sandbox = state.editor.currentSandbox;
227+
const sandbox = state.editor.sandbox;
228228

229229
if (!sandbox?.id) {
230230
return;
231231
}
232232

233233
const updatedSandbox = await effects.api.getSandbox(sandbox.id);
234234

235-
sandbox.collection = updatedSandbox.collection;
236-
sandbox.owned = updatedSandbox.owned;
237-
sandbox.userLiked = updatedSandbox.userLiked;
238-
sandbox.title = updatedSandbox.title;
239-
sandbox.team = updatedSandbox.team;
240-
sandbox.roomId = updatedSandbox.roomId;
235+
sandbox.setCollection(updatedSandbox.collection);
236+
sandbox.setOwned(updatedSandbox.owned);
237+
sandbox.setLiked(updatedSandbox.userLiked);
238+
sandbox.setTitle(updatedSandbox.title);
239+
sandbox.setTeam(updatedSandbox.team);
240+
sandbox.setRoomId(updatedSandbox.roomId);
241241

242-
await actions.editor.internal.initializeLiveSandbox(sandbox);
242+
await actions.editor.internal.initializeLiveSandbox();
243243
};
244244

245245
export const acceptTeamInvitation: Action<{ teamName: string }> = (

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { Module, PrettierConfig } from '@codesandbox/common/lib/types';
12
import prettify from 'app/utils/prettify';
2-
import { PrettierConfig, Module } from '@codesandbox/common/lib/types';
33

44
type Options = {
55
getPrettierConfig(): PrettierConfig;
6-
getCurrentModule(): Module;
6+
getCurrentModule(): Module | null;
77
};
88

99
let _options: Options;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export default {
1515

1616
const dispose = _reaction(
1717
state => [
18-
state.editor.isAllModulesSynced,
19-
state.editor.currentSandbox?.template,
18+
state.editor.sandbox.isAllModulesSynced,
19+
state.editor.sandbox?.template,
2020
state.preferences.settings.livePreviewEnabled,
2121
],
2222
([isAllModulesSynced, template, livePreviewEnabled]) => {

packages/app/src/app/overmind/factories.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ export const withOwnedSandbox = <T>(
7979
): AsyncAction<T> => async (context, payload) => {
8080
const { state, actions } = context;
8181

82-
const sandbox = state.editor.currentSandbox;
82+
const sandbox = state.editor.sandbox;
8383
if (sandbox) {
8484
if (
8585
typeof requiredPermission === 'undefined'
8686
? !sandbox.owned
87-
: !hasPermission(sandbox.authorization, requiredPermission)
87+
: !sandbox.hasPermission(requiredPermission)
8888
) {
8989
if (state.editor.isForkingSandbox) {
9090
return cancelAction(context, payload);
@@ -103,7 +103,7 @@ export const withOwnedSandbox = <T>(
103103
if (modalResponse === 'fork') {
104104
try {
105105
await actions.editor.internal.forkSandbox({
106-
sandboxId: state.editor.currentId!,
106+
sandboxId: state.editor.sandbox.id!,
107107
});
108108
} catch (e) {
109109
return cancelAction(context, payload);

packages/app/src/app/overmind/internalActions.ts

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import values from 'lodash-es/values';
1515

1616
import { ApiError } from './effects/api/apiFactory';
1717
import { createOptimisticModule } from './utils/common';
18-
import { defaultOpenedModule, mainModule } from './utils/main-module';
19-
import { parseConfigurations } from './utils/parse-configurations';
2018
import { Action, AsyncAction } from '.';
2119

2220
export const signIn: AsyncAction<{ useExtraScopes?: boolean }> = async (
@@ -176,25 +174,7 @@ export const setCurrentSandbox: AsyncAction<Sandbox> = async (
176174
{ state, effects, actions },
177175
sandbox
178176
) => {
179-
state.editor.sandboxes[sandbox.id] = sandbox;
180-
state.editor.currentId = sandbox.id;
181-
182-
let { currentModuleShortid } = state.editor;
183-
const parsedConfigs = parseConfigurations(sandbox);
184-
const main = mainModule(sandbox, parsedConfigs);
185-
186-
state.editor.mainModuleShortid = main.shortid;
187-
188-
// Only change the module shortid if it doesn't exist in the new sandbox
189-
// This can happen when a sandbox is opened that's different from the current
190-
// sandbox, with completely different files
191-
if (
192-
!sandbox.modules.find(module => module.shortid === currentModuleShortid)
193-
) {
194-
const defaultModule = defaultOpenedModule(sandbox, parsedConfigs);
195-
196-
currentModuleShortid = defaultModule.shortid;
197-
}
177+
state.editor.sandbox.set(sandbox);
198178

199179
const sandboxOptions = effects.router.getSandboxOptions();
200180

@@ -208,9 +188,10 @@ export const setCurrentSandbox: AsyncAction<Sandbox> = async (
208188
// @ts-ignore
209189
sandboxOptions.currentModule.directoryShortid
210190
);
211-
currentModuleShortid = resolvedModule
212-
? resolvedModule.shortid
213-
: currentModuleShortid;
191+
192+
if (resolvedModule) {
193+
state.editor.sandbox.setCurrentModule(resolvedModule);
194+
}
214195
} catch (error) {
215196
actions.internal.handleError({
216197
message: `Could not find module ${sandboxOptions.currentModule}`,
@@ -219,7 +200,6 @@ export const setCurrentSandbox: AsyncAction<Sandbox> = async (
219200
}
220201
}
221202

222-
state.editor.currentModuleShortid = currentModuleShortid;
223203
state.editor.workspaceConfigCode = '';
224204

225205
state.server.status = ServerStatus.INITIALIZING;
@@ -230,7 +210,7 @@ export const setCurrentSandbox: AsyncAction<Sandbox> = async (
230210

231211
const newTab: ModuleTab = {
232212
type: TabType.MODULE,
233-
moduleShortid: currentModuleShortid,
213+
moduleShortid: state.editor.sandbox.currentModule.shortid,
234214
dirty: true,
235215
};
236216

@@ -276,23 +256,23 @@ export const updateCurrentSandbox: AsyncAction<Sandbox> = async (
276256
{ state },
277257
sandbox
278258
) => {
279-
if (!state.editor.currentSandbox) {
259+
if (!state.editor.sandbox) {
280260
return;
281261
}
282262

283-
state.editor.currentSandbox.team = sandbox.team || null;
284-
state.editor.currentSandbox.collection = sandbox.collection;
285-
state.editor.currentSandbox.owned = sandbox.owned;
286-
state.editor.currentSandbox.userLiked = sandbox.userLiked;
287-
state.editor.currentSandbox.title = sandbox.title;
263+
state.editor.sandbox.setTeam(sandbox.team || null);
264+
state.editor.sandbox.setCollection(sandbox.collection);
265+
state.editor.sandbox.setOwned(sandbox.owned);
266+
state.editor.sandbox.setLiked(sandbox.userLiked);
267+
state.editor.sandbox.setTitle(sandbox.title);
288268
};
289269

290270
export const ensurePackageJSON: AsyncAction = async ({
291271
state,
292272
actions,
293273
effects,
294274
}) => {
295-
const sandbox = state.editor.currentSandbox;
275+
const sandbox = state.editor.sandbox;
296276
if (!sandbox) {
297277
return;
298278
}
@@ -306,7 +286,7 @@ export const ensurePackageJSON: AsyncAction = async ({
306286
const optimisticModule = createOptimisticModule({
307287
id: optimisticId,
308288
title: 'package.json',
309-
code: generatePackageJsonFromSandbox(sandbox),
289+
code: generatePackageJsonFromSandbox(sandbox.get()),
310290
path: '/package.json',
311291
});
312292

@@ -329,7 +309,9 @@ export const ensurePackageJSON: AsyncAction = async ({
329309
module.shortid = updatedModule.shortid;
330310
} catch (error) {
331311
sandbox.modules.splice(sandbox.modules.indexOf(module), 1);
332-
state.editor.modulesByPath = effects.vscode.sandboxFsSync.create(sandbox);
312+
state.editor.modulesByPath = effects.vscode.sandboxFsSync.create(
313+
sandbox.get()
314+
);
333315
actions.internal.handleError({
334316
message: 'Could not add package.json file',
335317
error,
@@ -339,15 +321,15 @@ export const ensurePackageJSON: AsyncAction = async ({
339321
};
340322

341323
export const closeTabByIndex: Action<number> = ({ state }, tabIndex) => {
342-
const { currentModule } = state.editor;
324+
const { currentModule } = state.editor.sandbox;
343325
const tabs = state.editor.tabs as ModuleTab[];
344326
const isActiveTab = currentModule.shortid === tabs[tabIndex].moduleShortid;
345327

346328
if (isActiveTab) {
347329
const newTab = tabIndex > 0 ? tabs[tabIndex - 1] : tabs[tabIndex + 1];
348330

349331
if (newTab) {
350-
state.editor.currentModuleShortid = newTab.moduleShortid;
332+
currentModule.shortid = newTab.moduleShortid;
351333
}
352334
}
353335

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const deployWithNetlify: AsyncAction = async ({
1818
actions,
1919
state,
2020
}) => {
21-
const sandbox = state.editor.currentSandbox;
21+
const sandbox = state.editor.sandbox;
2222

2323
state.deployment.deploying = true;
2424
state.deployment.netlifyLogs = null;
@@ -50,14 +50,14 @@ export const deployWithNetlify: AsyncAction = async ({
5050
};
5151

5252
export const getNetlifyDeploys: AsyncAction = async ({ state, effects }) => {
53-
const sandbox = state.editor.currentSandbox;
53+
const sandbox = state.editor.sandbox;
5454

5555
try {
5656
state.deployment.netlifyClaimUrl = await effects.netlify.claimSite(
57-
sandbox.getId()
57+
sandbox.id
5858
);
5959
state.deployment.netlifySite = await effects.netlify.getDeployments(
60-
sandbox.getId()
60+
sandbox.id
6161
);
6262
} catch (error) {
6363
state.deployment.netlifySite = null;
@@ -72,9 +72,7 @@ export const getDeploys: AsyncAction = async ({ state, actions, effects }) => {
7272
state.deployment.gettingDeploys = true;
7373

7474
try {
75-
const zeitConfig = effects.zeit.getConfig(
76-
state.editor.currentSandbox.get()
77-
);
75+
const zeitConfig = effects.zeit.getConfig(state.editor.sandbox.get());
7876

7977
state.deployment.hasAlias = !!zeitConfig.alias;
8078
if (zeitConfig.name) {
@@ -97,7 +95,7 @@ export const deployClicked: AsyncAction = async ({
9795
effects,
9896
actions,
9997
}) => {
100-
const sandbox = state.editor.currentSandbox;
98+
const sandbox = state.editor.sandbox;
10199

102100
try {
103101
state.deployment.deploying = true;
@@ -192,7 +190,7 @@ export const aliasDeployment: AsyncAction<string> = async (
192190
{ state, effects, actions },
193191
id
194192
) => {
195-
const zeitConfig = effects.zeit.getConfig(state.editor.currentSandbox.get());
193+
const zeitConfig = effects.zeit.getConfig(state.editor.sandbox.get());
196194

197195
try {
198196
const url = await effects.zeit.aliasDeployment(id, zeitConfig);

0 commit comments

Comments
 (0)