@selfcommunity/react-templates 0.5.0-alpha.5 → 0.5.0-alpha.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/components/CategoryFeed/CategoryFeed.js +24 -6
- package/lib/cjs/components/EventFeed/EventFeed.js +35 -23
- package/lib/cjs/components/ExploreFeed/ExploreFeed.js +20 -7
- package/lib/cjs/components/FeedObjectDetail/FeedObjectDetail.js +4 -2
- package/lib/cjs/components/GroupFeed/GroupFeed.js +28 -16
- package/lib/cjs/components/MainFeed/MainFeed.js +19 -6
- package/lib/cjs/components/UserFeed/UserFeed.js +5 -4
- package/lib/cjs/components/UserProfile/UserProfile.js +5 -2
- package/lib/esm/components/CategoryFeed/CategoryFeed.js +28 -10
- package/lib/esm/components/EventFeed/EventFeed.js +36 -24
- package/lib/esm/components/ExploreFeed/ExploreFeed.js +22 -9
- package/lib/esm/components/FeedObjectDetail/FeedObjectDetail.js +4 -2
- package/lib/esm/components/GroupFeed/GroupFeed.js +30 -18
- package/lib/esm/components/MainFeed/MainFeed.js +21 -8
- package/lib/esm/components/UserFeed/UserFeed.js +5 -4
- package/lib/esm/components/UserProfile/UserProfile.js +5 -2
- package/lib/umd/{c473ce30406a3dad83e1.eot → 30b299174b4fa1fb9ce8.eot} +0 -0
- package/lib/umd/{b6dbec3d5816ff8baef1.woff → 3b49304a98beb1239bc7.ttf} +0 -0
- package/lib/umd/519.js +2 -0
- package/lib/umd/738.js +1 -1
- package/lib/umd/73cbb3dbfaa3ddd4df47.js +2 -0
- package/lib/umd/73cbb3dbfaa3ddd4df47.js.LICENSE.txt +21 -0
- package/lib/umd/ab247f43e550f5f6d0f8.woff2 +0 -0
- package/lib/umd/{ba74e493633796d551d1.ttf → ce10db0c87e7112cb315.woff} +0 -0
- package/lib/umd/{6158171e38cbff3c3340.svg → fff8590360ed9eed64ae.svg} +75 -69
- package/lib/umd/react-templates.js +1 -1
- package/package.json +9 -6
- package/lib/umd/60a7fdeaadfe844bc015.woff2 +0 -0
- package/lib/umd/916.js +0 -2
- /package/lib/umd/{916.js.LICENSE.txt → 519.js.LICENSE.txt} +0 -0
|
@@ -64,6 +64,7 @@ const WIDGETS = [
|
|
|
64
64
|
* @param inProps
|
|
65
65
|
*/
|
|
66
66
|
function CategoryFeed(inProps) {
|
|
67
|
+
var _a;
|
|
67
68
|
// PROPS
|
|
68
69
|
const props = (0, system_1.useThemeProps)({
|
|
69
70
|
props: inProps,
|
|
@@ -78,12 +79,26 @@ function CategoryFeed(inProps) {
|
|
|
78
79
|
const feedRef = (0, react_1.useRef)();
|
|
79
80
|
// Hooks
|
|
80
81
|
const { scCategory } = (0, react_core_1.useSCFetchCategory)({ id: categoryId, category });
|
|
82
|
+
const isAdvertisingCustomAdvEnabled = (0, react_core_1.useSCPreferenceEnabled)(react_core_1.SCPreferences.ADVERTISING_CUSTOM_ADV_ENABLED);
|
|
83
|
+
const isAdvertisingCustomAdvOnlyForAnonUsersEnabled = (0, react_core_1.useSCPreferenceEnabled)(react_core_1.SCPreferences.ADVERTISING_CUSTOM_ADV_ONLY_FOR_ANONYMOUS_USERS_ENABLED);
|
|
84
|
+
const isPaymentsEnabled = (0, react_core_1.useSCPreferencesAndFeaturesEnabled)([react_core_1.SCPreferences.CONFIGURATIONS_PAYMENTS_ENABLED], [types_1.SCFeatureName.PAYMENTS]);
|
|
85
|
+
/**
|
|
86
|
+
* Render advertising above the feed
|
|
87
|
+
*/
|
|
88
|
+
function renderAdvertising() {
|
|
89
|
+
if (isAdvertisingCustomAdvEnabled &&
|
|
90
|
+
((isAdvertisingCustomAdvOnlyForAnonUsersEnabled && scUserContext.user === null) || !isAdvertisingCustomAdvOnlyForAnonUsersEnabled)) {
|
|
91
|
+
return (0, jsx_runtime_1.jsx)(react_ui_1.CustomAdv, { position: types_1.SCCustomAdvPosition.POSITION_ABOVE_FEED, categoriesId: [scCategory.id] });
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
81
95
|
// HANDLERS
|
|
82
96
|
const handleComposerSuccess = (feedObject) => {
|
|
83
97
|
// Not insert if the category does not match
|
|
84
98
|
if (feedObject.categories.findIndex((c) => c.id === scCategory.id) === -1) {
|
|
85
|
-
|
|
86
|
-
|
|
99
|
+
const messageId = feedObject.scheduled_at ? 'ui.composer.scheduled.success' : 'ui.composerIconButton.composer.success';
|
|
100
|
+
enqueueSnackbar((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: messageId, defaultMessage: messageId }), {
|
|
101
|
+
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" }) }))),
|
|
87
102
|
variant: 'success',
|
|
88
103
|
autoHideDuration: 7000
|
|
89
104
|
});
|
|
@@ -93,10 +108,10 @@ function CategoryFeed(inProps) {
|
|
|
93
108
|
const feedUnit = {
|
|
94
109
|
type: feedObject.type,
|
|
95
110
|
[feedObject.type]: feedObject,
|
|
96
|
-
|
|
111
|
+
seen: false,
|
|
97
112
|
has_boost: false
|
|
98
113
|
};
|
|
99
|
-
feedRef && feedRef.current && feedRef.current.addFeedData(feedUnit, true);
|
|
114
|
+
!feedObject.draft && feedRef && feedRef.current && feedRef.current.addFeedData(feedUnit, true);
|
|
100
115
|
};
|
|
101
116
|
// WIDGETS
|
|
102
117
|
const _widgets = (0, react_1.useMemo)(() => widgets.map((w) => {
|
|
@@ -108,14 +123,17 @@ function CategoryFeed(inProps) {
|
|
|
108
123
|
if (!scCategory) {
|
|
109
124
|
return (0, jsx_runtime_1.jsx)(index_1.CategoryFeedSkeleton, {});
|
|
110
125
|
}
|
|
126
|
+
else if (scCategory && isPaymentsEnabled && !scCategory.followed && !scCategory.payment_order && ((_a = scCategory.paywalls) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
127
|
+
return (0, jsx_runtime_1.jsx)(react_ui_1.HiddenPurchasableContent, {});
|
|
128
|
+
}
|
|
111
129
|
return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ id: id, className: (0, classnames_1.default)(classes.root, className), ref: feedRef, endpoint: Object.assign(Object.assign({}, api_services_1.Endpoints.CategoryFeed), { url: () => api_services_1.Endpoints.CategoryFeed.url({ id: scCategory.id }) }), widgets: _widgets, ItemComponent: react_ui_1.FeedObject, itemPropsGenerator: (scUser, item) => ({
|
|
112
130
|
feedObject: item[item.type],
|
|
113
131
|
feedObjectType: item.type,
|
|
114
132
|
feedObjectActivities: item.activities ? item.activities : null,
|
|
115
|
-
markRead: scUser ? !item.
|
|
133
|
+
markRead: scUser ? !item.seen : null
|
|
116
134
|
}), itemIdGenerator: (item) => item[item.type].id, ItemProps: FeedObjectProps, ItemSkeleton: react_ui_1.FeedObjectSkeleton, ItemSkeletonProps: {
|
|
117
135
|
template: react_ui_1.SCFeedObjectTemplateType.PREVIEW
|
|
118
|
-
}, FeedSidebarProps: FeedSidebarProps, HeaderComponent: (0, jsx_runtime_1.
|
|
136
|
+
}, FeedSidebarProps: FeedSidebarProps, HeaderComponent: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [((scCategory.content_only_staff && react_core_1.UserUtils.isStaff(scUserContext.user)) || !scCategory.content_only_staff) && ((0, jsx_runtime_1.jsx)(react_ui_1.InlineComposerWidget, { onSuccess: handleComposerSuccess, defaultValue: { categories: [scCategory] }, feedType: types_1.SCFeedTypologyType.CATEGORY })), renderAdvertising()] }), CustomAdvProps: { categoriesId: [scCategory.id] }, enabledCustomAdvPositions: [
|
|
119
137
|
types_1.SCCustomAdvPosition.POSITION_FEED_SIDEBAR,
|
|
120
138
|
types_1.SCCustomAdvPosition.POSITION_FEED,
|
|
121
139
|
types_1.SCCustomAdvPosition.POSITION_BELOW_TOPBAR
|
|
@@ -83,18 +83,33 @@ function EventFeed(inProps) {
|
|
|
83
83
|
name: constants_1.PREFIX
|
|
84
84
|
});
|
|
85
85
|
const { id = 'event_feed', className, event, eventId, widgets = WIDGETS, FeedObjectProps = {}, FeedSidebarProps = null, FeedProps = {} } = props;
|
|
86
|
+
// STATUS
|
|
87
|
+
const [status, setStatus] = (0, react_1.useState)(undefined);
|
|
86
88
|
// CONTEXT
|
|
87
89
|
const scRoutingContext = (0, react_core_1.useSCRouting)();
|
|
88
90
|
const scUserContext = (0, react_core_1.useSCUser)();
|
|
91
|
+
const scEventsManager = scUserContext.managers.events;
|
|
89
92
|
const { enqueueSnackbar } = (0, notistack_1.useSnackbar)();
|
|
93
|
+
const { scEvent } = (0, react_core_1.useSCFetchEvent)({ id: eventId, event });
|
|
90
94
|
// REF
|
|
91
95
|
const feedRef = (0, react_1.useRef)();
|
|
92
|
-
//
|
|
93
|
-
const
|
|
96
|
+
// CONST
|
|
97
|
+
const authUserId = scUserContext.user ? scUserContext.user.id : null;
|
|
98
|
+
(0, react_1.useEffect)(() => {
|
|
99
|
+
var _a;
|
|
100
|
+
/**
|
|
101
|
+
* Call scEventsManager.subscriptionStatus inside an effect
|
|
102
|
+
* to avoid warning rendering child during update parent state
|
|
103
|
+
*/
|
|
104
|
+
if (authUserId) {
|
|
105
|
+
setStatus((_a = scEventsManager === null || scEventsManager === void 0 ? void 0 : scEventsManager.subscriptionStatus) === null || _a === void 0 ? void 0 : _a.call(scEventsManager, scEvent));
|
|
106
|
+
}
|
|
107
|
+
}, [authUserId, scEventsManager === null || scEventsManager === void 0 ? void 0 : scEventsManager.subscriptionStatus, scEvent]);
|
|
94
108
|
// HANDLERS
|
|
95
109
|
const handleComposerSuccess = (feedObject) => {
|
|
96
110
|
var _a;
|
|
97
|
-
|
|
111
|
+
const messageId = feedObject.scheduled_at ? 'ui.composer.scheduled.success' : 'ui.composerIconButton.composer.success';
|
|
112
|
+
enqueueSnackbar((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: messageId, defaultMessage: messageId }), {
|
|
98
113
|
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" }) }))),
|
|
99
114
|
variant: 'success',
|
|
100
115
|
autoHideDuration: 7000
|
|
@@ -104,10 +119,10 @@ function EventFeed(inProps) {
|
|
|
104
119
|
const feedUnit = {
|
|
105
120
|
type: feedObject.type,
|
|
106
121
|
[feedObject.type]: feedObject,
|
|
107
|
-
|
|
122
|
+
seen: false,
|
|
108
123
|
has_boost: false
|
|
109
124
|
};
|
|
110
|
-
feedRef && feedRef.current && feedRef.current.addFeedData(feedUnit, true);
|
|
125
|
+
!feedObject.draft && feedRef && feedRef.current && feedRef.current.addFeedData(feedUnit, true);
|
|
111
126
|
}
|
|
112
127
|
};
|
|
113
128
|
// WIDGETS
|
|
@@ -118,35 +133,32 @@ function EventFeed(inProps) {
|
|
|
118
133
|
return w;
|
|
119
134
|
}), [widgets, scEvent]);
|
|
120
135
|
if (scUserContext.user === undefined ||
|
|
136
|
+
(scUserContext.user && status === undefined) ||
|
|
121
137
|
!scEvent ||
|
|
122
|
-
(scUserContext.user &&
|
|
123
|
-
((scEvent.privacy === types_1.SCEventPrivacyType.PUBLIC && !scEvent.subscription_status) ||
|
|
124
|
-
scEvent.subscription_status === types_1.SCEventSubscriptionStatusType.INVITED)) ||
|
|
138
|
+
(scUserContext.user && scEvent.privacy === types_1.SCEventPrivacyType.PUBLIC && !status) ||
|
|
125
139
|
(scEvent && ((eventId !== undefined && scEvent.id !== eventId) || (event && scEvent.id !== event.id)))) {
|
|
126
140
|
return (0, jsx_runtime_1.jsx)(Skeleton_1.default, {});
|
|
127
141
|
}
|
|
128
142
|
else if (scEvent.privacy === types_1.SCEventPrivacyType.PRIVATE &&
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
143
|
+
(status === types_1.SCEventSubscriptionStatusType.INVITED ||
|
|
144
|
+
(status !== types_1.SCEventSubscriptionStatusType.SUBSCRIBED &&
|
|
145
|
+
status !== types_1.SCEventSubscriptionStatusType.GOING &&
|
|
146
|
+
status !== types_1.SCEventSubscriptionStatusType.NOT_GOING))) {
|
|
132
147
|
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 }) })));
|
|
133
148
|
}
|
|
134
|
-
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) => {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
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
|
|
141
|
-
});
|
|
142
|
-
}, itemIdGenerator: (item) => item[item.type].id, ItemProps: FeedObjectProps, ItemSkeleton: react_ui_1.FeedObjectSkeleton, ItemSkeletonProps: {
|
|
149
|
+
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) => ({
|
|
150
|
+
feedObject: item[item.type],
|
|
151
|
+
feedObjectType: item.type,
|
|
152
|
+
feedObjectActivities: item.activities ? item.activities : null,
|
|
153
|
+
markRead: scUser ? !(item === null || item === void 0 ? void 0 : item.seen) : null
|
|
154
|
+
}), itemIdGenerator: (item) => item[item.type].id, ItemProps: FeedObjectProps, ItemSkeleton: react_ui_1.FeedObjectSkeleton, ItemSkeletonProps: {
|
|
143
155
|
template: react_ui_1.SCFeedObjectTemplateType.PREVIEW
|
|
144
156
|
}, 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 &&
|
|
145
157
|
((!scUserContext.user && scEvent.privacy === types_1.SCEventPrivacyType.PUBLIC) ||
|
|
146
158
|
(scUserContext.user &&
|
|
147
|
-
(
|
|
148
|
-
|
|
149
|
-
|
|
159
|
+
(status === types_1.SCEventSubscriptionStatusType.SUBSCRIBED ||
|
|
160
|
+
status === types_1.SCEventSubscriptionStatusType.GOING ||
|
|
161
|
+
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: [
|
|
150
162
|
types_1.SCCustomAdvPosition.POSITION_FEED_SIDEBAR,
|
|
151
163
|
types_1.SCCustomAdvPosition.POSITION_FEED,
|
|
152
164
|
types_1.SCCustomAdvPosition.POSITION_BELOW_TOPBAR
|
|
@@ -84,13 +84,26 @@ function ExploreFeed(inProps) {
|
|
|
84
84
|
});
|
|
85
85
|
const { id = 'explore_feed', className, widgets = WIDGETS, FeedObjectProps = {}, FeedSidebarProps = null, FeedProps = {} } = props;
|
|
86
86
|
// CONTEXT
|
|
87
|
-
const { enqueueSnackbar } = (0, notistack_1.useSnackbar)();
|
|
88
87
|
const scUserContext = (0, react_1.useContext)(react_core_1.SCUserContext);
|
|
88
|
+
const isAdvertisingCustomAdvEnabled = (0, react_core_1.useSCPreferenceEnabled)(react_core_1.SCPreferences.ADVERTISING_CUSTOM_ADV_ENABLED);
|
|
89
|
+
const isAdvertisingCustomAdvOnlyForAnonUsersEnabled = (0, react_core_1.useSCPreferenceEnabled)(react_core_1.SCPreferences.ADVERTISING_CUSTOM_ADV_ONLY_FOR_ANONYMOUS_USERS_ENABLED);
|
|
90
|
+
const { enqueueSnackbar } = (0, notistack_1.useSnackbar)();
|
|
89
91
|
// REF
|
|
90
92
|
const feedRef = (0, react_1.useRef)();
|
|
93
|
+
/**
|
|
94
|
+
* Render advertising above the feed
|
|
95
|
+
*/
|
|
96
|
+
function renderAdvertising() {
|
|
97
|
+
if (isAdvertisingCustomAdvEnabled &&
|
|
98
|
+
((isAdvertisingCustomAdvOnlyForAnonUsersEnabled && scUserContext.user === null) || !isAdvertisingCustomAdvOnlyForAnonUsersEnabled)) {
|
|
99
|
+
return (0, jsx_runtime_1.jsx)(react_ui_1.CustomAdv, { position: types_1.SCCustomAdvPosition.POSITION_ABOVE_FEED });
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
91
103
|
// HANDLERS
|
|
92
104
|
const handleComposerSuccess = (feedObject) => {
|
|
93
|
-
|
|
105
|
+
const messageId = feedObject.scheduled_at ? 'ui.composer.scheduled.success' : 'ui.inlineComposerWidget.success';
|
|
106
|
+
enqueueSnackbar((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: messageId, defaultMessage: messageId }), {
|
|
94
107
|
variant: 'success',
|
|
95
108
|
autoHideDuration: 3000
|
|
96
109
|
});
|
|
@@ -98,10 +111,10 @@ function ExploreFeed(inProps) {
|
|
|
98
111
|
const feedUnit = {
|
|
99
112
|
type: feedObject.type,
|
|
100
113
|
[feedObject.type]: feedObject,
|
|
101
|
-
|
|
114
|
+
seen: false,
|
|
102
115
|
has_boost: false
|
|
103
116
|
};
|
|
104
|
-
feedRef && feedRef.current && feedRef.current.addFeedData(feedUnit, true);
|
|
117
|
+
!feedObject.draft && feedRef && feedRef.current && feedRef.current.addFeedData(feedUnit, true);
|
|
105
118
|
};
|
|
106
119
|
const handleAddGenerationContent = (feedObjects) => {
|
|
107
120
|
if (feedRef && feedRef.current) {
|
|
@@ -111,7 +124,7 @@ function ExploreFeed(inProps) {
|
|
|
111
124
|
const feedUnit = {
|
|
112
125
|
type: feedObject.type,
|
|
113
126
|
[feedObject.type]: feedObject,
|
|
114
|
-
|
|
127
|
+
seen: false,
|
|
115
128
|
has_boost: false
|
|
116
129
|
};
|
|
117
130
|
feedRef.current.addFeedData(feedUnit, true);
|
|
@@ -127,10 +140,10 @@ function ExploreFeed(inProps) {
|
|
|
127
140
|
feedObject: item[item.type],
|
|
128
141
|
feedObjectType: item.type,
|
|
129
142
|
feedObjectActivities: item.activities ? item.activities : null,
|
|
130
|
-
markRead: scUser ? !item.
|
|
143
|
+
markRead: scUser ? !item.seen : null
|
|
131
144
|
}), itemIdGenerator: (item) => item[item.type].id, ItemProps: FeedObjectProps, ItemSkeleton: react_ui_1.FeedObjectSkeleton, ItemSkeletonProps: {
|
|
132
145
|
template: react_ui_1.SCFeedObjectTemplateType.PREVIEW
|
|
133
|
-
}, HeaderComponent: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_ui_1.InlineComposerWidget, { onSuccess: handleComposerSuccess }), react_core_1.UserUtils.isAdmin(scUserContext.user) && (0, jsx_runtime_1.jsx)(react_ui_1.OnBoardingWidget, { onGeneratedContent: handleAddGenerationContent })] }), FeedSidebarProps: FeedSidebarProps, enabledCustomAdvPositions: [
|
|
146
|
+
}, HeaderComponent: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_ui_1.InlineComposerWidget, { onSuccess: handleComposerSuccess }), react_core_1.UserUtils.isAdmin(scUserContext.user) && (0, jsx_runtime_1.jsx)(react_ui_1.OnBoardingWidget, { onGeneratedContent: handleAddGenerationContent }), renderAdvertising()] }), FeedSidebarProps: FeedSidebarProps, enabledCustomAdvPositions: [
|
|
134
147
|
types_1.SCCustomAdvPosition.POSITION_FEED_SIDEBAR,
|
|
135
148
|
types_1.SCCustomAdvPosition.POSITION_FEED,
|
|
136
149
|
types_1.SCCustomAdvPosition.POSITION_BELOW_TOPBAR
|
|
@@ -56,8 +56,10 @@ function FeedObjectDetail(inProps) {
|
|
|
56
56
|
const scUserContext = (0, react_core_1.useSCUser)();
|
|
57
57
|
const scPreferences = (0, react_core_1.useSCPreferences)();
|
|
58
58
|
// RETRIVE OBJECTS
|
|
59
|
-
const { obj,
|
|
59
|
+
const { obj, error } = (0, react_core_1.useSCFetchFeedObject)({ id: feedObjectId, feedObject, feedObjectType });
|
|
60
60
|
const [comments, setComments] = (0, react_1.useState)([]);
|
|
61
|
+
const commentsEnabled = react_core_1.SCPreferences.CONFIGURATIONS_COMMENTS_ENABLED in scPreferences.preferences &&
|
|
62
|
+
scPreferences.preferences[react_core_1.SCPreferences.CONFIGURATIONS_COMMENTS_ENABLED].value;
|
|
61
63
|
/**
|
|
62
64
|
* Compute preferences
|
|
63
65
|
*/
|
|
@@ -96,6 +98,6 @@ function FeedObjectDetail(inProps) {
|
|
|
96
98
|
if (!obj) {
|
|
97
99
|
return (0, jsx_runtime_1.jsx)(Skeleton_1.default, {});
|
|
98
100
|
}
|
|
99
|
-
return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ id: id, className: (0, classnames_1.default)(classes.root, className) }, { children: (0, jsx_runtime_1.jsxs)(material_1.Grid, Object.assign({ container: true, spacing: 2 }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Grid, Object.assign({ item: true, xs: 12, md: 7 }, { children: [(0, jsx_runtime_1.jsx)(react_ui_1.FeedObject, Object.assign({}, FeedObjectProps, { feedObject: obj, template: react_ui_1.SCFeedObjectTemplateType.DETAIL, onReply: handleReply })), renderAdvertising(), (0, jsx_runtime_1.jsx)(react_ui_1.CommentsFeedObject, Object.assign({ showTitle: true, feedObject: obj, comments: comments }, CommentsFeedObjectProps), `comments_${obj.id}`)] })), (0, jsx_runtime_1.jsx)(material_1.Grid, Object.assign({ item: true, xs: 12, md: 5 }, { children: (0, jsx_runtime_1.jsx)(material_1.Hidden, Object.assign({ mdDown: true }, { children: (0, jsx_runtime_1.jsx)(react_ui_1.StickyBox, Object.assign({}, FeedSidebarProps, { children: (0, jsx_runtime_1.jsx)(react_ui_1.RelatedFeedObjectsWidget, Object.assign({ feedObject: obj, feedObjectId: obj.id }, RelatedFeedObjectProps), `related_${obj.id}`) })) })) }))] })) })));
|
|
101
|
+
return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ id: id, className: (0, classnames_1.default)(classes.root, className) }, { children: (0, jsx_runtime_1.jsxs)(material_1.Grid, Object.assign({ container: true, spacing: 2 }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Grid, Object.assign({ item: true, xs: 12, md: 7 }, { children: [(0, jsx_runtime_1.jsx)(react_ui_1.FeedObject, Object.assign({}, FeedObjectProps, { feedObject: obj, template: react_ui_1.SCFeedObjectTemplateType.DETAIL, onReply: handleReply })), renderAdvertising(), commentsEnabled && ((0, jsx_runtime_1.jsx)(react_ui_1.CommentsFeedObject, Object.assign({ showTitle: true, feedObject: obj, comments: comments }, CommentsFeedObjectProps), `comments_${obj.id}`))] })), (0, jsx_runtime_1.jsx)(material_1.Grid, Object.assign({ item: true, xs: 12, md: 5 }, { children: (0, jsx_runtime_1.jsx)(material_1.Hidden, Object.assign({ mdDown: true }, { children: (0, jsx_runtime_1.jsx)(react_ui_1.StickyBox, Object.assign({}, FeedSidebarProps, { children: (0, jsx_runtime_1.jsx)(react_ui_1.RelatedFeedObjectsWidget, Object.assign({ feedObject: obj, feedObjectId: obj.id }, RelatedFeedObjectProps), `related_${obj.id}`) })) })) }))] })) })));
|
|
100
102
|
}
|
|
101
103
|
exports.default = FeedObjectDetail;
|
|
@@ -69,18 +69,33 @@ function GroupFeed(inProps) {
|
|
|
69
69
|
name: constants_1.PREFIX
|
|
70
70
|
});
|
|
71
71
|
const { id = 'group_feed', className, group, groupId, widgets = WIDGETS, FeedObjectProps = {}, FeedSidebarProps = null, FeedProps = {} } = props;
|
|
72
|
+
// STATUS
|
|
73
|
+
const [status, setStatus] = (0, react_1.useState)(undefined);
|
|
72
74
|
// CONTEXT
|
|
73
75
|
const scRoutingContext = (0, react_core_1.useSCRouting)();
|
|
76
|
+
const scUserContext = (0, react_core_1.useSCUser)();
|
|
77
|
+
const scGroupsManager = scUserContext.managers.groups;
|
|
74
78
|
const { enqueueSnackbar } = (0, notistack_1.useSnackbar)();
|
|
79
|
+
const { scGroup } = (0, react_core_1.useSCFetchGroup)({ id: groupId, group });
|
|
75
80
|
// REF
|
|
76
81
|
const feedRef = (0, react_1.useRef)();
|
|
77
|
-
//
|
|
78
|
-
const
|
|
82
|
+
// CONST
|
|
83
|
+
const authUserId = scUserContext.user ? scUserContext.user.id : null;
|
|
84
|
+
(0, react_1.useEffect)(() => {
|
|
85
|
+
/**
|
|
86
|
+
* Call scGroupsManager.subscriptionStatus inside an effect
|
|
87
|
+
* to avoid warning rendering child during update parent state
|
|
88
|
+
*/
|
|
89
|
+
if (authUserId) {
|
|
90
|
+
setStatus(scGroupsManager.subscriptionStatus(scGroup));
|
|
91
|
+
}
|
|
92
|
+
}, [authUserId, scGroupsManager.subscriptionStatus, scGroup]);
|
|
79
93
|
// HANDLERS
|
|
80
94
|
const handleComposerSuccess = (feedObject) => {
|
|
81
95
|
var _a;
|
|
82
|
-
|
|
83
|
-
|
|
96
|
+
const messageId = feedObject.scheduled_at ? 'ui.composer.scheduled.success' : 'ui.composerIconButton.composer.success';
|
|
97
|
+
enqueueSnackbar((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: messageId, defaultMessage: messageId }), {
|
|
98
|
+
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" }) }))),
|
|
84
99
|
variant: 'success',
|
|
85
100
|
autoHideDuration: 7000
|
|
86
101
|
});
|
|
@@ -89,10 +104,10 @@ function GroupFeed(inProps) {
|
|
|
89
104
|
const feedUnit = {
|
|
90
105
|
type: feedObject.type,
|
|
91
106
|
[feedObject.type]: feedObject,
|
|
92
|
-
|
|
107
|
+
seen: false,
|
|
93
108
|
has_boost: false
|
|
94
109
|
};
|
|
95
|
-
feedRef && feedRef.current && feedRef.current.addFeedData(feedUnit, true);
|
|
110
|
+
!feedObject.draft && feedRef && feedRef.current && feedRef.current.addFeedData(feedUnit, true);
|
|
96
111
|
}
|
|
97
112
|
};
|
|
98
113
|
// WIDGETS
|
|
@@ -105,18 +120,15 @@ function GroupFeed(inProps) {
|
|
|
105
120
|
if (!scGroup) {
|
|
106
121
|
return (0, jsx_runtime_1.jsx)(Skeleton_1.default, {});
|
|
107
122
|
}
|
|
108
|
-
else if (scGroup &&
|
|
123
|
+
else if (scGroup && status !== types_1.SCGroupSubscriptionStatusType.SUBSCRIBED) {
|
|
109
124
|
return (0, jsx_runtime_1.jsx)(react_ui_1.GroupInfoWidget, { className: classes.root, groupId: scGroup === null || scGroup === void 0 ? void 0 : scGroup.id });
|
|
110
125
|
}
|
|
111
|
-
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.GetGroupFeed), { url: () => api_services_1.Endpoints.GetGroupFeed.url({ id: scGroup.id }) }), widgets: _widgets, ItemComponent: react_ui_1.FeedObject, itemPropsGenerator: (scUser, item) => {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
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
|
|
118
|
-
});
|
|
119
|
-
}, itemIdGenerator: (item) => item[item.type].id, ItemProps: FeedObjectProps, ItemSkeleton: react_ui_1.FeedObjectSkeleton, ItemSkeletonProps: {
|
|
126
|
+
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.GetGroupFeed), { url: () => api_services_1.Endpoints.GetGroupFeed.url({ id: scGroup.id }) }), widgets: _widgets, ItemComponent: react_ui_1.FeedObject, itemPropsGenerator: (scUser, item) => ({
|
|
127
|
+
feedObject: item[item.type],
|
|
128
|
+
feedObjectType: item.type,
|
|
129
|
+
feedObjectActivities: item.activities ? item.activities : null,
|
|
130
|
+
markRead: scUser ? !(item === null || item === void 0 ? void 0 : item.seen) : null
|
|
131
|
+
}), itemIdGenerator: (item) => item[item.type].id, ItemProps: FeedObjectProps, ItemSkeleton: react_ui_1.FeedObjectSkeleton, ItemSkeletonProps: {
|
|
120
132
|
template: react_ui_1.SCFeedObjectTemplateType.PREVIEW
|
|
121
133
|
}, FeedSidebarProps: FeedSidebarProps, HeaderComponent: scGroup &&
|
|
122
134
|
scGroup.subscription_status === types_1.SCGroupSubscriptionStatusType.SUBSCRIBED && ((0, jsx_runtime_1.jsx)(react_ui_1.InlineComposerWidget, { onSuccess: handleComposerSuccess, defaultValue: { group: scGroup }, label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "templates.groupFeed.composer.label", defaultMessage: "templates.groupFeed.composer.label" }), feedType: types_1.SCFeedTypologyType.GROUP })), CustomAdvProps: { position: types_1.SCCustomAdvPosition.POSITION_FEED, groupsId: [scGroup.id] }, enabledCustomAdvPositions: [
|
|
@@ -85,16 +85,29 @@ function MainFeed(inProps) {
|
|
|
85
85
|
const { id = 'main_feed', className, widgets = WIDGETS, FeedObjectProps = {}, FeedSidebarProps = null, FeedProps = {} } = props;
|
|
86
86
|
//CONTEXT
|
|
87
87
|
const scUserContext = (0, react_1.useContext)(react_core_1.SCUserContext);
|
|
88
|
+
const isAdvertisingCustomAdvEnabled = (0, react_core_1.useSCPreferenceEnabled)(react_core_1.SCPreferences.ADVERTISING_CUSTOM_ADV_ENABLED);
|
|
89
|
+
const isAdvertisingCustomAdvOnlyForAnonUsersEnabled = (0, react_core_1.useSCPreferenceEnabled)(react_core_1.SCPreferences.ADVERTISING_CUSTOM_ADV_ONLY_FOR_ANONYMOUS_USERS_ENABLED);
|
|
88
90
|
const { enqueueSnackbar } = (0, notistack_1.useSnackbar)();
|
|
89
91
|
// REF
|
|
90
92
|
const feedRef = (0, react_1.useRef)();
|
|
93
|
+
/**
|
|
94
|
+
* Render advertising above the feed
|
|
95
|
+
*/
|
|
96
|
+
function renderAdvertising() {
|
|
97
|
+
if (isAdvertisingCustomAdvEnabled &&
|
|
98
|
+
((isAdvertisingCustomAdvOnlyForAnonUsersEnabled && scUserContext.user === null) || !isAdvertisingCustomAdvOnlyForAnonUsersEnabled)) {
|
|
99
|
+
return (0, jsx_runtime_1.jsx)(react_ui_1.CustomAdv, { position: types_1.SCCustomAdvPosition.POSITION_ABOVE_FEED });
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
91
103
|
// Ckeck user is authenticated
|
|
92
104
|
if (!scUserContext.user) {
|
|
93
105
|
return null;
|
|
94
106
|
}
|
|
95
107
|
// HANDLERS
|
|
96
108
|
const handleComposerSuccess = (feedObject) => {
|
|
97
|
-
|
|
109
|
+
const messageId = feedObject.scheduled_at ? 'ui.composer.scheduled.success' : 'ui.inlineComposerWidget.success';
|
|
110
|
+
enqueueSnackbar((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: messageId, defaultMessage: messageId }), {
|
|
98
111
|
variant: 'success',
|
|
99
112
|
autoHideDuration: 3000
|
|
100
113
|
});
|
|
@@ -102,10 +115,10 @@ function MainFeed(inProps) {
|
|
|
102
115
|
const feedUnit = {
|
|
103
116
|
type: feedObject.type,
|
|
104
117
|
[feedObject.type]: feedObject,
|
|
105
|
-
|
|
118
|
+
seen: false,
|
|
106
119
|
has_boost: false
|
|
107
120
|
};
|
|
108
|
-
feedRef && feedRef.current && feedRef.current.addFeedData(feedUnit, true);
|
|
121
|
+
!feedObject.draft && feedRef && feedRef.current && feedRef.current.addFeedData(feedUnit, true);
|
|
109
122
|
};
|
|
110
123
|
const handleAddGenerationContent = (feedObjects) => {
|
|
111
124
|
if (feedRef && feedRef.current) {
|
|
@@ -115,7 +128,7 @@ function MainFeed(inProps) {
|
|
|
115
128
|
const feedUnit = {
|
|
116
129
|
type: feedObject.type,
|
|
117
130
|
[feedObject.type]: feedObject,
|
|
118
|
-
|
|
131
|
+
seen: false,
|
|
119
132
|
has_boost: false
|
|
120
133
|
};
|
|
121
134
|
feedRef.current.addFeedData(feedUnit, true);
|
|
@@ -127,10 +140,10 @@ function MainFeed(inProps) {
|
|
|
127
140
|
feedObject: item[item.type],
|
|
128
141
|
feedObjectType: item.type,
|
|
129
142
|
feedObjectActivities: item.activities ? item.activities : null,
|
|
130
|
-
markRead: scUser ? !item.
|
|
143
|
+
markRead: scUser ? !item.seen : null
|
|
131
144
|
}), itemIdGenerator: (item) => item[item.type].id, ItemProps: FeedObjectProps, ItemSkeleton: react_ui_1.FeedObjectSkeleton, ItemSkeletonProps: {
|
|
132
145
|
template: react_ui_1.SCFeedObjectTemplateType.PREVIEW
|
|
133
|
-
}, FeedSidebarProps: FeedSidebarProps, HeaderComponent: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_ui_1.InlineComposerWidget, { onSuccess: handleComposerSuccess }), react_core_1.UserUtils.isAdmin(scUserContext.user) && (0, jsx_runtime_1.jsx)(react_ui_1.OnBoardingWidget, { onGeneratedContent: handleAddGenerationContent })] }), requireAuthentication: true, disablePaginationLinks: true, enabledCustomAdvPositions: [
|
|
146
|
+
}, FeedSidebarProps: FeedSidebarProps, HeaderComponent: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_ui_1.InlineComposerWidget, { onSuccess: handleComposerSuccess }), react_core_1.UserUtils.isAdmin(scUserContext.user) && (0, jsx_runtime_1.jsx)(react_ui_1.OnBoardingWidget, { onGeneratedContent: handleAddGenerationContent }), renderAdvertising()] }), requireAuthentication: true, disablePaginationLinks: true, enabledCustomAdvPositions: [
|
|
134
147
|
types_1.SCCustomAdvPosition.POSITION_FEED_SIDEBAR,
|
|
135
148
|
types_1.SCCustomAdvPosition.POSITION_FEED,
|
|
136
149
|
types_1.SCCustomAdvPosition.POSITION_BELOW_TOPBAR
|
|
@@ -92,7 +92,8 @@ function UserFeed(inProps) {
|
|
|
92
92
|
const feedRef = (0, react_1.useRef)();
|
|
93
93
|
// HANDLERS
|
|
94
94
|
const handleComposerSuccess = (feedObject) => {
|
|
95
|
-
|
|
95
|
+
const messageId = feedObject.scheduled_at ? 'ui.composer.scheduled.success' : 'ui.inlineComposerWidget.success';
|
|
96
|
+
enqueueSnackbar((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: messageId, defaultMessage: messageId }), {
|
|
96
97
|
variant: 'success',
|
|
97
98
|
autoHideDuration: 3000
|
|
98
99
|
});
|
|
@@ -100,10 +101,10 @@ function UserFeed(inProps) {
|
|
|
100
101
|
const feedUnit = {
|
|
101
102
|
type: feedObject.type,
|
|
102
103
|
[feedObject.type]: feedObject,
|
|
103
|
-
|
|
104
|
+
seen: false,
|
|
104
105
|
has_boost: false
|
|
105
106
|
};
|
|
106
|
-
feedRef && feedRef.current && feedRef.current.addFeedData(feedUnit, true);
|
|
107
|
+
!feedObject.draft && feedRef && feedRef.current && feedRef.current.addFeedData(feedUnit, true);
|
|
107
108
|
};
|
|
108
109
|
// WIDGETS
|
|
109
110
|
const _widgets = (0, react_1.useMemo)(() => widgets.map((w) => {
|
|
@@ -112,7 +113,7 @@ function UserFeed(inProps) {
|
|
|
112
113
|
if (scUser === null) {
|
|
113
114
|
return (0, jsx_runtime_1.jsx)(index_1.UserFeedSkeleton, {});
|
|
114
115
|
}
|
|
115
|
-
return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ id: id, className: (0, classnames_1.default)(classes.root, className), ref: feedRef, endpoint: Object.assign(Object.assign({}, api_services_1.Endpoints.UserFeed), { url: () => api_services_1.Endpoints.UserFeed.url({ id: scUser.id }) }), widgets: _widgets, ItemComponent: react_ui_1.FeedObject, itemPropsGenerator: (
|
|
116
|
+
return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ id: id, className: (0, classnames_1.default)(classes.root, className), ref: feedRef, endpoint: Object.assign(Object.assign({}, api_services_1.Endpoints.UserFeed), { url: () => api_services_1.Endpoints.UserFeed.url({ id: scUser.id }) }), widgets: _widgets, ItemComponent: react_ui_1.FeedObject, itemPropsGenerator: (_scUser, item) => ({
|
|
116
117
|
feedObject: item[item.type],
|
|
117
118
|
feedObjectType: item.type,
|
|
118
119
|
feedObjectActivities: item.activities ? item.activities : null
|
|
@@ -185,13 +185,16 @@ function UserProfile(inProps) {
|
|
|
185
185
|
const isMe = (0, react_1.useMemo)(() => scUserContext.user && (scUser === null || scUser === void 0 ? void 0 : scUser.id) === scUserContext.user.id, [scUserContext.user, scUser]);
|
|
186
186
|
const followEnabled = (0, react_1.useMemo)(() => react_core_1.SCPreferences.CONFIGURATIONS_FOLLOW_ENABLED in scPreferencesContext.preferences &&
|
|
187
187
|
scPreferencesContext.preferences[react_core_1.SCPreferences.CONFIGURATIONS_FOLLOW_ENABLED].value, [scPreferencesContext.preferences]);
|
|
188
|
-
const
|
|
188
|
+
const connectionEnabled = react_core_1.SCPreferences.CONFIGURATIONS_CONNECTION_ENABLED in scPreferencesContext.preferences &&
|
|
189
|
+
scPreferencesContext.preferences[react_core_1.SCPreferences.CONFIGURATIONS_CONNECTION_ENABLED].value;
|
|
190
|
+
const privateMessagingEnabled = (0, react_1.useMemo)(() => react_core_1.SCPreferences.ADDONS_PRIVATE_MESSAGES_ENABLED in scPreferencesContext.preferences &&
|
|
191
|
+
scPreferencesContext.preferences[react_core_1.SCPreferences.ADDONS_PRIVATE_MESSAGES_ENABLED].value, [scPreferencesContext.preferences]);
|
|
189
192
|
const _widgets = (0, react_1.useMemo)(() => {
|
|
190
193
|
var _a, _b;
|
|
191
194
|
if (widgets !== null) {
|
|
192
195
|
return widgets;
|
|
193
196
|
}
|
|
194
|
-
if (!scUser) {
|
|
197
|
+
if (!scUser || (!followEnabled && !connectionEnabled)) {
|
|
195
198
|
return [];
|
|
196
199
|
}
|
|
197
200
|
let _widgets = [];
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useMemo, useRef } from 'react';
|
|
3
3
|
import { styled } from '@mui/material';
|
|
4
|
-
import { CategoryTrendingFeedWidget, CategoryTrendingUsersWidget, ContributionUtils, Feed, FeedObject, FeedObjectSkeleton, InlineComposerWidget, SCFeedObjectTemplateType } from '@selfcommunity/react-ui';
|
|
4
|
+
import { CategoryTrendingFeedWidget, CategoryTrendingUsersWidget, ContributionUtils, Feed, FeedObject, FeedObjectSkeleton, HiddenPurchasableContent, InlineComposerWidget, SCFeedObjectTemplateType, CustomAdv } from '@selfcommunity/react-ui';
|
|
5
5
|
import { Endpoints } from '@selfcommunity/api-services';
|
|
6
|
-
import { Link, SCRoutes, UserUtils, useSCFetchCategory, useSCRouting, useSCUser } from '@selfcommunity/react-core';
|
|
7
|
-
import { SCCustomAdvPosition, SCFeedTypologyType } from '@selfcommunity/types';
|
|
6
|
+
import { Link, SCPreferences, SCRoutes, UserUtils, useSCFetchCategory, useSCPreferenceEnabled, useSCPreferencesAndFeaturesEnabled, useSCRouting, useSCUser } from '@selfcommunity/react-core';
|
|
7
|
+
import { SCCustomAdvPosition, SCFeatureName, SCFeedTypologyType } from '@selfcommunity/types';
|
|
8
8
|
import { CategoryFeedSkeleton } from './index';
|
|
9
9
|
import { useThemeProps } from '@mui/system';
|
|
10
10
|
import classNames from 'classnames';
|
|
@@ -61,6 +61,7 @@ const WIDGETS = [
|
|
|
61
61
|
* @param inProps
|
|
62
62
|
*/
|
|
63
63
|
export default function CategoryFeed(inProps) {
|
|
64
|
+
var _a;
|
|
64
65
|
// PROPS
|
|
65
66
|
const props = useThemeProps({
|
|
66
67
|
props: inProps,
|
|
@@ -75,12 +76,26 @@ export default function CategoryFeed(inProps) {
|
|
|
75
76
|
const feedRef = useRef();
|
|
76
77
|
// Hooks
|
|
77
78
|
const { scCategory } = useSCFetchCategory({ id: categoryId, category });
|
|
79
|
+
const isAdvertisingCustomAdvEnabled = useSCPreferenceEnabled(SCPreferences.ADVERTISING_CUSTOM_ADV_ENABLED);
|
|
80
|
+
const isAdvertisingCustomAdvOnlyForAnonUsersEnabled = useSCPreferenceEnabled(SCPreferences.ADVERTISING_CUSTOM_ADV_ONLY_FOR_ANONYMOUS_USERS_ENABLED);
|
|
81
|
+
const isPaymentsEnabled = useSCPreferencesAndFeaturesEnabled([SCPreferences.CONFIGURATIONS_PAYMENTS_ENABLED], [SCFeatureName.PAYMENTS]);
|
|
82
|
+
/**
|
|
83
|
+
* Render advertising above the feed
|
|
84
|
+
*/
|
|
85
|
+
function renderAdvertising() {
|
|
86
|
+
if (isAdvertisingCustomAdvEnabled &&
|
|
87
|
+
((isAdvertisingCustomAdvOnlyForAnonUsersEnabled && scUserContext.user === null) || !isAdvertisingCustomAdvOnlyForAnonUsersEnabled)) {
|
|
88
|
+
return _jsx(CustomAdv, { position: SCCustomAdvPosition.POSITION_ABOVE_FEED, categoriesId: [scCategory.id] });
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
78
92
|
// HANDLERS
|
|
79
93
|
const handleComposerSuccess = (feedObject) => {
|
|
80
94
|
// Not insert if the category does not match
|
|
81
95
|
if (feedObject.categories.findIndex((c) => c.id === scCategory.id) === -1) {
|
|
82
|
-
|
|
83
|
-
|
|
96
|
+
const messageId = feedObject.scheduled_at ? 'ui.composer.scheduled.success' : 'ui.composerIconButton.composer.success';
|
|
97
|
+
enqueueSnackbar(_jsx(FormattedMessage, { id: messageId, defaultMessage: messageId }), {
|
|
98
|
+
action: () => (_jsx(Link, Object.assign({ to: scRoutingContext.url(SCRoutes[`${feedObject.type.toUpperCase()}_ROUTE_NAME`], ContributionUtils.getRouteData(feedObject)) }, { children: _jsx(FormattedMessage, { id: "ui.composerIconButton.composer.viewContribute", defaultMessage: "ui.composerIconButton.composer.viewContribute" }) }))),
|
|
84
99
|
variant: 'success',
|
|
85
100
|
autoHideDuration: 7000
|
|
86
101
|
});
|
|
@@ -90,10 +105,10 @@ export default function CategoryFeed(inProps) {
|
|
|
90
105
|
const feedUnit = {
|
|
91
106
|
type: feedObject.type,
|
|
92
107
|
[feedObject.type]: feedObject,
|
|
93
|
-
|
|
108
|
+
seen: false,
|
|
94
109
|
has_boost: false
|
|
95
110
|
};
|
|
96
|
-
feedRef && feedRef.current && feedRef.current.addFeedData(feedUnit, true);
|
|
111
|
+
!feedObject.draft && feedRef && feedRef.current && feedRef.current.addFeedData(feedUnit, true);
|
|
97
112
|
};
|
|
98
113
|
// WIDGETS
|
|
99
114
|
const _widgets = useMemo(() => widgets.map((w) => {
|
|
@@ -105,14 +120,17 @@ export default function CategoryFeed(inProps) {
|
|
|
105
120
|
if (!scCategory) {
|
|
106
121
|
return _jsx(CategoryFeedSkeleton, {});
|
|
107
122
|
}
|
|
123
|
+
else if (scCategory && isPaymentsEnabled && !scCategory.followed && !scCategory.payment_order && ((_a = scCategory.paywalls) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
124
|
+
return _jsx(HiddenPurchasableContent, {});
|
|
125
|
+
}
|
|
108
126
|
return (_jsx(Root, Object.assign({ id: id, className: classNames(classes.root, className), ref: feedRef, endpoint: Object.assign(Object.assign({}, Endpoints.CategoryFeed), { url: () => Endpoints.CategoryFeed.url({ id: scCategory.id }) }), widgets: _widgets, ItemComponent: FeedObject, itemPropsGenerator: (scUser, item) => ({
|
|
109
127
|
feedObject: item[item.type],
|
|
110
128
|
feedObjectType: item.type,
|
|
111
129
|
feedObjectActivities: item.activities ? item.activities : null,
|
|
112
|
-
markRead: scUser ? !item.
|
|
130
|
+
markRead: scUser ? !item.seen : null
|
|
113
131
|
}), itemIdGenerator: (item) => item[item.type].id, ItemProps: FeedObjectProps, ItemSkeleton: FeedObjectSkeleton, ItemSkeletonProps: {
|
|
114
132
|
template: SCFeedObjectTemplateType.PREVIEW
|
|
115
|
-
}, FeedSidebarProps: FeedSidebarProps, HeaderComponent:
|
|
133
|
+
}, FeedSidebarProps: FeedSidebarProps, HeaderComponent: _jsxs(_Fragment, { children: [((scCategory.content_only_staff && UserUtils.isStaff(scUserContext.user)) || !scCategory.content_only_staff) && (_jsx(InlineComposerWidget, { onSuccess: handleComposerSuccess, defaultValue: { categories: [scCategory] }, feedType: SCFeedTypologyType.CATEGORY })), renderAdvertising()] }), CustomAdvProps: { categoriesId: [scCategory.id] }, enabledCustomAdvPositions: [
|
|
116
134
|
SCCustomAdvPosition.POSITION_FEED_SIDEBAR,
|
|
117
135
|
SCCustomAdvPosition.POSITION_FEED,
|
|
118
136
|
SCCustomAdvPosition.POSITION_BELOW_TOPBAR
|