UNPKG

feeles-ide

Version:

The hackable and serializable IDE to make learning material

96 lines (85 loc) 2.96 kB
import _extends from 'babel-runtime/helpers/extends'; 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 ActionCopyright from 'material-ui/svg-icons/action/copyright'; import shallowEqual from '../../utils/shallowEqual'; import uniqueBy from '../../utils/uniqueBy'; var CreditsCard = function (_PureComponent) { _inherits(CreditsCard, _PureComponent); function CreditsCard() { var _ref; var _temp, _this, _ret; _classCallCheck(this, CreditsCard); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = CreditsCard.__proto__ || _Object$getPrototypeOf(CreditsCard)).call.apply(_ref, [this].concat(args))), _this), _this.state = { credits: _this.getCredits() }, _temp), _possibleConstructorReturn(_this, _ret); } _createClass(CreditsCard, [{ key: 'componentWillReceiveProps', value: function componentWillReceiveProps(nextProps) { if (this.props.files !== nextProps) { var next = this.getCredits(); if (!shallowEqual(this.state.credits, next)) { this.setState({ credits: next }); } } } }, { key: 'getCredits', value: function getCredits() { var credits = this.props.files.reduce(function (p, c) { return p.concat(c.credits); }, []).sort(function (a, b) { return a.timestamp > b.timestamp; }); return uniqueBy(credits, 'label'); } }, { key: 'renderCredit', value: function renderCredit(credit) { return React.createElement( 'div', { key: credit.hash }, credit.url ? React.createElement( 'a', { href: credit.url, target: '_blank' }, credit.label ) : React.createElement( 'span', null, credit.label ) ); } }, { key: 'render', value: function render() { return React.createElement( Card, _extends({ icon: CreditsCard.icon() }, this.props.cardPropsBag), this.state.credits.map(this.renderCredit) ); } }], [{ key: 'icon', value: function icon() { return React.createElement(ActionCopyright, null); } }]); return CreditsCard; }(PureComponent); CreditsCard.propTypes = { cardPropsBag: PropTypes.object.isRequired, files: PropTypes.array.isRequired, localization: PropTypes.object.isRequired }; export default CreditsCard;