UNPKG

feeles-ide

Version:

The hackable and serializable IDE to make learning material

129 lines (116 loc) 4.2 kB
import _extends from 'babel-runtime/helpers/extends'; import _Object$keys from 'babel-runtime/core-js/object/keys'; import _JSON$stringify from 'babel-runtime/core-js/json/stringify'; import _Object$assign from 'babel-runtime/core-js/object/assign'; import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of'; import _classCallCheck from 'babel-runtime/helpers/classCallCheck'; import _createClass from 'babel-runtime/helpers/createClass'; import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn'; import _inherits from 'babel-runtime/helpers/inherits'; import React, { PureComponent } from 'react'; import PropTypes from 'prop-types'; import Card from '../CardWindow'; import { CardText, CardActions } from 'material-ui/Card'; import ActionTouchApp from 'material-ui/svg-icons/action/touch-app'; import { SourceFile } from '../../File/'; import EnvItem from './EnvItem'; import EditFile from '../EditFile'; var EnvCard = function (_PureComponent) { _inherits(EnvCard, _PureComponent); function EnvCard() { var _ref; var _temp, _this, _ret; _classCallCheck(this, EnvCard); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = EnvCard.__proto__ || _Object$getPrototypeOf(EnvCard)).call.apply(_ref, [this].concat(args))), _this), _this.state = { env: _this.props.getConfig('env'), fileKey: '' }, _this.handleUpdateEnv = function (change) { var env = _Object$assign({}, _this.state.env, change); _this.props.setConfig('env', env).then(function (file) { return file.json; }).then(function (env) { return _this.setState({ env: env }); }); }, _temp), _possibleConstructorReturn(_this, _ret); } _createClass(EnvCard, [{ key: 'componentWillReceiveProps', value: function componentWillReceiveProps(nextProps) { if (this.props.files !== nextProps.files) { var envFile = this.props.findFile('.env'); this.setState({ env: this.props.getConfig('env'), fileKey: envFile ? envFile.key : '' }); } } }, { key: 'componentWillMount', value: function componentWillMount() { var envFile = this.props.findFile('.env'); if (!envFile) { var env = this.props.getConfig('env'); this.props.addFile(new SourceFile({ type: 'application/json', name: '.env', text: _JSON$stringify(env, null, '\t') })); } else { this.setState({ fileKey: envFile.key }); } } }, { key: 'render', value: function render() { var _this2 = this; var localization = this.props.localization; return React.createElement( Card, _extends({ icon: EnvCard.icon() }, this.props.cardPropsBag), React.createElement( CardText, null, _Object$keys(this.state.env).map(function (key) { return React.createElement(EnvItem, { key: key, itemKey: key, item: _this2.state.env[key], localization: localization, updateEnv: _this2.handleUpdateEnv }); }) ), React.createElement( CardActions, null, React.createElement(EditFile, { fileKey: this.state.fileKey, findFile: this.props.findFile, selectTab: this.props.selectTab, localization: localization }) ) ); } }], [{ key: 'icon', value: function icon() { return React.createElement(ActionTouchApp, null); } }]); return EnvCard; }(PureComponent); EnvCard.propTypes = { cardPropsBag: PropTypes.object.isRequired, files: PropTypes.array.isRequired, getConfig: PropTypes.func.isRequired, setConfig: PropTypes.func.isRequired, localization: PropTypes.object.isRequired, findFile: PropTypes.func.isRequired, selectTab: PropTypes.func.isRequired, addFile: PropTypes.func.isRequired }; export default EnvCard;