From a92c9a2cf5a121921b25af548742f071824513d0 Mon Sep 17 00:00:00 2001 From: Oliver Foster Date: Wed, 12 Jun 2024 12:47:45 +0100 Subject: [PATCH 1/2] Fix: Ensure user answers are correctly restored (fixes #56) --- js/BranchingSet.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/js/BranchingSet.js b/js/BranchingSet.js index ea65713..8e96c4f 100644 --- a/js/BranchingSet.js +++ b/js/BranchingSet.js @@ -224,10 +224,15 @@ export default class BranchingSet { if (isAnyPartRestored) { // Make sure to explicitly set the block to complete if complete // This helps trickle setup locking correctly - const areAllDescendantsComplete = cloned.getAllDescendantModels(true).every(model => model.get('_isComplete')); + const allDescendantsModels = cloned.getAllDescendantModels(true); + const areAllDescendantsComplete = allDescendantsModels.every(model => model.get('_isComplete')); if (areAllDescendantsComplete) { cloned.setCompletionStatus(); } + // Try to restore user answers on all questions + allDescendantsModels + .filter(model => model.isTypeGroup('question')) + .forEach(model => model?.restoreUserAnswers?.()); } if (shouldSave) { this.saveNextModel(nextModel); From 0feb6708de707da78340e28fd9a702db3ac0d78c Mon Sep 17 00:00:00 2001 From: Oliver Foster Date: Wed, 12 Jun 2024 21:59:19 +0100 Subject: [PATCH 2/2] Remove unnecessary optional chaining --- js/BranchingSet.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/BranchingSet.js b/js/BranchingSet.js index 8e96c4f..402d08e 100644 --- a/js/BranchingSet.js +++ b/js/BranchingSet.js @@ -232,7 +232,7 @@ export default class BranchingSet { // Try to restore user answers on all questions allDescendantsModels .filter(model => model.isTypeGroup('question')) - .forEach(model => model?.restoreUserAnswers?.()); + .forEach(model => model.restoreUserAnswers()); } if (shouldSave) { this.saveNextModel(nextModel);