client/components/input/drag-and-drop-image.js

"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
/*
 * Copyright (C) 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 useCallback = _react.default.useCallback;

/**
 * Props for DragAndDropImage component
 * @typedef {Object} Props
 * @property {number} achievementId - ID of the achievement
 * @property {string} achievementName - Name of the achievement
 * @property {string} height - Height of the image
 * @property {string} src - Image source URL
 */

/**
 * The `DragAndDropImage` component renders an image of a particular achievement badge, which can be dragged to set the user's publicly showcased achievements.
 *
 * @param {Props} props - Props for the component
 *
 * @returns {JSX.Element} - The rendered image element.
 */

function DragAndDropImage(_ref) {
  var achievementId = _ref.achievementId,
    achievementName = _ref.achievementName,
    height = _ref.height,
    src = _ref.src;
  /**
   * Transfers the data of the achievement badge component properties to the DragEvent, which in turn transfers the data on handleDrop to that of the achievement badge which will be showcased on editor's public profile.
   * @param {React.DragEvent<HTMLImageElement>} ev - The drag event object.
   */
  var handleDragStart = useCallback(function (ev) {
    var data = {
      id: achievementId,
      name: achievementName,
      src: src
    };
    ev.dataTransfer.setData('text', JSON.stringify(data));
  }, [achievementId, achievementName, src]);
  return /*#__PURE__*/_react.default.createElement("img", {
    draggable: true,
    height: height,
    src: src,
    onDragStart: handleDragStart
  });
}
DragAndDropImage.displayName = 'DragAndDropImage';
var _default = DragAndDropImage;
exports.default = _default;
//# sourceMappingURL=drag-and-drop-image.js.map