Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 879daf3

Browse files
committed
Fix: The base class calls setLocalStorage. Revise this function for lp problems to support this.
1 parent ae4db0b commit 879daf3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

runestone/lp/js/lp.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class LP extends RunestoneBase {
145145
// Store the answer as a string, since this is what goes in to / comes out from the database. We have to translate this back to a data structure when restoring from the db or local storage.
146146
let code_snippets = this.textareasToData();
147147
this.setLocalStorage({
148-
answer: JSON.stringify({ code_snippets: code_snippets }),
148+
answer: { code_snippets: code_snippets },
149149
timestamp: new Date(),
150150
});
151151
// Store the answer that the server returns, which includes additional data (correct/incorrect, feedback from the build, etc.).
@@ -178,8 +178,6 @@ class LP extends RunestoneBase {
178178
}
179179
serverAnswer.answer.code_snippets = code_snippets;
180180
this.displayAnswer(serverAnswer);
181-
// JSON-encode the answer for storage.
182-
serverAnswer.answer = JSON.stringify(serverAnswer.answer);
183181
this.setLocalStorage(serverAnswer);
184182
}
185183

@@ -269,7 +267,10 @@ class LP extends RunestoneBase {
269267
}
270268

271269
setLocalStorage(data) {
272-
localStorage.setItem(this.localStorageKey(), JSON.stringify(data));
270+
// Make a shallow copy, so we can JSON-encode the code snippets (matching what comes from the server) without changing the original object.
271+
data_clone = object.assign({}, data);
272+
data_clone.answer = JSON.stringify(data.answer);
273+
localStorage.setItem(this.localStorageKey(), JSON.stringify(data_clone));
273274
}
274275
}
275276

0 commit comments

Comments
 (0)