From 997bb9524d62c7eacebcd05f5f1ce669658a44b5 Mon Sep 17 00:00:00 2001 From: vtm Date: Fri, 12 Jan 2018 00:47:29 +0300 Subject: [PATCH] Improve langs dropdown-selector in gameTab --- assets/js/widgets/components/LangSelector.jsx | 21 ++++++----- assets/js/widgets/containers/Editor.jsx | 11 +++--- .../js/widgets/containers/GameStatusTab.jsx | 6 ++-- assets/js/widgets/containers/GameWidget.jsx | 5 ++- assets/js/widgets/middlewares/Game.js | 35 +++++++++++++------ lib/mix/tasks/upload_langs.ex | 2 ++ priv/repo/seeds/langs.yml | 2 +- 7 files changed, 50 insertions(+), 32 deletions(-) diff --git a/assets/js/widgets/components/LangSelector.jsx b/assets/js/widgets/components/LangSelector.jsx index 36642c892..4503cdb3e 100644 --- a/assets/js/widgets/components/LangSelector.jsx +++ b/assets/js/widgets/components/LangSelector.jsx @@ -1,10 +1,13 @@ import React from 'react'; import PropTypes from 'prop-types'; import _ from 'lodash'; -import languages from '../config/languages'; +import Gon from 'Gon'; -const LangSelector = ({ currentLangKey, onChange }) => { - const options = _.filter(_.keys(languages), key => key !== currentLangKey); +const languages = Gon.getAsset('langs'); + +const LangSelector = ({ currentLangSlug, onChange }) => { + +const [[currentLang, ...other], otherLangs] = _.partition(languages, lang => lang.slug === currentLangSlug); return (
- {_.map(options, langKey => ( + {_.map(otherLangs, ({ slug, name }) => ( ))}
@@ -36,7 +39,7 @@ const LangSelector = ({ currentLangKey, onChange }) => { }; LangSelector.propTypes = { - currentLangKey: PropTypes.string.isRequired, + currentLangSlug: PropTypes.string.isRequired, onChange: PropTypes.func.isRequired, }; diff --git a/assets/js/widgets/containers/Editor.jsx b/assets/js/widgets/containers/Editor.jsx index f740d9a36..75e34039e 100644 --- a/assets/js/widgets/containers/Editor.jsx +++ b/assets/js/widgets/containers/Editor.jsx @@ -1,12 +1,14 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; +import Gon from 'Gon'; import AceEditor from 'react-ace'; import 'brace'; import 'brace/mode/javascript'; import 'brace/mode/ruby'; import 'brace/mode/elixir'; import 'brace/theme/solarized_dark'; -import languages from '../config/languages'; +// import languages from '../config/languages'; +const languages = Gon.getAsset('langs'); const selectionBlockStyle = { position: 'absolute', @@ -21,7 +23,7 @@ class Editor extends Component { value: PropTypes.string, name: PropTypes.string.isRequired, editable: PropTypes.bool, - lang: PropTypes.string.isRequired, + syntax: PropTypes.string, onChange: PropTypes.func, allowCopy: PropTypes.bool, } @@ -30,7 +32,7 @@ class Editor extends Component { value: '', editable: false, onChange: null, - lang: _.values(languages)[0], + syntax: 'javascript', allowCopy: true, } @@ -39,11 +41,10 @@ class Editor extends Component { value, name, editable, - lang, + syntax, onChange, allowCopy, } = this.props; - const syntax = languages[lang]; return (
diff --git a/assets/js/widgets/containers/GameStatusTab.jsx b/assets/js/widgets/containers/GameStatusTab.jsx index 488a99268..abc758f5c 100644 --- a/assets/js/widgets/containers/GameStatusTab.jsx +++ b/assets/js/widgets/containers/GameStatusTab.jsx @@ -76,10 +76,10 @@ class GameStatusTab extends Component { type="button" disabled > - {languages[leftEditorLang]} + {leftEditorLang.name} ) : ( - + )} {!canCheckResult ? null : (