From f3446daaaef7f8bacdb5801ad27568aaae043c16 Mon Sep 17 00:00:00 2001 From: abe <37171082+KravMaguy@users.noreply.github.com> Date: Thu, 22 Dec 2022 10:50:25 -0500 Subject: [PATCH] feat: mark user editable regions in help post (#48512) Co-authored-by: Naomi Carrigan Co-authored-by: Oliver Eyton-Williams Co-authored-by: kravmaguy Co-authored-by: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com> Closes https://github.com/freeCodeCamp/freeCodeCamp/issues/46411 --- .../Challenges/redux/create-question-epic.js | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/client/src/templates/Challenges/redux/create-question-epic.js b/client/src/templates/Challenges/redux/create-question-epic.js index e01f001147a..93ff05697b2 100644 --- a/client/src/templates/Challenges/redux/create-question-epic.js +++ b/client/src/templates/Challenges/redux/create-question-epic.js @@ -43,13 +43,36 @@ function createQuestionEpic(action$, state$, { window }) { ofType(actionTypes.createQuestion), tap(() => { const state = state$.value; - const challengeFiles = challengeFilesSelector(state); + let challengeFiles = challengeFilesSelector(state); const { title: challengeTitle, superBlock, block, helpCategory } = challengeMetaSelector(state); + if ( + challengeFiles?.some(file => file.editableRegionBoundaries.length > 0) + ) { + const editableRegionStrings = fileExtension => { + const startComment = fileExtension === 'html' ? '' : '*/'; + return `\n${startComment} User Editable Region ${endComment}\n`; + }; + + const filesWithEditableRegions = challengeFiles.map(file => { + const { contents, editableRegionBoundaries, ext } = file; + if (editableRegionBoundaries.length > 0) { + const comment = editableRegionStrings(ext); + const [start, end] = editableRegionBoundaries; + const lines = contents.split('\n'); + lines.splice(start, 0, comment); + lines.splice(end, 0, comment); + return { ...file, contents: lines.join('\n') }; + } + return file; + }); + challengeFiles = filesWithEditableRegions; + } const { navigator: { userAgent }, location: { pathname, origin }