From 1db6ef99ac75c32ad353970e9ec3b8ed84c828e7 Mon Sep 17 00:00:00 2001 From: Sam Engel Date: Wed, 8 May 2024 07:58:55 -0400 Subject: [PATCH] Use new clued entries function --- app/reducers/builderReducer.ts | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/app/reducers/builderReducer.ts b/app/reducers/builderReducer.ts index 82dd4073..1c086777 100644 --- a/app/reducers/builderReducer.ts +++ b/app/reducers/builderReducer.ts @@ -687,12 +687,31 @@ function _builderReducer( }; } if (isAddEnumerationsAction(action)) { + // Deep copy clues const clues = { ...state.clues }; - for (const [answer, answerClues] of Object.entries(clues)) { - clues[answer] = answerClues.map((clue) => - parseClueEnumeration(clue) == null ? `${clue} (${answer.length})` : clue - ); + for (const answer in clues) { + const answerClues = clues[answer]; + if (answerClues != null) { + clues[answer] = answerClues.slice(); + } } + // Modify only clues that have entries + forEachCluedEntry( + state.grid.sortedEntries, + state.grid.entries, + state.clues, + (_entry, clue, answer, clueIndex) => { + const answerClues = clues[answer]; + if ( + answerClues != null && + answerClues.length > clueIndex && + clue.trim().length > 0 && + parseClueEnumeration(clue) == null + ) { + answerClues[clueIndex] = `${clue} (${answer.length})`; + } + } + ); return { ...state, clues, cluesBackup: { ...state.clues } }; } if (isRestoreCluesAction(action)) {