mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-03-16 19:01:02 -04:00
refactor: files{} -> challengeFiles[], and key -> fileKey (#43023)
* fix(client): fix client * fix propType and add comment * revert user.json prettification * slight type refactor and payload correction Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * update ChallengeFile type imports * add cypress test for code-storage * update test and storage epic * fix Shaun's tired brain's logic * refactor with suggestions Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * update codeReset * increate cypress timeout because firefox is slow * remove unused import to make linter happy * use focus on editor Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * use more specific seletor for cypress editor test * account for silly null challengeFiles Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
@@ -5,15 +5,16 @@ import { useTranslation } from 'react-i18next';
|
||||
import SolutionViewer from './SolutionViewer';
|
||||
|
||||
const propTypes = {
|
||||
files: PropTypes.arrayOf(
|
||||
PropTypes.shape({
|
||||
contents: PropTypes.string,
|
||||
ext: PropTypes.string,
|
||||
key: PropTypes.string,
|
||||
name: PropTypes.string,
|
||||
path: PropTypes.string
|
||||
})
|
||||
),
|
||||
challengeFiles: PropTypes.array,
|
||||
// TODO: removed once refactored to TS
|
||||
// PropTypes.shape({
|
||||
// contents: PropTypes.string,
|
||||
// ext: PropTypes.string,
|
||||
// key: PropTypes.string,
|
||||
// name: PropTypes.string,
|
||||
// path: PropTypes.string
|
||||
// })
|
||||
// ),
|
||||
handleSolutionModalHide: PropTypes.func,
|
||||
isOpen: PropTypes.bool,
|
||||
projectTitle: PropTypes.string,
|
||||
@@ -21,8 +22,13 @@ const propTypes = {
|
||||
};
|
||||
|
||||
const ProjectModal = props => {
|
||||
const { isOpen, projectTitle, files, solution, handleSolutionModalHide } =
|
||||
props;
|
||||
const {
|
||||
isOpen,
|
||||
projectTitle,
|
||||
challengeFiles,
|
||||
solution,
|
||||
handleSolutionModalHide
|
||||
} = props;
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<Modal
|
||||
@@ -39,7 +45,7 @@ const ProjectModal = props => {
|
||||
</Modal.Title>
|
||||
</Modal.Header>
|
||||
<Modal.Body>
|
||||
<SolutionViewer files={files} solution={solution} />
|
||||
<SolutionViewer challengeFiles={challengeFiles} solution={solution} />
|
||||
</Modal.Body>
|
||||
<Modal.Footer>
|
||||
<Button onClick={handleSolutionModalHide}>{t('buttons.close')}</Button>
|
||||
|
||||
@@ -11,21 +11,25 @@ const prismLang = {
|
||||
};
|
||||
|
||||
const SolutionViewer = ({
|
||||
files,
|
||||
challengeFiles,
|
||||
solution = '// The solution is not available for this project'
|
||||
}) =>
|
||||
files && Array.isArray(files) && files.length ? (
|
||||
files.map(file => (
|
||||
<Panel bsStyle='primary' className='solution-viewer' key={file.ext}>
|
||||
<Panel.Heading>{file.ext.toUpperCase()}</Panel.Heading>
|
||||
challengeFiles?.length ? (
|
||||
challengeFiles.map(challengeFile => (
|
||||
<Panel
|
||||
bsStyle='primary'
|
||||
className='solution-viewer'
|
||||
key={challengeFile.ext}
|
||||
>
|
||||
<Panel.Heading>{challengeFile.ext.toUpperCase()}</Panel.Heading>
|
||||
<Panel.Body>
|
||||
<pre>
|
||||
<code
|
||||
className={`language-${prismLang[file.ext]}`}
|
||||
className={`language-${prismLang[challengeFile.ext]}`}
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: Prism.highlight(
|
||||
file.contents.trim(),
|
||||
Prism.languages[prismLang[file.ext]]
|
||||
challengeFile.contents.trim(),
|
||||
Prism.languages[prismLang[challengeFile.ext]]
|
||||
)
|
||||
}}
|
||||
/>
|
||||
@@ -59,7 +63,7 @@ const SolutionViewer = ({
|
||||
|
||||
SolutionViewer.displayName = 'SolutionViewer';
|
||||
SolutionViewer.propTypes = {
|
||||
files: PropTypes.arrayOf(PropTypes.objectOf(PropTypes.string)),
|
||||
challengeFiles: PropTypes.array,
|
||||
solution: PropTypes.string
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user