Skip to content

Commit d71fca8

Browse files
committed
fix: improve project code update logic to handle unchanged algorithms
1 parent 277055e commit d71fca8

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

js/widgets/reflection.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,18 +286,23 @@ class ReflectionMatrix {
286286
console.log("No changes in code detected.");
287287
return; // No changes in code
288288
}
289+
289290
this.showTypingIndicator("Reading code");
290-
const data = await this.generateNewAlgorithm(this.projectAlgorithm, code);
291+
const data = await this.generateNewAlgorithm(code);
291292
this.hideTypingIndicator();
292293

293294
if (data && !data.error) {
294-
this.projectAlgorithm = data.algorithm; // update algorithm
295-
this.code = code;
295+
if (data.algorithm !== "unchanged") {
296+
this.projectAlgorithm = data.algorithm; // update algorithm
297+
this.code = code;
298+
} else {
299+
console.log("No changes in algorithm detected.");
300+
}
296301
this.botReplyDiv(data, false, false);
297-
this.activity.textMsg(_("Project code updated."), 3000);
298302
} else {
299303
this.activity.errorMsg(_(data.error), 3000);
300304
}
305+
301306
this.projectAlgorithm = data.algorithm;
302307
}
303308

@@ -329,13 +334,13 @@ class ReflectionMatrix {
329334
* @param {string} code - The new project code.
330335
* @returns {Promise<Object>} - The server response containing the updated algorithm.
331336
*/
332-
async generateNewAlgorithm(previousAlgorithm, code) {
337+
async generateNewAlgorithm(code) {
333338
try {
334339
const response = await fetch(`${this.PORT}/updatecode`, {
335340
method: "POST",
336341
headers: { "Content-Type": "application/json" },
337342
body: JSON.stringify({
338-
oldcode: previousAlgorithm,
343+
oldcode: this.code,
339344
newcode: code
340345
})
341346
});

0 commit comments

Comments
 (0)