Skip to content

Commit de1dc37

Browse files
no type issues, woop woop
1 parent 3855903 commit de1dc37

File tree

10 files changed

+59
-37
lines changed

10 files changed

+59
-37
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export const refetchSandboxInfo: AsyncAction = async ({
235235
sandbox.setCollection(updatedSandbox.collection);
236236
sandbox.setOwned(updatedSandbox.owned);
237237
sandbox.setLiked(updatedSandbox.userLiked);
238-
sandbox.setTitle(updatedSandbox.title);
238+
sandbox.setTitle(updatedSandbox.title || '');
239239
sandbox.setTeam(updatedSandbox.team);
240240
sandbox.setRoomId(updatedSandbox.roomId);
241241

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default {
1717
title,
1818
() => code,
1919
_options.getPrettierConfig(),
20-
() => _options.getCurrentModule().id === moduleId
20+
() => _options.getCurrentModule()?.id === moduleId
2121
);
2222
},
2323
};

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export const setCurrentSandbox: AsyncAction<Sandbox> = async (
210210

211211
const newTab: ModuleTab = {
212212
type: TabType.MODULE,
213-
moduleShortid: state.editor.sandbox.currentModule.shortid,
213+
moduleShortid: state.editor.sandbox.currentModule?.shortid ?? null,
214214
dirty: true,
215215
};
216216

@@ -260,8 +260,14 @@ export const updateCurrentSandbox: AsyncAction<Sandbox> = async (
260260
return;
261261
}
262262

263-
state.editor.sandbox.setTeam(sandbox.team || null);
264-
state.editor.sandbox.setCollection(sandbox.collection);
263+
if (sandbox.team) {
264+
state.editor.sandbox.setTeam(sandbox.team);
265+
}
266+
267+
if (sandbox.collection) {
268+
state.editor.sandbox.setCollection(sandbox.collection);
269+
}
270+
265271
state.editor.sandbox.setOwned(sandbox.owned);
266272
state.editor.sandbox.setLiked(sandbox.userLiked);
267273
state.editor.sandbox.setTitle(sandbox.title);
@@ -321,15 +327,20 @@ export const ensurePackageJSON: AsyncAction = async ({
321327
};
322328

323329
export const closeTabByIndex: Action<number> = ({ state }, tabIndex) => {
324-
const { currentModule } = state.editor.sandbox;
330+
const sandbox = state.editor.sandbox;
325331
const tabs = state.editor.tabs as ModuleTab[];
326-
const isActiveTab = currentModule.shortid === tabs[tabIndex].moduleShortid;
332+
const isActiveTab =
333+
sandbox.currentModule?.shortid === tabs[tabIndex].moduleShortid;
327334

328335
if (isActiveTab) {
329336
const newTab = tabIndex > 0 ? tabs[tabIndex - 1] : tabs[tabIndex + 1];
330337

331-
if (newTab) {
332-
currentModule.shortid = newTab.moduleShortid;
338+
if (
339+
newTab &&
340+
newTab.moduleShortid &&
341+
sandbox.getModule(newTab.moduleShortid)
342+
) {
343+
sandbox.setCurrentModule(sandbox.getModule(newTab.moduleShortid)!);
333344
}
334345
}
335346

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ export const sandboxChanged: AsyncAction<{ id: string }> = withLoadApp<{
6666
}>(async ({ state, actions, effects }, { id }) => {
6767
// This happens when we fork. This can be avoided with state first routing
6868
if (state.editor.isForkingSandbox && state.editor.sandbox) {
69-
effects.vscode.openModule(state.editor.sandbox.currentModule);
69+
if (state.editor.sandbox.currentModule) {
70+
effects.vscode.openModule(state.editor.sandbox.currentModule);
71+
}
7072

7173
await actions.editor.internal.initializeLiveSandbox();
7274

@@ -142,7 +144,10 @@ export const sandboxChanged: AsyncAction<{ id: string }> = withLoadApp<{
142144
await effects.live.sendModuleStateSyncRequest();
143145
}
144146

145-
effects.vscode.openModule(sandbox.currentModule);
147+
if (sandbox.currentModule) {
148+
effects.vscode.openModule(sandbox.currentModule);
149+
}
150+
146151
effects.preview.executeCodeImmediately({ initialRender: true });
147152

148153
state.editor.isLoading = false;
@@ -251,7 +256,7 @@ export const codeChanged: Action<{
251256
});
252257

253258
if (
254-
!state.editor.sandbox.templateDefinition.isServer &&
259+
!state.editor.sandbox.templateDefinition?.isServer &&
255260
state.preferences.settings.livePreviewEnabled
256261
) {
257262
actions.editor.internal.updatePreviewCode();
@@ -377,14 +382,12 @@ export const moduleSelected: Action<
377382
| {
378383
// Id means it is coming from Explorer
379384
id: string;
380-
path?: undefined;
381385
}
382386
| {
383387
// Path means it is coming from VSCode
384-
id?: undefined;
385388
path: string;
386389
}
387-
> = ({ actions, effects, state }, { id, path }) => {
390+
> = ({ actions, effects, state }, payload) => {
388391
effects.analytics.track('Open File');
389392

390393
const sandbox = state.editor.sandbox;
@@ -394,11 +397,12 @@ export const moduleSelected: Action<
394397
}
395398

396399
try {
397-
const module = path
398-
? sandbox.getModuleByPath(path)
399-
: sandbox.getModuleById(id);
400+
const module =
401+
'path' in payload
402+
? sandbox.getModuleByPath(payload.path)
403+
: sandbox.getModuleById(payload.id);
400404

401-
if (sandbox.isCurrentModule(module)) {
405+
if (!module || sandbox.isCurrentModule(module)) {
402406
return;
403407
}
404408

@@ -447,7 +451,7 @@ export const moduleDoubleClicked: Action = ({ state, effects }) => {
447451
const tabs = state.editor.tabs as ModuleTab[];
448452
const tab = tabs.find(
449453
tabItem =>
450-
tabItem.moduleShortid === state.editor.sandbox.currentModule.shortid
454+
tabItem.moduleShortid === state.editor.sandbox.currentModule?.shortid
451455
);
452456

453457
if (tab) {
@@ -479,7 +483,7 @@ export const prettifyClicked: AsyncAction = async ({
479483
}) => {
480484
effects.analytics.track('Prettify Code');
481485
const module = state.editor.sandbox.currentModule;
482-
if (!module.id) {
486+
if (!module?.id) {
483487
return;
484488
}
485489
const newCode = await effects.prettyfier.prettify(
@@ -617,7 +621,7 @@ export const showEnvironmentVariablesNotification: AsyncAction = async ({
617621

618622
await actions.editor.fetchEnvironmentVariables();
619623

620-
const environmentVariables = sandbox.environmentVariables;
624+
const environmentVariables = sandbox.environmentVariables || {};
621625
const emptyVarCount = Object.keys(environmentVariables).filter(
622626
key => !environmentVariables[key]
623627
).length;

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ export const updateCurrentTemplate: AsyncAction = async ({
187187
'node') as TemplateType;
188188

189189
if (
190+
template &&
190191
newTemplate !== template.name &&
191192
template.isServer === getTemplateDefinition(newTemplate).isServer
192193
) {
@@ -297,7 +298,7 @@ export const forkSandbox: AsyncAction<{
297298
const sandbox = state.editor.sandbox;
298299
const template = sandbox.templateDefinition;
299300

300-
if (!state.isLoggedIn && template.isServer) {
301+
if (!state.isLoggedIn && template?.isServer) {
301302
effects.analytics.track('Show Server Fork Sign In Modal');
302303
actions.modalOpened({ modal: 'forkServerModal' });
303304

@@ -337,7 +338,7 @@ export const forkSandbox: AsyncAction<{
337338
);
338339
effects.preview.updateAddressbarUrl();
339340

340-
if (template.isServer) {
341+
if (template && template.isServer) {
341342
effects.preview.refresh();
342343
actions.server.startContainer(forkedSandbox);
343344
}
@@ -348,7 +349,7 @@ export const forkSandbox: AsyncAction<{
348349

349350
effects.notificationToast.success('Forked sandbox!');
350351

351-
if (template.isServer) {
352+
if (template && template.isServer) {
352353
actions.editor.showEnvironmentVariablesNotification();
353354
}
354355

packages/app/src/app/overmind/namespaces/editor/models/EditorSandbox.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,8 @@ export class EditorSandbox {
339339
this.currentSandbox.template = template;
340340
}
341341

342-
setTitle(title: string) {
343-
this.currentSandbox.title = title;
342+
setTitle(title: string | null) {
343+
this.currentSandbox.title = title || '';
344344
}
345345

346346
setDescription(description: string) {
@@ -375,15 +375,15 @@ export class EditorSandbox {
375375
this.currentSandbox.previewSecret = previewSecret;
376376
}
377377

378-
setTeam(team: { id: string; name: string }) {
378+
setTeam(team: { id: string; name: string } | null) {
379379
this.currentSandbox.team = team;
380380
}
381381

382-
setRoomId(roomId: string) {
382+
setRoomId(roomId: string | null) {
383383
this.currentSandbox.roomId = roomId;
384384
}
385385

386-
setCollection(collection: { path: string }) {
386+
setCollection(collection: { path: string } | null) {
387387
this.currentSandbox.collection = collection;
388388
}
389389

packages/app/src/app/overmind/namespaces/editor/state.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export const state: State = {
9191
return tabs.find(
9292
tab =>
9393
'moduleShortid' in tab &&
94-
tab.moduleShortid === currentSandbox.currentModule.shortid
94+
tab.moduleShortid === currentSandbox.currentModule?.shortid
9595
);
9696
},
9797
/**

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,9 @@ export const moduleDeleted: AsyncAction<{
642642
}
643643

644644
const removedModule = sandbox.removeModule(module);
645-
const wasCurrentModule = sandbox.currentModule.shortid === moduleShortid;
645+
const wasCurrentModule = sandbox.currentModule
646+
? sandbox.currentModule.shortid === moduleShortid
647+
: false;
646648

647649
effects.vscode.sandboxFsSync.unlink(
648650
state.editor.modulesByPath,

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ export const roomJoined: AsyncAction<{
5959
});
6060

6161
effects.live.sendModuleStateSyncRequest();
62-
effects.vscode.openModule(state.editor.sandbox.currentModule);
62+
if (state.editor.sandbox.currentModule) {
63+
effects.vscode.openModule(state.editor.sandbox.currentModule);
64+
}
6365
effects.preview.executeCodeImmediately({ initialRender: true });
6466
state.editor.isLoading = false;
6567
});
@@ -151,7 +153,7 @@ export const sendCurrentSelection: Action = ({ state, effects }) => {
151153

152154
if (state.live.isCurrentEditor) {
153155
const { liveUserId } = state.live;
154-
if (liveUserId) {
156+
if (liveUserId && state.editor.sandbox.currentModule) {
155157
effects.live.sendUserSelection(
156158
state.editor.sandbox.currentModule.shortid,
157159
liveUserId,
@@ -171,7 +173,7 @@ export const onSelectionChanged: Action<any> = (
171173

172174
if (state.live.isCurrentEditor) {
173175
const { liveUserId } = state.live;
174-
const moduleShortid = state.editor.sandbox.currentModule.shortid;
176+
const moduleShortid = state.editor.sandbox.currentModule?.shortid;
175177
if (!moduleShortid || !liveUserId) {
176178
return;
177179
}

packages/app/src/app/overmind/namespaces/live/liveMessageOperators.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export const onModuleUpdated: Operator<LiveMessage<{
222222
export const onModuleDeleted: Operator<LiveMessage<{
223223
moduleShortid: string;
224224
}>> = mutate(({ state, effects, actions }, { _isOwnMessage, data }) => {
225-
if (_isOwnMessage || !state.editor.sandbox) {
225+
if (_isOwnMessage) {
226226
return;
227227
}
228228
const sandbox = state.editor.sandbox;
@@ -233,7 +233,9 @@ export const onModuleDeleted: Operator<LiveMessage<{
233233
return;
234234
}
235235
const moduleIndex = state.editor.sandbox.modules.indexOf(removedModule);
236-
const wasCurrentModule = sandbox.currentModule.shortid === data.moduleShortid;
236+
const wasCurrentModule = sandbox.currentModule
237+
? sandbox.currentModule.shortid === data.moduleShortid
238+
: false;
237239

238240
state.editor.sandbox.modules.splice(moduleIndex, 1);
239241
effects.vscode.sandboxFsSync.unlink(

0 commit comments

Comments
 (0)