Files
freeCodeCamp/client/src/components/SolutionViewer/SolutionViewer.tsx
Oliver Eyton-Williams c11bd163b2 feat: display multifile projects (#45220)
* refactor: DRY up certification and ProjectModal

* fix: use sensible keys for SolutionViewer

* refactor: handle legacy solutions like new ones

* refactor: correct CompletedChallenge type

* fix: store challengeType for multifile projects

* fix: use challengeType to set display type

* feat: use dropdown to display project + code

* refactor: isOpen -> showCode to avoid a clash

We need to be able both show the code and show the completed project

* refactor: remove redundant parts of projectPreview

* refactor: fix project preview types

* feat: wip, using existing modal to show project

* feat: show projects on timeline

* feat: display projects on time-line

* chore: use consistent case for GitHub

* fix(a11y): translate show solution/view

* refactor: rename showFilesSolution

* refactor: use self-closing tag

* fix: remove hardcoding (certification + timeline)

* fix: remove hardcoding (settings)

* test: supply store and mock ga

* fix: include challengeType for projects

Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>

* refactor: remove space

Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>

* fix: key -> filekey on challenge submission

* fix: handle submissions without files

Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>
2022-03-02 19:49:54 -06:00

49 lines
1.3 KiB
TypeScript

import { Panel } from '@freecodecamp/react-bootstrap';
import Prism from 'prismjs';
import React from 'react';
import { ChallengeFile } from '../../redux/prop-types';
type Props = {
challengeFiles: Solution[] | null;
solution?: string;
};
type Solution = Pick<ChallengeFile, 'ext' | 'contents' | 'fileKey'>;
function SolutionViewer({ challengeFiles, solution }: Props) {
const isLegacy = !challengeFiles || !challengeFiles.length;
const solutions = isLegacy
? [
{
ext: 'js',
contents:
solution ?? '// The solution is not available for this project',
fileKey: 'script.js'
}
]
: challengeFiles;
return (
<>
{solutions.map(({ fileKey, ext, contents }) => (
<Panel bsStyle='primary' className='solution-viewer' key={fileKey}>
<Panel.Heading>{ext.toUpperCase()}</Panel.Heading>
<Panel.Body>
<pre>
<code
dangerouslySetInnerHTML={{
__html: Prism.highlight(
contents.trim(),
Prism.languages[ext],
ext
)
}}
/>
</pre>
</Panel.Body>
</Panel>
))}
</>
);
}
export default SolutionViewer;