From 18891bf3ff1cacec9c73e18aadd7d560bb7bfafb Mon Sep 17 00:00:00 2001 From: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Date: Thu, 7 Nov 2019 05:41:57 -0500 Subject: [PATCH] feat(curriculum): download solution as non-json text file (#37681) * feat: download solution as non-json text file * fix: added missing end of line character Co-Authored-By: Oliver Eyton-Williams --- .../Challenges/components/CompletionModal.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/client/src/templates/Challenges/components/CompletionModal.js b/client/src/templates/Challenges/components/CompletionModal.js index 0a46e361042..c5794dcf107 100644 --- a/client/src/templates/Challenges/components/CompletionModal.js +++ b/client/src/templates/Challenges/components/CompletionModal.js @@ -87,14 +87,14 @@ export class CompletionModal extends Component { if (Object.keys(files).length) { const filesForDownload = Object.keys(files) .map(key => files[key]) - .reduce( - (allFiles, { path, contents }) => ({ - ...allFiles, - [path]: contents - }), - {} - ); - const blob = new Blob([JSON.stringify(filesForDownload, null, 2)], { + .reduce((allFiles, { path, contents }) => { + const beforeText = `** start of ${path} **\n\n`; + const afterText = `\n\n** end of ${path} **\n\n`; + allFiles += + files.length > 1 ? beforeText + contents + afterText : contents; + return allFiles; + }, ''); + const blob = new Blob([filesForDownload], { type: 'text/json' }); newURL = URL.createObjectURL(blob); @@ -170,7 +170,7 @@ export class CompletionModal extends Component { bsSize='lg' bsStyle='primary' className='btn-invert' - download={`${dashedName}.json`} + download={`${dashedName}.txt`} href={this.state.downloadURL} > Download my solution