@selfcommunity/react-templates
Version:
React Templates Components to integrate a Community created with SelfCommunity.
156 lines (149 loc) • 7.83 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const material_1 = require("@mui/material");
const react_ui_1 = require("@selfcommunity/react-ui");
const api_services_1 = require("@selfcommunity/api-services");
const react_core_1 = require("@selfcommunity/react-core");
const types_1 = require("@selfcommunity/types");
const system_1 = require("@mui/system");
const classnames_1 = tslib_1.__importDefault(require("classnames"));
const react_intl_1 = require("react-intl");
const notistack_1 = require("notistack");
const constants_1 = require("./constants");
const Skeleton_1 = tslib_1.__importDefault(require("./Skeleton"));
const classes = {
root: `${constants_1.PREFIX}-root`
};
const Root = (0, material_1.styled)(react_ui_1.Feed, {
name: constants_1.PREFIX,
slot: 'Root'
})(() => ({}));
// Widgets for feed
const WIDGETS = [
{
type: 'widget',
component: react_ui_1.EventLocationWidget,
componentProps: {},
column: 'right',
position: 0
},
{
type: 'widget',
component: react_ui_1.EventMembersWidget,
componentProps: {},
column: 'right',
position: 1
},
{
type: 'widget',
component: react_ui_1.EventMediaWidget,
componentProps: {},
column: 'right',
position: 2
},
{
type: 'widget',
component: react_ui_1.RelatedEventsWidget,
componentProps: {},
column: 'right',
position: 3
}
];
/**
* > API documentation for the Community-JS Group Feed Template. Learn about the available props and the CSS API.
*
*
* This component renders a specific event's feed.
#### Import
```jsx
import {EventFeed} from '@selfcommunity/react-templates';
```
#### Component Name
The name `SCEventFeedTemplate` can be used when providing style overrides in the theme.
#### CSS
|Rule Name|Global class|Description|
|---|---|---|
|root|.SCEventFeedTemplate-root|Styles applied to the root element.|
*
* @param inProps
*/
function EventFeed(inProps) {
// PROPS
const props = (0, system_1.useThemeProps)({
props: inProps,
name: constants_1.PREFIX
});
const { id = 'event_feed', className, event, eventId, widgets = WIDGETS, FeedObjectProps = {}, FeedSidebarProps = null, FeedProps = {} } = props;
// CONTEXT
const scRoutingContext = (0, react_core_1.useSCRouting)();
const scUserContext = (0, react_core_1.useSCUser)();
const { enqueueSnackbar } = (0, notistack_1.useSnackbar)();
// REF
const feedRef = (0, react_1.useRef)();
// Hooks
const { scEvent } = (0, react_core_1.useSCFetchEvent)({ id: eventId, event });
// HANDLERS
const handleComposerSuccess = (feedObject) => {
var _a;
enqueueSnackbar((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composerIconButton.composer.success", defaultMessage: "ui.composerIconButton.composer.success" }), {
action: () => ((0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({ to: scRoutingContext.url(react_core_1.SCRoutes[`${feedObject.type.toUpperCase()}_ROUTE_NAME`], react_ui_1.ContributionUtils.getRouteData(feedObject)) }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composerIconButton.composer.viewContribute", defaultMessage: "ui.composerIconButton.composer.viewContribute" }) }))),
variant: 'success',
autoHideDuration: 7000
});
if (((_a = feedObject.event) === null || _a === void 0 ? void 0 : _a.id) === scEvent.id) {
// Hydrate feedUnit
const feedUnit = {
type: feedObject.type,
[feedObject.type]: feedObject,
seen_by_id: [],
has_boost: false
};
feedRef && feedRef.current && feedRef.current.addFeedData(feedUnit, true);
}
};
// WIDGETS
const _widgets = (0, react_1.useMemo)(() => widgets.map((w) => {
if (scEvent) {
return Object.assign(Object.assign({}, w), { componentProps: Object.assign(Object.assign({}, w.componentProps), { event: scEvent }) });
}
return w;
}), [widgets, scEvent]);
if (scUserContext.user === undefined ||
!scEvent ||
(scUserContext.user &&
((scEvent.privacy === types_1.SCEventPrivacyType.PUBLIC && !scEvent.subscription_status) ||
scEvent.subscription_status === types_1.SCEventSubscriptionStatusType.INVITED)) ||
(scEvent && ((eventId !== undefined && scEvent.id !== eventId) || (event && scEvent.id !== event.id)))) {
return (0, jsx_runtime_1.jsx)(Skeleton_1.default, {});
}
else if (scEvent.privacy === types_1.SCEventPrivacyType.PRIVATE &&
scEvent.subscription_status !== types_1.SCEventSubscriptionStatusType.SUBSCRIBED &&
scEvent.subscription_status !== types_1.SCEventSubscriptionStatusType.GOING &&
scEvent.subscription_status !== types_1.SCEventSubscriptionStatusType.NOT_GOING) {
return ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ mt: 2 }, { children: (0, jsx_runtime_1.jsx)(react_ui_1.EventInfoWidget, { className: classes.root, event: scEvent }) })));
}
return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className), id: id, ref: feedRef, endpoint: Object.assign(Object.assign({}, api_services_1.Endpoints.GetEventFeed), { url: () => api_services_1.Endpoints.GetEventFeed.url({ id: scEvent.id }) }), widgets: _widgets, ItemComponent: react_ui_1.FeedObject, itemPropsGenerator: (scUser, item) => {
var _a;
return ({
feedObject: item[item.type],
feedObjectType: item.type,
feedObjectActivities: item.activities ? item.activities : null,
markRead: scUser ? !((_a = item === null || item === void 0 ? void 0 : item.seen_by_id) === null || _a === void 0 ? void 0 : _a.includes(scUser.id)) : null
});
}, itemIdGenerator: (item) => item[item.type].id, ItemProps: FeedObjectProps, ItemSkeleton: react_ui_1.FeedObjectSkeleton, ItemSkeletonProps: {
template: react_ui_1.SCFeedObjectTemplateType.PREVIEW
}, FeedSidebarProps: FeedSidebarProps, HeaderComponent: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_ui_1.EventInfoWidget, { className: classes.root, event: scEvent }), Boolean(scEvent &&
((!scUserContext.user && scEvent.privacy === types_1.SCEventPrivacyType.PUBLIC) ||
(scUserContext.user &&
(scEvent.subscription_status === types_1.SCEventSubscriptionStatusType.SUBSCRIBED ||
scEvent.subscription_status === types_1.SCEventSubscriptionStatusType.GOING ||
scEvent.subscription_status === types_1.SCEventSubscriptionStatusType.NOT_GOING)))) && ((0, jsx_runtime_1.jsx)(react_ui_1.InlineComposerWidget, { onSuccess: handleComposerSuccess, defaultValue: { event: scEvent }, label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "templates.eventFeed.composer.label", defaultMessage: "templates.eventFeed.composer.label" }), feedType: types_1.SCFeedTypologyType.EVENT }))] }), CustomAdvProps: { position: types_1.SCCustomAdvPosition.POSITION_FEED, groupsId: [scEvent.id] }, enabledCustomAdvPositions: [
types_1.SCCustomAdvPosition.POSITION_FEED_SIDEBAR,
types_1.SCCustomAdvPosition.POSITION_FEED,
types_1.SCCustomAdvPosition.POSITION_BELOW_TOPBAR
] }, FeedProps)));
}
exports.default = EventFeed;