UNPKG

@r3l/app

Version:
120 lines (99 loc) 4.41 kB
"use strict"; var _typeof = require("@babel/runtime/helpers/typeof"); Object.defineProperty(exports, "__esModule", { value: true }); exports.CommentPopup = void 0; var _react = _interopRequireWildcard(require("react")); var _post = require("../../post/post.actions"); var _community = require("../../community"); var _reactRedux = require("react-redux"); var _styled = require("../../styled"); var _popup = require("../../ui/web/popup"); var _comment = require("../comment.actions"); var _navigation = require("../../navigation/navigation.actions"); 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; } var CommentPopup = function CommentPopup(_ref) { var comment = _ref.comment, setEditing = _ref.setEditing; var dispatch = (0, _reactRedux.useDispatch)(); var userId = (0, _reactRedux.useSelector)(function (state) { var _state$auth, _state$auth$user; return state === null || state === void 0 ? void 0 : (_state$auth = state.auth) === null || _state$auth === void 0 ? void 0 : (_state$auth$user = _state$auth.user) === null || _state$auth$user === void 0 ? void 0 : _state$auth$user._id; }); var isOwner = userId && userId === comment.user; var isAdmin = (0, _community.useRequireRole)(_community.MemberRole.ADMIN); var flagPost = function flagPost() { return dispatch((0, _post.flag)(comment)); }; var deletePost = function deletePost(commentId) { // TODO custom confirm // eslint-disable-next-line var okToDelete = confirm('Are you sure you want to delete this post?'); if (!okToDelete) return; dispatch((0, _comment.deleteComment)(commentId)); }; var auditUser = function auditUser(userId) { dispatch((0, _navigation.showModal)('relatedUsers', { userId: userId })); }; var getOptions = (0, _react.useCallback)(function (isOwner, isAdmin) { switch (true) { case isOwner: return [{ text: 'Edit Post', action: function action() { return setEditing(true); } }, { text: 'Delete Post', action: function action() { return deletePost(comment._id); } }, { text: 'Flag Post', action: function action() { return flagPost(); } }]; case isAdmin: return [{ text: 'Flag Post', action: function action() { return flagPost(); } }, { text: 'Delete Post', action: function action() { return deletePost(comment._id); } }, { text: 'Audit User', action: function action() { return auditUser(comment.user); } }]; default: return [{ text: 'Flag Post', action: function action() { return flagPost(); } }]; } }, [isOwner, isAdmin, comment._id, comment.user]); return /*#__PURE__*/_react.default.createElement(_popup.Popup, { options: getOptions(isOwner, isAdmin) }, /*#__PURE__*/_react.default.createElement(_styled.BodyText, { sx: { fontWeight: 'bold', fontSize: 3, color: 'grey', pointerEvents: 'none' } }, "...")); }; exports.CommentPopup = CommentPopup; //# sourceMappingURL=comment.popup.js.map