From 7bd6e77b0fbb168416956809e37d0ce6ac0821fd Mon Sep 17 00:00:00 2001 From: moT01 Date: Tue, 5 May 2020 07:48:51 -0500 Subject: [PATCH] feat: add multi file capabillity --- .../templates/Challenges/classic/Editor.js | 33 +++++++++++++++++-- .../src/templates/Challenges/classic/Show.js | 14 +++++--- .../templates/Challenges/classic/editor.css | 24 ++++++++++++++ .../Challenges/rechallenge/builders.js | 12 ++++--- .../challengeSeed-to-data.js | 2 ++ 5 files changed, 74 insertions(+), 11 deletions(-) create mode 100644 client/src/templates/Challenges/classic/editor.css diff --git a/client/src/templates/Challenges/classic/Editor.js b/client/src/templates/Challenges/classic/Editor.js index 6407284da8..c8fab2f607 100644 --- a/client/src/templates/Challenges/classic/Editor.js +++ b/client/src/templates/Challenges/classic/Editor.js @@ -15,10 +15,13 @@ import { import { userSelector, isDonationModalOpenSelector } from '../../../redux'; import { Loader } from '../../../components/helpers'; +import './editor.css'; + const MonacoEditor = React.lazy(() => import('react-monaco-editor')); const propTypes = { canFocus: PropTypes.bool, + challengeFiles: PropTypes.object, containerRef: PropTypes.any.isRequired, contents: PropTypes.string, dimensions: PropTypes.object, @@ -26,6 +29,8 @@ const propTypes = { ext: PropTypes.string, fileKey: PropTypes.string, inAccessibilityMode: PropTypes.bool.isRequired, + initialEditorContent: PropTypes.string, + initialExt: PropTypes.string, saveEditorContent: PropTypes.func.isRequired, setAccessibilityMode: PropTypes.func.isRequired, setEditorFocusability: PropTypes.func, @@ -93,6 +98,12 @@ class Editor extends Component { constructor(...props) { super(...props); + this.state = { + code: '', + ext: '', + fileKey: '' + }; + this.options = { fontSize: '18px', scrollBeyondLastLine: false, @@ -133,6 +144,11 @@ class Editor extends Component { }; editorDidMount = (editor, monaco) => { + this.setState({ + code: this.props.challengeFiles.indexcss.contents, + ext: this.props.challengeFiles.indexcss.ext, + fileKey: this.props.challengeFiles.indexcss.key + }); this._editor = editor; editor.updateOptions({ accessibilitySupport: this.props.inAccessibilityMode ? 'on' : 'auto' @@ -206,8 +222,12 @@ class Editor extends Component { } onChange = editorValue => { - const { updateFile, fileKey } = this.props; + const { updateFile } = this.props; + const { fileKey } = this.state; updateFile({ key: fileKey, editorValue }); + this.setState({ + code: editorValue + }); }; componentDidUpdate(prevProps) { @@ -217,11 +237,18 @@ class Editor extends Component { } render() { - const { contents, ext, theme, fileKey } = this.props; + const { code, ext, fileKey } = this.state; + const { theme } = this.props; const editorTheme = theme === 'night' ? 'vs-dark-custom' : 'vs-custom'; + return ( }> +
+
index.html
+
script.js
+
styles.css
+
diff --git a/client/src/templates/Challenges/classic/Show.js b/client/src/templates/Challenges/classic/Show.js index 4f8f152a42..aa710fad74 100644 --- a/client/src/templates/Challenges/classic/Show.js +++ b/client/src/templates/Challenges/classic/Show.js @@ -222,14 +222,12 @@ class ShowClassic extends Component { renderEditor() { const { files } = this.props; - const challengeFile = first(Object.keys(files).map(key => files[key])); return ( - challengeFile && ( + files && ( ) ); @@ -346,6 +344,14 @@ export const query = graphql` src } files { + indexcss { + key + ext + name + contents + head + tail + } indexhtml { key ext diff --git a/client/src/templates/Challenges/classic/editor.css b/client/src/templates/Challenges/classic/editor.css new file mode 100644 index 0000000000..60c04d16dd --- /dev/null +++ b/client/src/templates/Challenges/classic/editor.css @@ -0,0 +1,24 @@ +.monaco-editor-tabs { + display: flex; + padding: 0px 10px; + background-color: var(--primary-background); + border-bottom: 2px solid var(--primary-color); +} + +.monaco-editor-tab { + position: relative; + top: 2px; + padding: 4px 16px; + border: 2px solid var(--primary-color); + border-left: none; + background-color: var(--secondary-background); +} + +.monaco-editor-tab:first-child { + border-left: 2px solid var(--primary-color); +} + +.monaco-editor-tab-selected { + background-color: var(--primary-background); + border-bottom: 2px solid var(--primary-background); +} diff --git a/client/src/templates/Challenges/rechallenge/builders.js b/client/src/templates/Challenges/rechallenge/builders.js index f3f7db4356..a419b48f38 100644 --- a/client/src/templates/Challenges/rechallenge/builders.js +++ b/client/src/templates/Challenges/rechallenge/builders.js @@ -16,13 +16,16 @@ import { const htmlCatch = '\n\n'; const jsCatch = '\n;/*fcc*/\n'; +const cssCatch = '\n/*fcc*/\n'; -const defaultTemplate = ({ source }) => ` +const defaultTemplate = ({ source }) => { + return ` ${source} `; +}; const wrapInScript = partial( transformContents, @@ -30,11 +33,12 @@ const wrapInScript = partial( ); const wrapInStyle = partial( transformContents, - content => `${htmlCatch}` + content => `${htmlCatch}` ); const setExtToHTML = partial(setExt, 'html'); const padContentWithJsCatch = partial(compileHeadTail, jsCatch); -const padContentWithHTMLCatch = partial(compileHeadTail, htmlCatch); +const padContentWithCssCatch = partial(compileHeadTail, cssCatch); +// const padContentWithHTMLCatch = partial(compileHeadTail, htmlCatch); export const jsToHtml = cond([ [ @@ -52,7 +56,7 @@ export const cssToHtml = cond([ [ matchesProperty('ext', 'css'), flow( - padContentWithHTMLCatch, + padContentWithCssCatch, wrapInStyle, setExtToHTML ) diff --git a/tools/challenge-md-parser/challengeSeed-to-data.js b/tools/challenge-md-parser/challengeSeed-to-data.js index 501e55308f..e56927ace8 100644 --- a/tools/challenge-md-parser/challengeSeed-to-data.js +++ b/tools/challenge-md-parser/challengeSeed-to-data.js @@ -20,6 +20,8 @@ function defaultFile(lang) { }; } function createCodeGetter(key, regEx, seeds) { + console.log('seeds'); + console.log(seeds); return container => { const { properties: { id }