Skip to content

Commit 2b8d12d

Browse files
add missing modulesByPath updates related to live
1 parent e23e9a9 commit 2b8d12d

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,25 +130,28 @@ export const onModuleSaved: Operator<
130130
moduleShortid: data.moduleShortid,
131131
savedCode: data.savedCode,
132132
});
133+
134+
effects.vscode.fs.writeFile(state.editor.modulesByPath, module);
133135
});
134136

135137
export const onModuleCreated: Operator<
136138
LiveMessage<{
137139
module: Module;
138140
}>
139-
> = mutate(({ state }, { _isOwnMessage, data }) => {
141+
> = mutate(({ state, effects }, { _isOwnMessage, data }) => {
140142
if (_isOwnMessage) {
141143
return;
142144
}
143145
state.editor.currentSandbox.modules.push(data.module);
146+
effects.vscode.fs.writeFile(state.editor.modulesByPath, data.module);
144147
});
145148

146149
export const onModuleMassCreated: Operator<
147150
LiveMessage<{
148151
modules: Module[];
149152
directories: Directory[];
150153
}>
151-
> = mutate(({ state }, { _isOwnMessage, data }) => {
154+
> = mutate(({ state, effects }, { _isOwnMessage, data }) => {
152155
if (_isOwnMessage) {
153156
return;
154157
}
@@ -158,14 +161,18 @@ export const onModuleMassCreated: Operator<
158161
state.editor.currentSandbox.directories = state.editor.currentSandbox.directories.concat(
159162
data.directories
160163
);
164+
165+
state.editor.modulesByPath = effects.vscode.fs.create(
166+
state.editor.currentSandbox
167+
);
161168
});
162169

163170
export const onModuleUpdated: Operator<
164171
LiveMessage<{
165172
moduleShortid: string;
166173
module: Module;
167174
}>
168-
> = mutate(({ state }, { _isOwnMessage, data }) => {
175+
> = mutate(({ state, effects }, { _isOwnMessage, data }) => {
169176
if (_isOwnMessage) {
170177
return;
171178
}
@@ -178,6 +185,11 @@ export const onModuleUpdated: Operator<
178185
state.editor.sandboxes[sandbox.id].modules[moduleIndex],
179186
data.module
180187
);
188+
189+
effects.vscode.fs.writeFile(
190+
state.editor.modulesByPath,
191+
state.editor.sandboxes[sandbox.id].modules[moduleIndex]
192+
);
181193
});
182194

183195
export const onModuleDeleted: Operator<
@@ -198,12 +210,13 @@ export const onDirectoryCreated: Operator<
198210
LiveMessage<{
199211
module: Directory; // This is very weird?
200212
}>
201-
> = mutate(({ state }, { _isOwnMessage, data }) => {
213+
> = mutate(({ state, effects }, { _isOwnMessage, data }) => {
202214
if (_isOwnMessage) {
203215
return;
204216
}
205217
// Should this not be a directory?
206218
state.editor.currentSandbox.directories.push(data.module);
219+
effects.vscode.fs.mkdir(state.editor.modulesByPath, data.module);
207220
});
208221

209222
export const onDirectoryUpdated: Operator<
@@ -220,7 +233,10 @@ export const onDirectoryUpdated: Operator<
220233
directoryEntry => directoryEntry.shortid === data.directoryShortid
221234
);
222235

223-
state.editor.sandboxes[sandbox.id].directories[directoryIndex] = data.module;
236+
Object.assign(
237+
state.editor.sandboxes[sandbox.id].directories[directoryIndex],
238+
data.module
239+
);
224240
});
225241

226242
export const onDirectoryDeleted: Operator<
@@ -277,14 +293,6 @@ export const onUserSelection: Operator<
277293
color: json(user.color),
278294
},
279295
]);
280-
/*
281-
state.editor.pendingUserSelections.push({
282-
userId: userSelectionLiveUserId,
283-
name: user.username,
284-
selection,
285-
color: json(user.color),
286-
});
287-
*/
288296
}
289297
});
290298

0 commit comments

Comments
 (0)