client/components/pages/parts/editor-achievements.js

"use strict";

require("core-js/modules/es.reflect.construct.js");
require("core-js/modules/es.object.keys.js");
require("core-js/modules/es.symbol.js");
require("core-js/modules/es.array.filter.js");
require("core-js/modules/es.object.get-own-property-descriptor.js");
require("core-js/modules/es.object.get-own-property-descriptors.js");
require("core-js/modules/es.array.iterator.js");
require("core-js/modules/es.string.iterator.js");
require("core-js/modules/es.weak-map.js");
require("core-js/modules/web.dom-collections.iterator.js");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
require("core-js/modules/es.object.to-string.js");
require("core-js/modules/web.dom-collections.for-each.js");
require("core-js/modules/es.array.concat.js");
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var ReactSticky = _interopRequireWildcard(require("react-sticky"));
var bootstrap = _interopRequireWildcard(require("react-bootstrap"));
var _achievement = _interopRequireDefault(require("../../forms/parts/achievement"));
var _dragAndDrop = _interopRequireDefault(require("../../input/drag-and-drop"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireDefault(require("react"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } /*
                                                                                                                                                                                                                                                                                                                                           * Copyright (C) 2016  Daniel Hsing
                                                                                                                                                                                                                                                                                                                                           * 				 2016  Max Prettyjohns
                                                                                                                                                                                                                                                                                                                                           *
                                                                                                                                                                                                                                                                                                                                           * This program is free software; you can redistribute it and/or modify
                                                                                                                                                                                                                                                                                                                                           * it under the terms of the GNU General Public License as published by
                                                                                                                                                                                                                                                                                                                                           * the Free Software Foundation; either version 2 of the License, or
                                                                                                                                                                                                                                                                                                                                           * (at your option) any later version.
                                                                                                                                                                                                                                                                                                                                           *
                                                                                                                                                                                                                                                                                                                                           * This program is distributed in the hope that it will be useful,
                                                                                                                                                                                                                                                                                                                                           * but WITHOUT ANY WARRANTY; without even the implied warranty of
                                                                                                                                                                                                                                                                                                                                           * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                                                                                                                                                                                                                                                                                                                                           * GNU General Public License for more details.
                                                                                                                                                                                                                                                                                                                                           *
                                                                                                                                                                                                                                                                                                                                           * You should have received a copy of the GNU General Public License along
                                                                                                                                                                                                                                                                                                                                           * with this program; if not, write to the Free Software Foundation, Inc.,
                                                                                                                                                                                                                                                                                                                                           * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
                                                                                                                                                                                                                                                                                                                                           */
var Button = bootstrap.Button,
  CardDeck = bootstrap.CardDeck,
  Col = bootstrap.Col,
  Form = bootstrap.Form,
  Row = bootstrap.Row;
var Sticky = ReactSticky.Sticky,
  StickyContainer = ReactSticky.StickyContainer;

/**
 * Renders the document and displays the 'Editor Achievements Tab'.
 */
var EditorAchievementTab = /*#__PURE__*/function (_React$Component) {
  (0, _inherits2.default)(EditorAchievementTab, _React$Component);
  var _super = _createSuper(EditorAchievementTab);
  /**
   * Initializes the component state.
   * @constructor
   * @param {object} props - Properties passed to the component.
   */
  function EditorAchievementTab(props) {
    var _this;
    (0, _classCallCheck2.default)(this, EditorAchievementTab);
    _this = _super.call(this, props);
    _this.currAchievement = props.currAchievement;
    _this.state = {
      achievement: props.achievement,
      editor: props.editor
    };
    return _this;
  }

  /**
   * Renders the Editor Achievements list. Also splits the
   * achievements into Unlocked and Locked achievements.
   * @returns {Array} - An array containing rendered achievements
   * list split into Unlocked and Locked.
   */
  (0, _createClass2.default)(EditorAchievementTab, [{
    key: "renderAchievements",
    value: function renderAchievements() {
      var _this2 = this;
      var achievements = [];
      var locked = [];
      this.state.achievement.model.forEach(function (achievement) {
        var achievementHTML = /*#__PURE__*/_react.default.createElement(_achievement.default, {
          achievement: achievement,
          key: "".concat(_this2.state.editor.id).concat(achievement.id)
        });
        if (achievement.unlocked) {
          achievements.push(achievementHTML);
        } else {
          locked.push(achievementHTML);
        }
      });
      return [achievements, locked];
    }

    /**
     * Renders the EditorAchievements page, which displays all the achievements
     * (both unlocked and locked) of the editor, along with a RankUpdate form.
     * @returns {ReactElement} a HTML document which displays the
     * EditorAchievements page.
     */
  }, {
    key: "render",
    value: function render() {
      var _this$renderAchieveme = this.renderAchievements(),
        _this$renderAchieveme2 = (0, _slicedToArray2.default)(_this$renderAchieveme, 2),
        achievements = _this$renderAchieveme2[0],
        locked = _this$renderAchieveme2[1];
      var rankUpdate;
      if (this.props.isOwner) {
        var _this$currAchievement, _this$currAchievement2, _this$currAchievement3, _this$currAchievement4, _this$currAchievement5, _this$currAchievement6;
        rankUpdate = /*#__PURE__*/_react.default.createElement(Form, {
          className: "padding-bottom-1",
          id: "rankSelectForm",
          method: "post"
        }, /*#__PURE__*/_react.default.createElement(CardDeck, {
          className: "mb-3"
        }, /*#__PURE__*/_react.default.createElement(_dragAndDrop.default, {
          initialAchievement: (_this$currAchievement = this.currAchievement.model.fulfillmentValue) === null || _this$currAchievement === void 0 ? void 0 : (_this$currAchievement2 = _this$currAchievement[0]) === null || _this$currAchievement2 === void 0 ? void 0 : _this$currAchievement2.achievement,
          name: "rank1"
        }), /*#__PURE__*/_react.default.createElement(_dragAndDrop.default, {
          initialAchievement: (_this$currAchievement3 = this.currAchievement.model.fulfillmentValue) === null || _this$currAchievement3 === void 0 ? void 0 : (_this$currAchievement4 = _this$currAchievement3[1]) === null || _this$currAchievement4 === void 0 ? void 0 : _this$currAchievement4.achievement,
          name: "rank2"
        }), /*#__PURE__*/_react.default.createElement(_dragAndDrop.default, {
          initialAchievement: (_this$currAchievement5 = this.currAchievement.model.fulfillmentValue) === null || _this$currAchievement5 === void 0 ? void 0 : (_this$currAchievement6 = _this$currAchievement5[2]) === null || _this$currAchievement6 === void 0 ? void 0 : _this$currAchievement6.achievement,
          name: "rank3"
        })), /*#__PURE__*/_react.default.createElement("span", {
          className: "margin-left-1"
        }, /*#__PURE__*/_react.default.createElement(Button, {
          type: "submit",
          variant: "success"
        }, "Update"), /*#__PURE__*/_react.default.createElement("span", {
          className: "margin-left-1"
        }, "click badge to unset")));
      }
      var STICKY_TOP_MARGIN = 64;
      return /*#__PURE__*/_react.default.createElement(Row, null, /*#__PURE__*/_react.default.createElement(Col, {
        lg: {
          offset: 1,
          span: 10
        }
      }, /*#__PURE__*/_react.default.createElement("div", {
        id: "achievementsForm"
      }, /*#__PURE__*/_react.default.createElement(StickyContainer, null, /*#__PURE__*/_react.default.createElement(Sticky, {
        topOffset: -80
      }, function (_ref) {
        var style = _ref.style;
        var updatedStyle = _objectSpread(_objectSpread({}, style), {}, {
          background: 'white',
          borderBottom: '1px solid #ebe2df',
          flex: '1',
          marginTop: STICKY_TOP_MARGIN,
          zIndex: 10
        });
        return /*#__PURE__*/_react.default.createElement("div", {
          style: updatedStyle
        }, rankUpdate);
      }), /*#__PURE__*/_react.default.createElement("div", {
        style: {
          zIndex: 1
        }
      }, /*#__PURE__*/_react.default.createElement("div", {
        className: "h1"
      }, "Unlocked Achievements"), achievements, /*#__PURE__*/_react.default.createElement("div", {
        className: "h1"
      }, "Locked Achievements"), locked)))));
    }
  }]);
  return EditorAchievementTab;
}(_react.default.Component);
EditorAchievementTab.displayName = 'EditorAchievementTab';
EditorAchievementTab.propTypes = {
  achievement: _propTypes.default.shape({
    model: _propTypes.default.array
  }).isRequired,
  currAchievement: _propTypes.default.shape({
    model: _propTypes.default.array
  }).isRequired,
  editor: _propTypes.default.shape({
    authenticated: _propTypes.default.bool,
    id: _propTypes.default.number
  }).isRequired,
  isOwner: _propTypes.default.bool.isRequired
};
var _default = EditorAchievementTab;
exports.default = _default;
//# sourceMappingURL=editor-achievements.js.map