From 71c76696699ca32c27cb0cd4dd8adf9a4c668a04 Mon Sep 17 00:00:00 2001 From: Martin Krulis Date: Sat, 23 Jul 2022 18:54:31 +0200 Subject: [PATCH] Improving download filename of ZIP archive of solution source files. --- .../Solutions/SolutionDetail/SolutionDetail.js | 1 + .../Solutions/SolutionFiles/SolutionFiles.js | 3 +++ .../DownloadSolutionArchiveContainer.js | 17 ++++++++++++----- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/components/Solutions/SolutionDetail/SolutionDetail.js b/src/components/Solutions/SolutionDetail/SolutionDetail.js index b87f06c7c..51489b6d1 100644 --- a/src/components/Solutions/SolutionDetail/SolutionDetail.js +++ b/src/components/Solutions/SolutionDetail/SolutionDetail.js @@ -239,6 +239,7 @@ class SolutionDetail extends Component { const SolutionFiles = ({ solutionId, + attemptIndex, files, authorId, isReference = false, @@ -181,6 +182,7 @@ const SolutionFiles = ({ { - const name = toPlainAscii(`${user.name.lastName}-${user.name.firstName}`); - return `${name}_${solutionId}.zip`; +const solutionArchiveFileName = (solutionId, user, index = null) => { + const components = [user.name.lastName, user.name.firstName]; + if (index) { + components.push(String(index).padStart(3, '0')); + } + components.push(solutionId); + const name = toPlainAscii(components.join('_').replaceAll(' ', '-')); + return `${name}.zip`; }; const DownloadSolutionArchiveContainer = ({ @@ -50,6 +55,8 @@ const DownloadSolutionArchiveContainer = ({ ); DownloadSolutionArchiveContainer.propTypes = { + solutionId: PropTypes.string.isRequired, + attemptIndex: PropTypes.number, authorId: PropTypes.string.isRequired, isReference: PropTypes.bool, iconOnly: PropTypes.bool, @@ -64,10 +71,10 @@ export default connect( (state, { authorId }) => ({ authorUser: getUser(authorId)(state), }), - (dispatch, { solutionId }) => ({ + (dispatch, { solutionId, attemptIndex }) => ({ downloadSolutionArchive: user => e => { e.preventDefault(); - dispatch(downloadSolutionArchive(solutionId, solutionArchiveFileName(solutionId, user))); + dispatch(downloadSolutionArchive(solutionId, solutionArchiveFileName(solutionId, user, attemptIndex))); }, downloadRefSolutionArchive: user => e => { e.preventDefault();