'use strict'; var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var CorrectionCarousel = ReactRedux.connect(function (state) { return { users: state.users.all }; })((function (_React$Component) { _inherits(_class, _React$Component); function _class(props) { _classCallCheck(this, _class); _get(Object.getPrototypeOf(_class.prototype), 'constructor', this).call(this, props); this.state = { loading: true, corrections: [], correctionCategories: [], hasVideo: new Map(), reviewed: new Map() }; } _createClass(_class, [{ key: 'componentDidMount', value: function componentDidMount() { var _this = this; CAMBLY.get('/model/commentCategories').done((function (response) { this.setState({ correctionCategories: response.result }); }).bind(this)); CAMBLY.get('/model/comments', { 'studentId': this.props.user._id.$oid, 'recommended': true, limit: 5 }).done(function (resp) { var corrections = resp.result.filter(function (correction) { return correction.chat; }); // save all corrections so order is preserved _this.setState({ corrections: corrections }); // look up which corrections have video clips - we only want to feature those corrections.forEach(function (correction) { CAMBLY.get('/model/chats/' + correction.chat).always(function (resp) { // make sure the chat is over and the video has been archived before rendering if (['endTime', 'videoURL'].every(function (k) { return k in resp.result; })) { var hasVideo = new Map([].concat(_toConsumableArray(_this.state.hasVideo))).set(correction.id, true); _this.setState({ hasVideo: hasVideo, loading: false }); } }); }); }); } }, { key: 'correctionsToReview', value: function correctionsToReview() { var _this2 = this; return this.state.corrections.filter(function (c) { return _this2.state.hasVideo.get(c.id) && !_this2.state.reviewed.get(c.id); }); } }, { key: 'review', value: function review(id) { var reviewed = new Map([].concat(_toConsumableArray(this.state.reviewed))).set(id, true); this.setState({ reviewed: reviewed }); } }, { key: 'render', value: function render() { var _this3 = this; if (!this.correctionsToReview().length) { if (this.state.reviewed.size) { return React.createElement("div", { className: "correction-carousel", style: { paddingTop: 0, marginBottom: 50 } }, React.createElement("div", { className: "row no-gutters" }, React.createElement("h4", null, "That's all for now!"))); } return null; } return React.createElement("div", { className: "correction-carousel" }, this.state.loading ? React.createElement("h3", null, React.createElement("i", { className: "fa fa-cog fa-spin" })) : React.createElement(Scrollcontainer, { arrowLock: true }, this.correctionsToReview().map(function (c) { return React.createElement(CorrectionCard, { key: c.id, correction: c, video: React.createElement(CorrectionClip, { videoUrl: '/' + c.language + '/student/history/' + c.chat, seconds: c.seconds, review: _this3.review.bind(_this3, c.id) }), categories: _this3.state.correctionCategories }); }))); } }]); return _class; })(React.Component));