@selfcommunity/react-ui 0.7.0-alpha.350 → 0.7.0-alpha.352

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.
@@ -65,6 +65,16 @@ export interface CommentObjectProps {
65
65
  * @default null
66
66
  */
67
67
  onDelete?: (comment: SCCommentType) => void;
68
+ /**
69
+ * Callback on restore the comment
70
+ * @default null
71
+ */
72
+ onRestore?: (comment: SCCommentType) => void;
73
+ /**
74
+ * Callback on collapsed the comment
75
+ * @default null
76
+ */
77
+ onCollapsed?: (comment: SCCommentType) => void;
68
78
  /**
69
79
  * Show all summary initially (otherwise it will be truncated)
70
80
  * @default false
@@ -94,7 +94,7 @@ function CommentObject(inProps) {
94
94
  props: inProps,
95
95
  name: constants_1.PREFIX
96
96
  });
97
- const { id = `comment_object_${props.commentObjectId ? props.commentObjectId : props.commentObject ? props.commentObject.id : ''}`, className, commentObjectId, commentObject, feedObjectId, feedObject, feedObjectType = types_1.SCContributionType.POST, commentReply, onOpenReply, onDelete, onVote, elevation = 0, truncateContent = false, CommentObjectSkeletonProps = { elevation, WidgetProps: { variant: 'outlined' } }, CommentObjectReplyProps = { elevation, WidgetProps: { variant: 'outlined' } }, linkableCommentDateTime = true, cacheStrategy = utils_1.CacheStrategies.NETWORK_ONLY, CommentsObjectComponentProps = {} } = props, rest = tslib_1.__rest(props, ["id", "className", "commentObjectId", "commentObject", "feedObjectId", "feedObject", "feedObjectType", "commentReply", "onOpenReply", "onDelete", "onVote", "elevation", "truncateContent", "CommentObjectSkeletonProps", "CommentObjectReplyProps", "linkableCommentDateTime", "cacheStrategy", "CommentsObjectComponentProps"]);
97
+ const { id = `comment_object_${props.commentObjectId ? props.commentObjectId : props.commentObject ? props.commentObject.id : ''}`, className, commentObjectId, commentObject, feedObjectId, feedObject, feedObjectType = types_1.SCContributionType.POST, commentReply, onOpenReply, onDelete, onCollapsed, onRestore, onVote, elevation = 0, truncateContent = false, CommentObjectSkeletonProps = { elevation, WidgetProps: { variant: 'outlined' } }, CommentObjectReplyProps = { elevation, WidgetProps: { variant: 'outlined' } }, linkableCommentDateTime = true, cacheStrategy = utils_1.CacheStrategies.NETWORK_ONLY, CommentsObjectComponentProps = {} } = props, rest = tslib_1.__rest(props, ["id", "className", "commentObjectId", "commentObject", "feedObjectId", "feedObject", "feedObjectType", "commentReply", "onOpenReply", "onDelete", "onCollapsed", "onRestore", "onVote", "elevation", "truncateContent", "CommentObjectSkeletonProps", "CommentObjectReplyProps", "linkableCommentDateTime", "cacheStrategy", "CommentsObjectComponentProps"]);
98
98
  // CONTEXT
99
99
  const scContext = (0, react_core_1.useSCContext)();
100
100
  const scUserContext = (0, react_1.useContext)(react_core_1.SCUserContext);
@@ -212,54 +212,22 @@ function CommentObject(inProps) {
212
212
  * Handle comment delete
213
213
  */
214
214
  function handleDelete(comment) {
215
- if (comment.parent) {
216
- const _latestComment = obj.latest_comments.map((c) => {
217
- if (c.id === comment.id) {
218
- c.deleted = !c.deleted;
219
- }
220
- return c;
221
- });
222
- updateObject(Object.assign({}, obj, { latest_comments: _latestComment }));
223
- }
224
- else {
225
- const _comment = Object.assign({}, obj, { deleted: !obj.deleted });
226
- updateObject(Object.assign({}, obj, { deleted: !obj.deleted }));
227
- onDelete && onDelete(_comment);
228
- }
215
+ updateObject(comment);
216
+ onDelete && onDelete(comment);
229
217
  }
230
218
  /**
231
219
  * Handle comment delete
232
220
  */
233
221
  function handleHide(comment) {
234
- if (comment.parent) {
235
- const _latestComment = obj.latest_comments.map((c) => {
236
- if (c.id === comment.id) {
237
- c.collapsed = !c.collapsed;
238
- }
239
- return c;
240
- });
241
- updateObject(Object.assign({}, obj, { latest_comments: _latestComment }));
242
- }
243
- else {
244
- updateObject(Object.assign({}, obj, { collapsed: !obj.collapsed }));
245
- }
222
+ updateObject(Object.assign({}, obj, { collapsed: !obj.collapsed }));
223
+ onCollapsed && onCollapsed(comment);
246
224
  }
247
225
  /**
248
226
  * Handle comment restore
249
227
  */
250
228
  function handleRestore(comment) {
251
- if (comment.parent) {
252
- const _latestComment = obj.latest_comments.map((c) => {
253
- if (c.id === comment.id) {
254
- c.deleted = false;
255
- }
256
- return c;
257
- });
258
- updateObject(Object.assign({}, obj, { latest_comments: _latestComment }));
259
- }
260
- else {
261
- updateObject(Object.assign({}, obj, { deleted: false }));
262
- }
229
+ updateObject(Object.assign({}, obj, { deleted: false }));
230
+ onRestore && onRestore(comment);
263
231
  }
264
232
  /**
265
233
  * Handle edit comment
@@ -326,7 +294,7 @@ function CommentObject(inProps) {
326
294
  */
327
295
  function renderComment(comment) {
328
296
  if (comment.deleted &&
329
- (!scUserContext.user || (scUserContext.user && (!react_core_1.UserUtils.isStaff(scUserContext.user) || scUserContext.user.id !== comment.author.id)))) {
297
+ (!scUserContext.user || (scUserContext.user && !react_core_1.UserUtils.isStaff(scUserContext.user) && scUserContext.user.id !== comment.author.id))) {
330
298
  // render the comment if user is logged and is staff (admin, moderator)
331
299
  // or the comment author is the logged user
332
300
  return null;
@@ -65,6 +65,16 @@ export interface CommentObjectProps {
65
65
  * @default null
66
66
  */
67
67
  onDelete?: (comment: SCCommentType) => void;
68
+ /**
69
+ * Callback on restore the comment
70
+ * @default null
71
+ */
72
+ onRestore?: (comment: SCCommentType) => void;
73
+ /**
74
+ * Callback on collapsed the comment
75
+ * @default null
76
+ */
77
+ onCollapsed?: (comment: SCCommentType) => void;
68
78
  /**
69
79
  * Show all summary initially (otherwise it will be truncated)
70
80
  * @default false
@@ -92,7 +92,7 @@ export default function CommentObject(inProps) {
92
92
  props: inProps,
93
93
  name: PREFIX
94
94
  });
95
- const { id = `comment_object_${props.commentObjectId ? props.commentObjectId : props.commentObject ? props.commentObject.id : ''}`, className, commentObjectId, commentObject, feedObjectId, feedObject, feedObjectType = SCContributionType.POST, commentReply, onOpenReply, onDelete, onVote, elevation = 0, truncateContent = false, CommentObjectSkeletonProps = { elevation, WidgetProps: { variant: 'outlined' } }, CommentObjectReplyProps = { elevation, WidgetProps: { variant: 'outlined' } }, linkableCommentDateTime = true, cacheStrategy = CacheStrategies.NETWORK_ONLY, CommentsObjectComponentProps = {} } = props, rest = __rest(props, ["id", "className", "commentObjectId", "commentObject", "feedObjectId", "feedObject", "feedObjectType", "commentReply", "onOpenReply", "onDelete", "onVote", "elevation", "truncateContent", "CommentObjectSkeletonProps", "CommentObjectReplyProps", "linkableCommentDateTime", "cacheStrategy", "CommentsObjectComponentProps"]);
95
+ const { id = `comment_object_${props.commentObjectId ? props.commentObjectId : props.commentObject ? props.commentObject.id : ''}`, className, commentObjectId, commentObject, feedObjectId, feedObject, feedObjectType = SCContributionType.POST, commentReply, onOpenReply, onDelete, onCollapsed, onRestore, onVote, elevation = 0, truncateContent = false, CommentObjectSkeletonProps = { elevation, WidgetProps: { variant: 'outlined' } }, CommentObjectReplyProps = { elevation, WidgetProps: { variant: 'outlined' } }, linkableCommentDateTime = true, cacheStrategy = CacheStrategies.NETWORK_ONLY, CommentsObjectComponentProps = {} } = props, rest = __rest(props, ["id", "className", "commentObjectId", "commentObject", "feedObjectId", "feedObject", "feedObjectType", "commentReply", "onOpenReply", "onDelete", "onCollapsed", "onRestore", "onVote", "elevation", "truncateContent", "CommentObjectSkeletonProps", "CommentObjectReplyProps", "linkableCommentDateTime", "cacheStrategy", "CommentsObjectComponentProps"]);
96
96
  // CONTEXT
97
97
  const scContext = useSCContext();
98
98
  const scUserContext = useContext(SCUserContext);
@@ -210,54 +210,22 @@ export default function CommentObject(inProps) {
210
210
  * Handle comment delete
211
211
  */
212
212
  function handleDelete(comment) {
213
- if (comment.parent) {
214
- const _latestComment = obj.latest_comments.map((c) => {
215
- if (c.id === comment.id) {
216
- c.deleted = !c.deleted;
217
- }
218
- return c;
219
- });
220
- updateObject(Object.assign({}, obj, { latest_comments: _latestComment }));
221
- }
222
- else {
223
- const _comment = Object.assign({}, obj, { deleted: !obj.deleted });
224
- updateObject(Object.assign({}, obj, { deleted: !obj.deleted }));
225
- onDelete && onDelete(_comment);
226
- }
213
+ updateObject(comment);
214
+ onDelete && onDelete(comment);
227
215
  }
228
216
  /**
229
217
  * Handle comment delete
230
218
  */
231
219
  function handleHide(comment) {
232
- if (comment.parent) {
233
- const _latestComment = obj.latest_comments.map((c) => {
234
- if (c.id === comment.id) {
235
- c.collapsed = !c.collapsed;
236
- }
237
- return c;
238
- });
239
- updateObject(Object.assign({}, obj, { latest_comments: _latestComment }));
240
- }
241
- else {
242
- updateObject(Object.assign({}, obj, { collapsed: !obj.collapsed }));
243
- }
220
+ updateObject(Object.assign({}, obj, { collapsed: !obj.collapsed }));
221
+ onCollapsed && onCollapsed(comment);
244
222
  }
245
223
  /**
246
224
  * Handle comment restore
247
225
  */
248
226
  function handleRestore(comment) {
249
- if (comment.parent) {
250
- const _latestComment = obj.latest_comments.map((c) => {
251
- if (c.id === comment.id) {
252
- c.deleted = false;
253
- }
254
- return c;
255
- });
256
- updateObject(Object.assign({}, obj, { latest_comments: _latestComment }));
257
- }
258
- else {
259
- updateObject(Object.assign({}, obj, { deleted: false }));
260
- }
227
+ updateObject(Object.assign({}, obj, { deleted: false }));
228
+ onRestore && onRestore(comment);
261
229
  }
262
230
  /**
263
231
  * Handle edit comment
@@ -324,7 +292,7 @@ export default function CommentObject(inProps) {
324
292
  */
325
293
  function renderComment(comment) {
326
294
  if (comment.deleted &&
327
- (!scUserContext.user || (scUserContext.user && (!UserUtils.isStaff(scUserContext.user) || scUserContext.user.id !== comment.author.id)))) {
295
+ (!scUserContext.user || (scUserContext.user && !UserUtils.isStaff(scUserContext.user) && scUserContext.user.id !== comment.author.id))) {
328
296
  // render the comment if user is logged and is staff (admin, moderator)
329
297
  // or the comment author is the logged user
330
298
  return null;