UNPKG

@selfcommunity/react-ui

Version:

React UI Components to integrate a Community created with SelfCommunity Platform.

453 lines (444 loc) • 42.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = tslib_1.__importStar(require("react")); const styles_1 = require("@mui/material/styles"); const CardContent_1 = tslib_1.__importDefault(require("@mui/material/CardContent")); const material_1 = require("@mui/material"); const Skeleton_1 = tslib_1.__importDefault(require("./Skeleton")); const DateTimeAgo_1 = tslib_1.__importDefault(require("../../shared/DateTimeAgo")); const Bullet_1 = tslib_1.__importDefault(require("../../shared/Bullet")); const Tags_1 = tslib_1.__importDefault(require("../../shared/Tags")); const Actions_1 = tslib_1.__importDefault(require("./Actions")); const Icon_1 = tslib_1.__importDefault(require("@mui/material/Icon")); const react_intl_1 = require("react-intl"); const Poll_1 = tslib_1.__importDefault(require("./Poll")); const Contributors_1 = tslib_1.__importDefault(require("./Contributors")); const feedObject_1 = require("../../types/feedObject"); const MarkRead_1 = tslib_1.__importDefault(require("../../shared/MarkRead")); const classnames_1 = tslib_1.__importDefault(require("classnames")); const ContributionActionsMenu_1 = tslib_1.__importDefault(require("../../shared/ContributionActionsMenu")); const contribution_1 = require("../../utils/contribution"); const Follow_1 = tslib_1.__importDefault(require("./Actions/Follow")); const Widget_1 = tslib_1.__importDefault(require("../Widget")); const system_1 = require("@mui/system"); const BaseItem_1 = tslib_1.__importDefault(require("../../shared/BaseItem")); const Activities_1 = tslib_1.__importDefault(require("./Activities")); const CommentObjectReply_1 = tslib_1.__importDefault(require("../CommentObjectReply")); const Errors_1 = require("../../constants/Errors"); const notistack_1 = require("notistack"); const types_1 = require("@selfcommunity/types"); const api_services_1 = require("@selfcommunity/api-services"); const utils_1 = require("@selfcommunity/utils"); const errors_1 = require("../../utils/errors"); const react_core_1 = require("@selfcommunity/react-core"); const UserDeletedSnackBar_1 = tslib_1.__importDefault(require("../../shared/UserDeletedSnackBar")); const UserAvatar_1 = tslib_1.__importDefault(require("../../shared/UserAvatar")); const Feed_1 = require("../../constants/Feed"); const Composer_1 = tslib_1.__importDefault(require("../Composer")); const FeedObjectMediaPreview_1 = tslib_1.__importDefault(require("../FeedObjectMediaPreview")); const constants_1 = require("./constants"); const Media_1 = require("../../constants/Media"); const messages = (0, react_intl_1.defineMessages)({ visibleToAll: { id: 'ui.feedObject.visibleToAll', defaultMessage: 'ui.feedObject.visibleToAll' }, visibleToGroup: { id: 'ui.feedObject.visibleToGroup', defaultMessage: 'ui.feedObject.visibleToGroup' } }); const classes = { root: `${constants_1.PREFIX}-root`, deleted: `${constants_1.PREFIX}-deleted`, header: `${constants_1.PREFIX}-header`, category: `${constants_1.PREFIX}-category`, event: `${constants_1.PREFIX}-event`, group: `${constants_1.PREFIX}-group`, avatar: `${constants_1.PREFIX}-avatar`, username: `${constants_1.PREFIX}-username`, activityAt: `${constants_1.PREFIX}-activity-at`, tag: `${constants_1.PREFIX}-tag`, location: `${constants_1.PREFIX}-location`, content: `${constants_1.PREFIX}-content`, showMore: `${constants_1.PREFIX}-show-more`, error: `${constants_1.PREFIX}-error`, titleSection: `${constants_1.PREFIX}-title-section`, title: `${constants_1.PREFIX}-title`, textSection: `${constants_1.PREFIX}-text-section`, text: `${constants_1.PREFIX}-text`, snippet: `${constants_1.PREFIX}-snippet`, snippetContent: `${constants_1.PREFIX}-snippet-content`, mediasSection: `${constants_1.PREFIX}-medias-section`, pollsSection: `${constants_1.PREFIX}-polls-section`, infoSection: `${constants_1.PREFIX}-info-section`, actionsSection: `${constants_1.PREFIX}-actions-section`, replyContent: `${constants_1.PREFIX}-reply-content`, activitiesSection: `${constants_1.PREFIX}-activities-section`, activitiesContent: `${constants_1.PREFIX}-activities-content`, followButton: `${constants_1.PREFIX}-follow-button` }; const Root = (0, styles_1.styled)(Widget_1.default, { name: constants_1.PREFIX, slot: 'Root' })(() => ({})); /** * > API documentation for the Community-JS Feed Object component. Learn about the available props and the CSS API. * * * This component renders a feed object item (post, discussion or status). * Take a look at our <strong>demo</strong> component [here](/docs/sdk/community-js/react-ui/Components/FeedObject) #### Import ```jsx import {FeedObject} from '@selfcommunity/react-ui'; ``` #### Component Name The name `SCFeedObject` can be used when providing style overrides in the theme. #### CSS |Rule Name|Global class|Description| |---|---|---| |root|.SCFeedObject-root|Styles applied to the root element.| |deleted|.SCFeedObject-deleted|Styles applied to the feed obj when is deleted (visible only for admin and moderator).| |header|.SCFeedObject-header|Styles applied to the header of the card.| |category|.SCFeedObject-category|Styles applied to the category element.| |event|.SCFeedObject-event|Styles applied to the event element.| |group|.SCFeedObject-group|Styles applied to the group element.| |avatar|.SCFeedObject-avatar|Styles applied to the avatar element.| |username|.SCFeedObject-username|Styles applied to the username element.| |activityAt|.SCFeedObject-activity-at|Styles applied to the activity at section.| |tag|.SCFeedObject-tag|Styles applied to the tag element.| |location|.SCFeedObject-location|Styles applied to the location element.| |content|.SCFeedObject-content|Styles applied to the content section. Content section include: title-section, text-section, snippetContent, subContent, medias-section, polls-section, info-section.| |error|.SCFeedObject-error|Styles applied to the error element.| |title-section|.SCFeedObject-title-section|Styles applied to the title section.| |title|.SCFeedObject-title|Styles applied to the title element.| |text-section|.SCFeedObject-text-section|Styles applied to the text section.| |text|.SCFeedObject-text|Styles applied to the text element.| |snippet|.SCFeedObject-snippet|Styles applied to snippet element.| |snippet-content|.SCFeedObject-snippet-content|Styles applied to snippet content element.| |medias-section|.SCFeedObject-medias-section|Styles applied to the medias section.| |polls-section|.SCFeedObject-polls-section|Styles applied to the polls section.| |info-section|.SCFeedObject-info-section|Styles applied to the info section.| |actions-section|.SCFeedObject-actions-section|Styles applied to the actions container.| |reply-content|.SCFeedObject-reply-content|Styles applied to the reply box.| |activitiesSection|.SCFeedObject-activities-section|Styles applied to the activities section element.| |activitiesContent|.SCFeedObject-activities-content|Styles applied to the activities content element.| |followButton|.SCFeedObject-follow-button|Styles applied to the follow button element.| * @param inProps */ function FeedObject(inProps) { var _a, _b, _c, _d, _f, _g, _h; // PROPS const props = (0, system_1.useThemeProps)({ props: inProps, name: constants_1.PREFIX }); const { id = `feed_object_${props.feedObjectId ? props.feedObjectId : props.feedObject ? props.feedObject.id : ''}`, className = null, feedObjectId = null, feedObject = null, feedObjectType = null, feedObjectActivities = null, cacheStrategy = utils_1.CacheStrategies.CACHE_FIRST, markRead = false, template = feedObject_1.SCFeedObjectTemplateType.PREVIEW, hideFollowAction = false, summaryExpanded = false, activitiesExpanded = true, activitiesExpandedType, hideParticipantsPreview = false, pollVisible = true, FollowButtonProps = {}, FeedObjectSkeletonProps = { elevation: 0 }, ActionsProps = {}, CommentObjectReplyComponent = CommentObjectReply_1.default, CommentObjectReplyComponentProps = { WidgetProps: { variant: 'outlined' } }, CommentComponentProps = { variant: 'outlined' }, CommentObjectSkeletonProps = { elevation: 0, WidgetProps: { variant: 'outlined' } }, ContributionActionsMenuProps = {}, FeedObjectMediaPreviewProps = {}, ActivitiesProps = { cacheStrategy }, PollObjectProps = { elevation: 0 }, ContributorsFeedObjectProps = {}, onReply, onHeightChange, onStateChange } = props, rest = tslib_1.__rest(props, ["id", "className", "feedObjectId", "feedObject", "feedObjectType", "feedObjectActivities", "cacheStrategy", "markRead", "template", "hideFollowAction", "summaryExpanded", "activitiesExpanded", "activitiesExpandedType", "hideParticipantsPreview", "pollVisible", "FollowButtonProps", "FeedObjectSkeletonProps", "ActionsProps", "CommentObjectReplyComponent", "CommentObjectReplyComponentProps", "CommentComponentProps", "CommentObjectSkeletonProps", "ContributionActionsMenuProps", "FeedObjectMediaPreviewProps", "ActivitiesProps", "PollObjectProps", "ContributorsFeedObjectProps", "onReply", "onHeightChange", "onStateChange"]); // CONTEXT const scContext = (0, react_core_1.useSCContext)(); const scRoutingContext = (0, react_core_1.useSCRouting)(); const scUserContext = (0, react_core_1.useSCUser)(); const { enqueueSnackbar } = (0, notistack_1.useSnackbar)(); // OBJECTS const { obj, setObj, error } = (0, react_core_1.useSCFetchFeedObject)({ id: feedObjectId, feedObject, feedObjectType, cacheStrategy }); const objId = obj ? obj.id : null; const [openAlert, setOpenAlert] = (0, react_1.useState)(false); /** * Get initial expanded activities type */ const geExpandedActivities = () => { return obj && activitiesExpanded && (obj.comment_count > 0 || (feedObjectActivities && feedObjectActivities.length > 0)); }; // STATE const [composerOpen, setComposerOpen] = (0, react_1.useState)(false); const [expandedActivities, setExpandedActivities] = (0, react_1.useState)(geExpandedActivities()); const [comments, setComments] = (0, react_1.useState)([]); const [isReplying, setIsReplying] = (0, react_1.useState)(false); const [selectedActivities, setSelectedActivities] = (0, react_1.useState)(getInitialSelectedActivitiesType()); const [expanded, setExpanded] = (0, react_1.useState)(summaryExpanded); const hasEvent = (0, react_1.useMemo)(() => { var _a; return (obj === null || obj === void 0 ? void 0 : obj.medias.length) > 0 && ((_a = obj.medias[0].embed) === null || _a === void 0 ? void 0 : _a.embed_type) === Media_1.MEDIA_EMBED_SC_SHARED_EVENT; }, [obj === null || obj === void 0 ? void 0 : obj.medias]); const _hideFollowAction = (0, react_1.useMemo)(() => { var _a, _b, _c, _d; return hideFollowAction || (hasEvent && ((_d = (_c = (_b = (_a = obj === null || obj === void 0 ? void 0 : obj.medias) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.embed) === null || _c === void 0 ? void 0 : _c.metadata) === null || _d === void 0 ? void 0 : _d.active) === false); }, [hideFollowAction, hasEvent, obj]); // INTL const intl = (0, react_intl_1.useIntl)(); /** * Notify changes to Feed if the FeedObject is contained in the feed */ const notifyFeedChanges = (0, react_1.useMemo)(() => (state) => { if (onStateChange && state) { onStateChange(state); } onHeightChange && onHeightChange(); }, [onStateChange, onHeightChange]); /** * Update state object * @param newObj */ const updateObject = (newObj) => { setObj(newObj); notifyFeedChanges(); }; /** * Get initial selected activities section */ function getInitialSelectedActivitiesType() { if (activitiesExpandedType) { return activitiesExpandedType; } if (feedObjectActivities && feedObjectActivities.length > 0) { return feedObject_1.SCFeedObjectActivitiesType.RELEVANCE_ACTIVITIES; } return feedObject_1.SCFeedObjectActivitiesType.RECENT_COMMENTS; } /** * Open expanded activities */ (0, react_1.useEffect)(() => { const _e = geExpandedActivities(); setExpandedActivities(_e); notifyFeedChanges({ activitiesExpanded: _e, activitiesExpandedType: selectedActivities, cacheStrategy: utils_1.CacheStrategies.CACHE_FIRST }); }, [objId, selectedActivities]); /** * Handle change/update poll: votes */ const handleChangePoll = (0, react_1.useCallback)((pollChoices) => { if ('poll' in obj) { updateObject(Object.assign({}, obj, { poll: Object.assign(Object.assign({}, obj.poll), { choices: pollChoices }) })); } }, [obj]); /** * Handle change poll visibility */ const handleTogglePollVisibility = (0, react_1.useCallback)((visible) => { notifyFeedChanges({ pollVisible: visible }); }, [pollVisible, notifyFeedChanges]); /** * Handle toggle summary */ const handleToggleSummary = (0, react_1.useCallback)(() => { setExpanded(!expanded); notifyFeedChanges({ summaryExpanded: !expanded }); }, [expanded, notifyFeedChanges]); /** * Render header action * if author = authenticated user -> render edit action * else render ContributionActionsMenu */ const renderHeaderAction = () => { return ((0, jsx_runtime_1.jsx)(ContributionActionsMenu_1.default, Object.assign({ feedObject: obj, feedObjectType: feedObjectType, onEditContribution: handleToggleEdit, onHideContribution: handleHide, onDeleteContribution: handleDelete, onRestoreContribution: handleRestore, onSuspendNotificationContribution: handleSuspendNotification, onFlagContribution: handleFlag }, ContributionActionsMenuProps))); }; /** * Handle flag obj */ const handleFlag = (0, react_1.useCallback)((obj, type, flagged) => { enqueueSnackbar(flagged ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.feedObject.flagSent", defaultMessage: "ui.feedObject.flagSent" })) : ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.feedObject.flagRemoved", defaultMessage: "ui.feedObject.flagRemoved" })), { autoHideDuration: 3000 }); }, []); /** * Handle restore obj */ const handleRestore = (0, react_1.useCallback)(() => { updateObject(Object.assign({}, obj, { deleted: false })); }, [obj]); /** * Handle restore obj */ const handleHide = (0, react_1.useCallback)(() => { updateObject(Object.assign({}, obj, { collapsed: !obj.collapsed })); }, [obj]); /** * Handle delete obj */ const handleDelete = (0, react_1.useCallback)(() => { updateObject(Object.assign({}, obj, { deleted: !obj.deleted })); }, [obj]); /** * Handle suspend notification obj */ const handleSuspendNotification = (0, react_1.useCallback)(() => { updateObject(Object.assign({}, obj, { suspended: !obj.suspended })); enqueueSnackbar(obj.suspended ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.feedObject.notificationsEnabled", defaultMessage: "ui.feedObject.notificationsEnabled" })) : ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.feedObject.notificationsDisabled", defaultMessage: "ui.feedObject.notificationsDisabled" })), { autoHideDuration: 3000 }); }, [obj]); /** * Handle initial edit * Open composer */ const handleToggleEdit = (0, react_1.useCallback)(() => { setComposerOpen((prev) => !prev); }, [composerOpen]); /** * handle edit success */ const handleEditSuccess = (0, react_1.useCallback)((data) => { updateObject(data); setComposerOpen(false); }, [obj, composerOpen]); /** * handle vote */ const handleVoteSuccess = (0, react_1.useCallback)((data) => { updateObject(Object.assign({}, obj, { voted: data.voted, vote_count: data.vote_count, reactions_count: data.reactions_count, reaction: data.reaction })); }, [obj]); /** * Expand activities if the user is logged */ const handleExpandActivities = (0, react_1.useCallback)(() => { if (scUserContext.user) { const _e = !expandedActivities; setExpandedActivities(_e); notifyFeedChanges({ activitiesExpanded: _e }); } else { scContext.settings.handleAnonymousAction(); } }, [expandedActivities, scUserContext.user, notifyFeedChanges, selectedActivities]); /** * Handle follow obj */ const handleFollow = (0, react_1.useCallback)((isFollow) => { updateObject(Object.assign(Object.assign({}, obj), { followed: isFollow })); }, [obj]); /** * Handle delete comment callback */ const handleDeleteComment = (0, react_1.useCallback)(() => { updateObject(Object.assign(Object.assign({}, obj), { comment_count: Math.max(obj.comment_count - 1, 0) })); }, [obj]); /** * Handle select activities */ const handleSelectedActivities = (0, react_1.useCallback)((type) => { setSelectedActivities(type); setComments([]); notifyFeedChanges({ activitiesExpandedType: type }); }, [obj, expandedActivities]); /** * Perform reply * Comment of first level */ const performReply = (0, react_1.useMemo)(() => (comment) => { return api_services_1.http .request({ url: api_services_1.Endpoints.NewComment.url({}), method: api_services_1.Endpoints.NewComment.method, data: { [`${obj.type}`]: obj.id, text: comment } }) .then((res) => { if (res.status >= 300) { return Promise.reject(res); } return Promise.resolve(res.data); }); }, [objId]); /** * Handle comment */ const handleReply = (comment) => { if (!scUserContext.user) { scContext.settings.handleAnonymousAction(); } else if (react_core_1.UserUtils.isBlocked(scUserContext.user)) { enqueueSnackbar((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.common.userBlocked", defaultMessage: "ui.common.userBlocked" }), { variant: 'warning', autoHideDuration: 3000 }); } else { setIsReplying(true); performReply(comment) .then((data) => { // if add a comment -> the comment must be untruncated const _data = data; _data.summary_truncated = false; if (selectedActivities !== feedObject_1.SCFeedObjectActivitiesType.RECENT_COMMENTS) { setComments([]); setSelectedActivities(feedObject_1.SCFeedObjectActivitiesType.RECENT_COMMENTS); } else { setComments([...[_data], ...comments]); } setIsReplying(false); const newObj = Object.assign({}, obj, { comment_count: obj.comment_count + 1 }); updateObject(newObj); utils_1.LRUCache.deleteKeysWithPrefix(react_core_1.SCCache.getCommentObjectsCachePrefixKeys(obj.id, obj.type)); onReply && onReply(data); notifyFeedChanges({ activitiesExpanded: expandedActivities, activitiesExpandedType: feedObject_1.SCFeedObjectActivitiesType.RECENT_COMMENTS }); }) .catch((error) => { utils_1.Logger.error(Errors_1.SCOPE_SC_UI, error); if (!(0, errors_1.catchUnauthorizedActionByBlockedUser)(error, scUserContext.managers.blockedUsers.isBlocked(obj.author), enqueueSnackbar)) { enqueueSnackbar((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.common.error.action", defaultMessage: "ui.common.error.action" }), { variant: 'error', autoHideDuration: 3000 }); } }); } }; /** * Get contribution summary */ const getContributionSummary = (0, react_1.useCallback)((obj, template) => { const contributionHtml = 'summary_html' in obj ? obj.summary_html : obj.summary; const summaryHtmlTruncated = 'summary_truncated' in obj ? obj.summary_truncated : obj.html.length >= Feed_1.MAX_SUMMARY_LENGTH; const summaryHtml = expanded || template === feedObject_1.SCFeedObjectTemplateType.DETAIL ? (0, contribution_1.getContributionHtml)(obj.html, scRoutingContext.url) : (0, contribution_1.getContributionHtml)(contributionHtml, scRoutingContext.url); if (template === feedObject_1.SCFeedObjectTemplateType.SHARE) { return ((0, jsx_runtime_1.jsxs)(react_core_1.Link, Object.assign({ to: scRoutingContext.url((0, contribution_1.getContributionRouteName)(obj), (0, contribution_1.getRouteData)(obj)), className: classes.text }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { component: "span", className: classes.text, variant: "body2", gutterBottom: true, dangerouslySetInnerHTML: { __html: summaryHtml } }), !expanded && summaryHtmlTruncated && ((0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ size: "small", variant: "text", color: "inherit", className: classes.showMore, onClick: handleToggleSummary }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.feedObject.content.showMore", defaultMessage: "ui.feedObject.content.showMore" }) })))] }))); } else if (template === feedObject_1.SCFeedObjectTemplateType.DETAIL) { return ((0, jsx_runtime_1.jsx)(material_1.Typography, { component: "div", gutterBottom: true, className: classes.text, dangerouslySetInnerHTML: { __html: summaryHtml } })); } else { return ((0, jsx_runtime_1.jsxs)(material_1.Typography, Object.assign({ component: "div", gutterBottom: true, className: classes.text }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { component: "span", dangerouslySetInnerHTML: { __html: summaryHtml } }), !expanded && summaryHtmlTruncated && ((0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ size: "small", variant: "text", color: "inherit", className: classes.showMore, onClick: handleToggleSummary }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.feedObject.content.showMore", defaultMessage: "ui.feedObject.content.showMore" }) })))] }))); } }, [obj, template, expanded]); /** * Render the obj object * Manage variants: * SNIPPET, PREVIEW, DETAIL, SEARCH, SHARE */ let objElement; if ((!obj && error) || ((obj === null || obj === void 0 ? void 0 : obj.deleted) && !scUserContext.user && !(react_core_1.UserUtils.isAdmin(scUserContext.user) || react_core_1.UserUtils.isModerator(scUserContext.user)))) { objElement = ((0, jsx_runtime_1.jsx)(CardContent_1.default, Object.assign({ className: (0, classnames_1.default)(classes.error, classes.content) }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.feedObject.error", defaultMessage: "ui.feedObject.error" }) }))); } else if (template === feedObject_1.SCFeedObjectTemplateType.PREVIEW || template === feedObject_1.SCFeedObjectTemplateType.DETAIL || template === feedObject_1.SCFeedObjectTemplateType.SEARCH) { objElement = ((0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: obj ? ((0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ className: (0, classnames_1.default)({ [classes.deleted]: obj && obj.deleted }) }, { children: [obj.categories.length > 0 && ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: classes.category }, { children: [(0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [obj.group && ((0, jsx_runtime_1.jsx)(material_1.Chip, { className: classes.group, color: "secondary", size: "small", icon: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "groups" }), component: react_core_1.Link, to: scRoutingContext.url(react_core_1.SCRoutes.GROUP_ROUTE_NAME, obj.group), clickable: true }, obj.group.id)), obj.event && ((0, jsx_runtime_1.jsx)(material_1.Chip, { className: classes.event, color: "secondary", size: "small", label: obj.event.name, icon: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "CalendarIcon" }), component: react_core_1.Link, to: scRoutingContext.url(react_core_1.SCRoutes.EVENT_ROUTE_NAME, obj.event), clickable: true }, obj.event.id))] }), obj.categories.map((c) => ((0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({ to: scRoutingContext.url(react_core_1.SCRoutes.CATEGORY_ROUTE_NAME, c) }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "overline" }, { children: c.name })) }), c.id)))] }))), obj.group && !obj.categories.length && ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: classes.group }, { children: (0, jsx_runtime_1.jsx)(material_1.Chip, { color: "secondary", size: "small", icon: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "groups" }), label: obj.group.name, component: react_core_1.Link, to: scRoutingContext.url(react_core_1.SCRoutes.GROUP_ROUTE_NAME, obj.group), clickable: true }, obj.group.id) }))), obj.event && !obj.categories.length && ((0, jsx_runtime_1.jsx)(material_1.Chip, { className: classes.event, color: "secondary", size: "small", icon: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "CalendarIcon" }), label: obj.event.name, component: react_core_1.Link, to: scRoutingContext.url(react_core_1.SCRoutes.EVENT_ROUTE_NAME, obj.event), clickable: true }, obj.event.id)), (0, jsx_runtime_1.jsx)(material_1.CardHeader, { className: classes.header, avatar: (0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({}, (!obj.author.deleted && { to: scRoutingContext.url(react_core_1.SCRoutes.USER_PROFILE_ROUTE_NAME, obj.author) }), { onClick: obj.author.deleted ? () => setOpenAlert(true) : null }, { children: (0, jsx_runtime_1.jsx)(UserAvatar_1.default, Object.assign({ hide: !obj.author.community_badge }, { children: (0, jsx_runtime_1.jsx)(material_1.Avatar, Object.assign({ "aria-label": "recipe", src: obj.author.avatar, className: classes.avatar }, { children: obj.author.username })) })) })), title: (0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({}, (!obj.author.deleted && { to: scRoutingContext.url(react_core_1.SCRoutes.USER_PROFILE_ROUTE_NAME, obj.author) }), { onClick: obj.author.deleted ? () => setOpenAlert(true) : null, className: classes.username }, { children: obj.author.username })), subheader: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({ to: scRoutingContext.url((0, contribution_1.getContributionRouteName)(obj), (0, contribution_1.getRouteData)(obj)), className: classes.activityAt }, { children: (0, jsx_runtime_1.jsx)(DateTimeAgo_1.default, { component: 'span', date: obj.added_at }) })), obj.location && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Bullet_1.default, {}), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ className: classes.location }, { children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { children: "add_location_alt" }), (_a = obj.location) === null || _a === void 0 ? void 0 : _a.location] }))] })), (0, jsx_runtime_1.jsx)(Bullet_1.default, {}), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.tag }, { children: obj.addressing.length > 0 ? ((0, jsx_runtime_1.jsx)(Tags_1.default, { tags: obj.addressing, TagChipProps: { disposable: false, clickable: false } })) : obj.group ? ((0, jsx_runtime_1.jsx)(material_1.Tooltip, Object.assign({ title: `${intl.formatMessage(messages.visibleToGroup, { group: obj.group.name })}` }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, Object.assign({ color: "disabled", fontSize: "small" }, { children: "groups" })) }))) : ((0, jsx_runtime_1.jsx)(material_1.Tooltip, Object.assign({ title: `${intl.formatMessage(messages.visibleToAll)}` }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, Object.assign({ color: "disabled", fontSize: "small" }, { children: "public" })) }))) }))] }), action: renderHeaderAction() }), (0, jsx_runtime_1.jsxs)(CardContent_1.default, Object.assign({ classes: { root: classes.content } }, { children: [(0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.titleSection }, { children: 'title' in obj && ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: template === feedObject_1.SCFeedObjectTemplateType.DETAIL ? ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body1", gutterBottom: true, className: classes.title }, { children: obj.title }))) : ((0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({ to: scRoutingContext.url((0, contribution_1.getContributionRouteName)(obj), (0, contribution_1.getRouteData)(obj)) }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body1", gutterBottom: true, className: classes.title }, { children: obj.title })) }))) })) })), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.textSection }, { children: getContributionSummary(obj, template) })), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.mediasSection }, { children: (0, jsx_runtime_1.jsx)(FeedObjectMediaPreview_1.default, Object.assign({ medias: obj.medias }, FeedObjectMediaPreviewProps)) })), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.pollsSection }, { children: obj['poll'] && ((0, jsx_runtime_1.jsx)(Poll_1.default, Object.assign({ visible: pollVisible || template === feedObject_1.SCFeedObjectTemplateType.DETAIL || Boolean(obj.type !== types_1.SCContributionType.DISCUSSION && !obj.html && !obj.medias.length), feedObject: obj, pollObject: obj['poll'], onChange: handleChangePoll, onToggleVisibility: handleTogglePollVisibility }, PollObjectProps))) })), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.infoSection }, { children: (0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ direction: "row", justifyContent: "space-between", alignItems: "center", spacing: 2 }, { children: [!hideParticipantsPreview && ((0, jsx_runtime_1.jsx)(Contributors_1.default, Object.assign({ feedObject: obj, feedObjectType: obj.type }, ContributorsFeedObjectProps, { cacheStrategy: cacheStrategy }))), !_hideFollowAction && (0, jsx_runtime_1.jsx)(Follow_1.default, Object.assign({ feedObject: obj, feedObjectType: obj.type, handleFollow: handleFollow }, FollowButtonProps))] })) }))] })), (0, jsx_runtime_1.jsxs)(material_1.CardActions, Object.assign({ className: classes.actionsSection }, { children: [(0, jsx_runtime_1.jsx)(Actions_1.default, Object.assign({ feedObjectId: feedObjectId, feedObjectType: feedObjectType, feedObject: obj, hideCommentAction: template === feedObject_1.SCFeedObjectTemplateType.DETAIL || (hasEvent && !((_c = (_b = obj === null || obj === void 0 ? void 0 : obj.medias[0].embed) === null || _b === void 0 ? void 0 : _b.metadata) === null || _c === void 0 ? void 0 : _c.active)), handleExpandActivities: template === feedObject_1.SCFeedObjectTemplateType.PREVIEW ? handleExpandActivities : null, VoteActionProps: { onVoteAction: handleVoteSuccess } }, ActionsProps)), ((template === feedObject_1.SCFeedObjectTemplateType.DETAIL && (!hasEvent || ((_h = (_g = (_f = (_d = obj === null || obj === void 0 ? void 0 : obj.medias) === null || _d === void 0 ? void 0 : _d[0]) === null || _f === void 0 ? void 0 : _f.embed) === null || _g === void 0 ? void 0 : _g.metadata) === null || _h === void 0 ? void 0 : _h.active))) || expandedActivities) && ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.replyContent }, { children: (0, jsx_runtime_1.jsx)(CommentObjectReplyComponent, Object.assign({ id: `reply-feedObject-${obj.id}`, onReply: handleReply, editable: !isReplying || Boolean(obj) }, CommentObjectReplyComponentProps), Number(isReplying)) })))] })), template === feedObject_1.SCFeedObjectTemplateType.PREVIEW && (obj.comment_count > 0 || (feedObjectActivities && feedObjectActivities.length > 0)) && ((0, jsx_runtime_1.jsx)(material_1.Collapse, Object.assign({ in: expandedActivities, timeout: "auto", classes: { root: classes.activitiesSection } }, { children: (0, jsx_runtime_1.jsx)(CardContent_1.default, Object.assign({ className: classes.activitiesContent }, { children: (0, jsx_runtime_1.jsx)(Activities_1.default, Object.assign({ feedObject: obj, feedObjectActivities: feedObjectActivities, activitiesType: selectedActivities, onSetSelectedActivities: handleSelectedActivities, comments: comments, CommentsObjectProps: { CommentComponentProps: Object.assign({ onDelete: handleDeleteComment, truncateContent: true, CommentsObjectComponentProps: { inPlaceLoadMoreContents: false } }, CommentComponentProps), CommentObjectSkeletonProps: CommentObjectSkeletonProps }, cacheStrategy: cacheStrategy }, ActivitiesProps), selectedActivities) })) }))), composerOpen && ((0, jsx_runtime_1.jsx)(Composer_1.default, { open: composerOpen, feedObject: obj, onClose: handleToggleEdit, onSuccess: handleEditSuccess, maxWidth: "sm", fullWidth: true }))] }))) : ((0, jsx_runtime_1.jsx)(Skeleton_1.default, Object.assign({ template: template }, FeedObjectSkeletonProps))) })); } else if (template === feedObject_1.SCFeedObjectTemplateType.SHARE) { objElement = ((0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: obj ? ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [obj.categories.length > 0 && ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: classes.category }, { children: [(0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [obj.group && ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: classes.group }, { children: (0, jsx_runtime_1.jsx)(material_1.Chip, { color: "secondary", size: "small", icon: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "groups" }), component: react_core_1.Link, to: scRoutingContext.url(react_core_1.SCRoutes.GROUP_ROUTE_NAME, obj.group), clickable: true }, obj.group.id) }))), obj.event && ((0, jsx_runtime_1.jsx)(material_1.Chip, { className: classes.event, color: "secondary", size: "small", icon: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "CalendarIcon" }), component: react_core_1.Link, to: scRoutingContext.url(react_core_1.SCRoutes.EVENT_ROUTE_NAME, obj.event), clickable: true }, obj.event.id))] }), obj.categories.map((c) => ((0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({ to: scRoutingContext.url(react_core_1.SCRoutes.CATEGORY_ROUTE_NAME, c) }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "overline" }, { children: c.name })) }), c.id)))] }))), obj.group && !obj.categories.length && ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: classes.group }, { children: (0, jsx_runtime_1.jsx)(material_1.Chip, { color: "secondary", size: "small", icon: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "groups" }), label: obj.group.name, component: react_core_1.Link, to: scRoutingContext.url(react_core_1.SCRoutes.GROUP_ROUTE_NAME, obj.group), clickable: true }, obj.group.id) }))), obj.event && !obj.categories.length && ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: classes.event }, { children: (0, jsx_runtime_1.jsx)(material_1.Chip, { color: "secondary", size: "small", icon: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "groups" }), label: obj.event.name, component: react_core_1.Link, to: scRoutingContext.url(react_core_1.SCRoutes.EVENT_ROUTE_NAME, obj.event), clickable: true }, obj.event.id) }))), (0, jsx_runtime_1.jsx)(material_1.CardHeader, { classes: { root: classes.header }, avatar: (0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({}, (!obj.author.deleted && { to: scRoutingContext.url(react_core_1.SCRoutes.USER_PROFILE_ROUTE_NAME, obj.author) }), { onClick: obj.author.deleted ? () => setOpenAlert(true) : null, className: classes.username }, { children: (0, jsx_runtime_1.jsx)(UserAvatar_1.default, Object.assign({ hide: !obj.author.community_badge }, { children: (0, jsx_runtime_1.jsx)(material_1.Avatar, Object.assign({ "aria-label": "recipe", src: obj.author.avatar, className: classes.avatar }, { children: obj.author.username })) })) })), title: (0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({}, (!obj.author.deleted && { to: scRoutingContext.url(react_core_1.SCRoutes.USER_PROFILE_ROUTE_NAME, obj.author) }), { onClick: obj.author.deleted ? () => setOpenAlert(true) : null, className: classes.username }, { children: obj.author.username })), subheader: (0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({ to: scRoutingContext.url((0, contribution_1.getContributionRouteName)(obj), (0, contribution_1.getRouteData)(obj)), className: classes.activityAt }, { children: (0, jsx_runtime_1.jsx)(DateTimeAgo_1.default, { date: obj.added_at }) })) }), (0, jsx_runtime_1.jsxs)(CardContent_1.default, Object.assign({ classes: { root: classes.content } }, { children: [(0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.titleSection }, { children: 'title' in obj && ((0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({ to: scRoutingContext.url((0, contribution_1.getContributionRouteName)(obj), (0, contribution_1.getRouteData)(obj)) }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body1", gutterBottom: true, className: classes.title }, { children: obj.title })) }))) })), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.textSection }, { children: getContributionSummary(obj, template) })), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.mediasSection }, { children: (0, jsx_runtime_1.jsx)(FeedObjectMediaPreview_1.default, Object.assign({ medias: obj.medias }, FeedObjectMediaPreviewProps)) })), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.pollsSection }, { children: obj['poll'] && ((0, jsx_runtime_1.jsx)(Poll_1.default, Object.assign({ feedObject: obj, pollObject: obj['poll'], onChange: handleChangePoll, visible: Boolean(obj.type !== types_1.SCContributionType.DISCUSSION && !obj.html && !obj.medias.length) }, PollObjectProps))) }))] }))] })) : ((0, jsx_runtime_1.jsx)(Skeleton_1.default, Object.assign({ template: template }, FeedObjectSkeletonProps))) })); } else { objElement = ((0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: obj ? ((0, jsx_runtime_1.jsx)(BaseItem_1.default, { elevation: 0, className: classes.snippet, image: (0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({}, (!obj.author.deleted && { to: scRoutingContext.url(react_core_1.SCRoutes.USER_PROFILE_ROUTE_NAME, obj.author) }), { onClick: obj.author.deleted ? () => setOpenAlert(true) : null }, { children: (0, jsx_runtime_1.jsx)(UserAvatar_1.default, Object.assign({ hide: !obj.author.community_badge }, { children: (0, jsx_runtime_1.jsx)(material_1.Avatar, { alt: obj.author.username, variant: "circular", src: obj.author.avatar, className: classes.avatar }) })) })), primary: (0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({}, (!obj.author.deleted && { to: scRoutingContext.url(react_core_1.SCRoutes.USER_PROFILE_ROUTE_NAME, obj.author) }), { onClick: obj.author.deleted ? () => setOpenAlert(true) : null, className: classes.username }, { children: obj.author.username })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2", className: classes.snippetContent }, { children: (0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({ to: scRoutingContext.url((0, contribution_1.getContributionRouteName)(obj), (0, contribution_1.getRouteData)(obj)) }, { children: (0, contribution_1.getContributionSnippet)(obj) })) }))] }), disableTypography: true, secondary: (0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ direction: "row", justifyContent: "space-between", spacing: 2, alignItems: "center" }, { children: [(0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({ to: scRoutingContext.url((0, contribution_1.getContributionRouteName)(obj), (0, contribution_1.getRouteData)(obj)), className: classes.activityAt }, { children: (0, jsx_runtime_1.jsx)(DateTimeAgo_1.default, { component: "span", date: obj.added_at }) })), (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ component: react_core_1.Link, to: scRoutingContext.url((0, contribution_1.getContributionRouteName)(obj), (0, contribution_1.getRouteData)(obj)), variant: "text", color: "secondary", size: "small" }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.feedObject.comment", defaultMessage: "ui.feedObject.comment" }) }))] })) })) : ((0, jsx_runtime_1.jsx)(Skeleton_1.default, Object.assign({}, FeedObjectSkeletonProps))) })); } /** * Renders root object */ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(Root, Object.assign({ id: id, className: (0, classnames_1.default)(classes.root, className, `${constants_1.PREFIX}-${template}`) }, rest, { children: [obj && markRead && (0, jsx_runtime_1.jsx)(MarkRead_1.default, { endpoint: api_services_1.Endpoints.FeedObjectMarkRead, data: { object: [obj.id] } }), objElement] })), openAlert && (0, jsx_runtime_1.jsx)(UserDeletedSnackBar_1.default, { open: openAlert, handleClose: () => setOpenAlert(false) })] })); } exports.default = FeedObject;