@selfcommunity/react-templates
Version:
React Templates Components to integrate a Community created with SelfCommunity.
127 lines (120 loc) • 4.47 kB
JavaScript
;
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 constants_1 = require("./constants");
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.FeedUpdatesWidget,
componentProps: { subscriptionChannel: types_1.SCNotificationTopicType.INTERACTION, publicationChannel: 'notifications_feed' },
column: 'left',
position: 0,
publishEvents: true
},
{
type: 'widget',
component: react_ui_1.BroadcastMessages,
componentProps: { subscriptionChannel: 'notification_feed' },
column: 'left',
position: 0
},
{
type: 'widget',
component: react_ui_1.PlatformWidget,
componentProps: {},
column: 'right',
position: 0
},
{
type: 'widget',
component: react_ui_1.LoyaltyProgramWidget,
componentProps: {},
column: 'right',
position: 1
},
{
type: 'widget',
component: react_ui_1.CategoriesSuggestionWidget,
componentProps: {},
column: 'right',
position: 2
},
{
type: 'widget',
component: react_ui_1.UserSuggestionWidget,
componentProps: {},
column: 'right',
position: 3
}
];
/**
* > API documentation for the Community-JS Notification Feed Template. Learn about the available props and the CSS API.
*
*
* This component renders the template for the notification feed.
* Take a look at our <strong>demo</strong> component [here](/docs/sdk/community-js/react-templates/Components/NotificationFeed)
#### Import
```jsx
import {NotificationFeed} from '@selfcommunity/react-templates';
```
#### Component Name
The name `SCNotificationFeedTemplate` can be used when providing style overrides in the theme.
#### CSS
|Rule Name|Global class|Description|
|---|---|---|
|root|.SCNotificationFeedTemplate-root|Styles applied to the root element.|
*
* @param inProps
*/
function NotificationFeed(inProps) {
// PROPS
const props = (0, system_1.useThemeProps)({
props: inProps,
name: constants_1.PREFIX
});
const { id = 'notification_feed', className, widgets = WIDGETS, NotificationProps = {}, FeedSidebarProps = null, FeedProps = {} } = props;
//CONTEXT
const scUserContext = (0, react_1.useContext)(react_core_1.SCUserContext);
// Ckeck user is authenticated
if (!scUserContext.user) {
return null;
}
/**
* Update user unseen notification counter
* @param page
* @param offset
* @param total
* @param data
*/
const handleFetchData = (page, offset, total, data) => {
let _unviewed = (0, react_ui_1.getUnseenNotificationCounter)(data);
_unviewed > 0 && scUserContext.setUnseenInteractionsCounter(scUserContext.user.unseen_interactions_counter - _unviewed);
if (!_unviewed) {
// Sync counters
void scUserContext.refreshCounters();
}
};
return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ id: id, className: (0, classnames_1.default)(classes.root, className), endpoint: api_services_1.Endpoints.UserNotificationList, widgets: widgets, ItemComponent: react_ui_1.Notification, itemPropsGenerator: (scUser, item) => ({
notificationObject: item
}), itemIdGenerator: (item) => item.sid, ItemProps: NotificationProps, ItemSkeleton: react_ui_1.NotificationSkeleton, ItemSkeletonProps: {
template: react_ui_1.SCFeedObjectTemplateType.PREVIEW
}, FeedSidebarProps: FeedSidebarProps, requireAuthentication: true, disablePaginationLinks: true, onNextData: handleFetchData, onPreviousData: handleFetchData }, FeedProps)));
}
exports.default = NotificationFeed;