Skip to content

Commit 09c4bbd

Browse files
committed
Updating saving file
1 parent 1f36ca0 commit 09c4bbd

File tree

1 file changed

+39
-27
lines changed

1 file changed

+39
-27
lines changed

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

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -126,50 +126,62 @@ export const saveCode: AsyncAction<{
126126
}
127127

128128
try {
129+
let updatedModule: {
130+
updatedAt: string;
131+
insertedAt: string;
132+
code: string;
133+
isBinary: boolean;
134+
};
129135
if (state.user?.experiments.comments) {
130136
const {
131137
saved_code,
132138
updated_at,
133139
inserted_at,
134-
version,
135140
} = await effects.live.saveModule(module);
136-
module.savedCode = saved_code;
137-
module.updatedAt = updated_at;
138-
module.insertedAt = inserted_at;
139-
sandbox.version = version;
141+
142+
updatedModule = {
143+
code: saved_code,
144+
updatedAt: updated_at,
145+
insertedAt: inserted_at,
146+
isBinary: false,
147+
};
140148
} else {
141149
await effects.live.saveModule(module);
142-
const updatedModule = await effects.api.saveModuleCode(
150+
updatedModule = await effects.api.saveModuleCode(
143151
sandbox.id,
144152
module.shortid,
145153
code
146154
);
155+
}
147156

148-
module.insertedAt = updatedModule.insertedAt;
149-
module.updatedAt = updatedModule.updatedAt;
150-
module.isBinary = updatedModule.isBinary;
157+
module.insertedAt = updatedModule.insertedAt;
158+
module.updatedAt = updatedModule.updatedAt;
159+
module.isBinary = updatedModule.isBinary;
151160

152-
if (!effects.vscode.isModuleOpened(module)) {
153-
module.code = updatedModule.code;
154-
}
155-
const savedCode =
156-
updatedModule.code === module.code ? null : updatedModule.code;
161+
if (!effects.vscode.isModuleOpened(module)) {
162+
module.code = updatedModule.code;
163+
}
164+
const savedCode =
165+
updatedModule.code === module.code ? null : updatedModule.code;
157166

158-
module.savedCode = savedCode;
167+
module.savedCode = savedCode;
159168

160-
if (savedCode === null) {
161-
// If the savedCode is also module.code
162-
effects.moduleRecover.remove(sandbox.id, module);
163-
}
169+
if (savedCode === null) {
170+
// If the savedCode is also module.code
171+
effects.moduleRecover.remove(sandbox.id, module);
172+
}
164173

165-
if (state.live.isLive && state.live.isCurrentEditor) {
166-
setTimeout(() => {
167-
// Send the save event 50ms later so the operation can be sent first (the operation that says the
168-
// file difference created by VSCode due to the file watch event). If the other client gets the save before the operation,
169-
// the other client will also send an operation with the same difference resulting in a duplicate event.
170-
effects.live.sendModuleSaved(module);
171-
}, 50);
172-
}
174+
if (
175+
state.live.isLive &&
176+
state.live.isCurrentEditor &&
177+
!state.user?.experiments.comments
178+
) {
179+
setTimeout(() => {
180+
// Send the save event 50ms later so the operation can be sent first (the operation that says the
181+
// file difference created by VSCode due to the file watch event). If the other client gets the save before the operation,
182+
// the other client will also send an operation with the same difference resulting in a duplicate event.
183+
effects.live.sendModuleSaved(module);
184+
}, 50);
173185
}
174186

175187
effects.vscode.sandboxFsSync.writeFile(state.editor.modulesByPath, module);

0 commit comments

Comments
 (0)