From 2952f9399d3cf2601aba4120f14030dccf102391 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Mon, 10 Jan 2022 23:02:30 +0100 Subject: [PATCH] fix(client): keep challengeFile order on update (#44722) * fix: keep challengeFile order on update * refactor: name variable challengeFile, not file Co-authored-by: Shaun Hamilton * fix: prettify Co-authored-by: Shaun Hamilton --- client/src/templates/Challenges/redux/index.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/client/src/templates/Challenges/redux/index.js b/client/src/templates/Challenges/redux/index.js index f21207b22a..28218d68df 100644 --- a/client/src/templates/Challenges/redux/index.js +++ b/client/src/templates/Challenges/redux/index.js @@ -231,13 +231,11 @@ export const reducer = handleActions( ); return { ...state, - challengeFiles: [ - ...state.challengeFiles.filter(x => x.fileKey !== fileKey), - { - ...state.challengeFiles.find(x => x.fileKey === fileKey), - ...updates - } - ] + challengeFiles: state.challengeFiles.map(challengeFile => + challengeFile.fileKey === fileKey + ? { ...challengeFile, ...updates } + : { ...challengeFile } + ) }; }, [actionTypes.storedCodeFound]: (state, { payload }) => ({