@r3l/app
Version:
203 lines (179 loc) • 7.39 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.TagEl = exports.CommentEl = exports.DomainEl = exports.TitleEl = exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactRedux = require("react-redux");
var _Tag = require("../tag/Tag");
var _styled = require("../styled");
var _navigation = require("../navigation/navigation.actions");
var _history = _interopRequireDefault(require("../navigation/history"));
var _hooks = require("./hooks");
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 _default = /*#__PURE__*/(0, _react.memo)(PostTitle);
exports.default = _default;
function PostTitle(_ref) {
var _post$tags;
var children = _ref.children,
post = _ref.post,
link = _ref.link,
title = _ref.title,
noLink = _ref.noLink,
singlePost = _ref.singlePost,
preview = _ref.preview,
mobile = _ref.mobile;
var postUrl = (0, _hooks.usePostUrl)(post);
if (!post) return null;
var c = mobile ? 'textOverlay' : undefined;
var titleLines = preview && mobile ? 2 : 3;
var renderCommentLink = post.commentCount && postUrl || (post === null || post === void 0 ? void 0 : (_post$tags = post.tags) === null || _post$tags === void 0 ? void 0 : _post$tags.length);
return /*#__PURE__*/_react.default.createElement(_styled.View, {
webContainerSx: {
flex: 1
},
sx: {
flex: 1,
justifyContent: ['center', 'flex-start']
}
}, /*#__PURE__*/_react.default.createElement(_styled.View, null, /*#__PURE__*/_react.default.createElement(TitleEl, {
c: c,
titleLines: titleLines,
title: title,
post: post,
noLink: noLink,
singlePost: singlePost
}), /*#__PURE__*/_react.default.createElement(DomainEl, {
singlePost: singlePost,
noLink: noLink,
link: link,
post: post,
c: c
})), renderCommentLink ? /*#__PURE__*/_react.default.createElement(_styled.Text, {
numberOfLines: 1
}, /*#__PURE__*/_react.default.createElement(CommentEl, {
post: post,
c: c,
noLink: noLink
}), /*#__PURE__*/_react.default.createElement(TagEl, {
post: post,
c: c,
noLink: noLink
})) : null, children);
}
var TitleEl = function TitleEl(_ref2) {
var post = _ref2.post,
noLink = _ref2.noLink,
title = _ref2.title,
singlePost = _ref2.singlePost,
c = _ref2.c,
titleLines = _ref2.titleLines;
var dispatch = (0, _reactRedux.useDispatch)();
var postUrl = (0, _hooks.usePostUrl)(post);
if (!title) return null;
return /*#__PURE__*/_react.default.createElement(_styled.InlineLink, {
to: post.url,
external: true,
target: '_blank',
disabled: noLink,
rel: 'ugc nofollow',
webAction: function webAction() {
return _history.default.push(postUrl);
},
nativeAction: function nativeAction() {
singlePost ? dispatch((0, _navigation.goToUrl)(post.url)) : dispatch((0, _navigation.goToUrl)(post.url)) && dispatch((0, _navigation.goToPost)(post));
}
}, /*#__PURE__*/_react.default.createElement(_styled.Title, {
numberOfLines: titleLines,
sx: {
color: c
}
}, title.replace(/&/g, '&')));
};
exports.TitleEl = TitleEl;
var DomainEl = function DomainEl(_ref3) {
var singlePost = _ref3.singlePost,
link = _ref3.link,
post = _ref3.post,
noLink = _ref3.noLink,
c = _ref3.c;
var dispatch = (0, _reactRedux.useDispatch)();
var postUrl = (0, _hooks.usePostUrl)(post);
var hasAuthor = link && link.articleAuthor && link.articleAuthor.length;
var authorEl = hasAuthor ? /*#__PURE__*/_react.default.createElement(_styled.SmallText, {
sx: {
mr: 0.5 * 8.001,
color: c || 'grey'
}
}, ' ', "\u2022 ", link.articleAuthor.join(', ')) : null;
if (!(link !== null && link !== void 0 && link.domain) && !authorEl) return null;
return /*#__PURE__*/_react.default.createElement(_styled.Text, {
numberOfLines: 1,
sx: {
mt: 2.001
}
}, (link === null || link === void 0 ? void 0 : link.domain) && /*#__PURE__*/_react.default.createElement(_styled.InlineLink, {
to: post.url,
target: "_blank",
external: true,
disabled: !postUrl || noLink,
hu: true,
c: c || 'blue',
rel: 'ugc nofollow',
webAction: function webAction() {
return _history.default.push(postUrl);
},
nativeAction: function nativeAction() {
singlePost ? dispatch((0, _navigation.goToUrl)(post.url)) : dispatch((0, _navigation.goToUrl)(post.url)) && dispatch((0, _navigation.goToPost)(post));
}
}, /*#__PURE__*/_react.default.createElement(_styled.SmallText, {
sx: {
color: c || 'blue'
}
}, link.domain && "".concat(link.domain, "\xA0\u2197\uFE0E"))), authorEl);
};
exports.DomainEl = DomainEl;
var CommentEl = function CommentEl(_ref4) {
var post = _ref4.post,
noLink = _ref4.noLink,
c = _ref4.c;
var dispatch = (0, _reactRedux.useDispatch)();
var postUrl = (0, _hooks.usePostUrl)(post);
if (!post.commentCount) return null;
return /*#__PURE__*/_react.default.createElement(_styled.InlineLink, {
to: postUrl,
hu: true,
disabled: noLink,
c: c || 'blue',
nativeAction: function nativeAction() {
return dispatch((0, _navigation.goToPost)(post));
}
}, /*#__PURE__*/_react.default.createElement(_styled.SmallText, {
sx: {
color: c || 'blue'
}
}, post.commentCount, " Comment", post.commentCount > 1 ? 's' : '', "\xA0\xA0"));
};
exports.CommentEl = CommentEl;
var TagEl = function TagEl(_ref5) {
var noLink = _ref5.noLink,
c = _ref5.c,
post = _ref5.post;
var community = (0, _hooks.usePostComunity)(post);
var tags = post === null || post === void 0 ? void 0 : post.tags;
if (!(tags !== null && tags !== void 0 && tags.length)) return null;
return tags.map(function (tag, i) {
return /*#__PURE__*/_react.default.createElement(_Tag.Tag, {
name: tag,
key: tag + i,
community: community || post.data && post.data.community,
noLink: noLink,
c: c || 'blue'
});
});
};
exports.TagEl = TagEl;
//# sourceMappingURL=postTitle.component.js.map