@quesmed/types 2.6.14 → 2.6.16
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.
|
@@ -512,6 +512,28 @@ const removeCommnetFromDiscussion = (comments, commentId, parentId) => {
|
|
|
512
512
|
}
|
|
513
513
|
return comments.filter(({ id }) => Number(id) !== Number(commentId));
|
|
514
514
|
};
|
|
515
|
+
const updateCommentFromDiscussion = (comments, commentId, update, parentId) => {
|
|
516
|
+
const updatedComments = [...comments];
|
|
517
|
+
if (parentId) {
|
|
518
|
+
const parentIndex = comments.findIndex((comment) => Number(comment.id) === Number(parentId));
|
|
519
|
+
if (parentIndex !== -1) {
|
|
520
|
+
const parentComment = updatedComments[parentIndex];
|
|
521
|
+
parentComment.replies = (parentComment.replies ?? []).map((reply) => Number(reply.id) === Number(commentId)
|
|
522
|
+
? { ...reply, ...update }
|
|
523
|
+
: reply);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
else {
|
|
527
|
+
const commentIndex = comments.findIndex((comment) => Number(comment.id) === Number(commentId));
|
|
528
|
+
if (commentIndex !== -1) {
|
|
529
|
+
updatedComments[commentIndex] = {
|
|
530
|
+
...updatedComments[commentIndex],
|
|
531
|
+
...update,
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
return updatedComments;
|
|
536
|
+
};
|
|
515
537
|
exports.QUESTION_LIKE = (0, client_1.gql) `
|
|
516
538
|
mutation QuestionLike($marksheetId: Int, $questionId: Int!, $like: Int!) {
|
|
517
539
|
restricted {
|
|
@@ -757,7 +779,7 @@ const updateQuestionCommentsRemove = (typeId) => (cache, result, options) => {
|
|
|
757
779
|
if (!variables || !questionCommentRemove) {
|
|
758
780
|
return;
|
|
759
781
|
}
|
|
760
|
-
const { questionId, id: commentId, parentId } = questionCommentRemove;
|
|
782
|
+
const { questionId, id: commentId, parentId, userId, user, } = questionCommentRemove;
|
|
761
783
|
try {
|
|
762
784
|
const dataFragment = cache.readFragment({
|
|
763
785
|
id: cache.identify({
|
|
@@ -775,7 +797,7 @@ const updateQuestionCommentsRemove = (typeId) => (cache, result, options) => {
|
|
|
775
797
|
}),
|
|
776
798
|
data: {
|
|
777
799
|
...dataFragment,
|
|
778
|
-
comments:
|
|
800
|
+
comments: updateCommentFromDiscussion(comments, commentId, { userId, user }, parentId),
|
|
779
801
|
},
|
|
780
802
|
fragment: getQuestionFragment(typeId),
|
|
781
803
|
});
|
|
@@ -506,6 +506,28 @@ const removeCommnetFromDiscussion = (comments, commentId, parentId) => {
|
|
|
506
506
|
}
|
|
507
507
|
return comments.filter(({ id }) => Number(id) !== Number(commentId));
|
|
508
508
|
};
|
|
509
|
+
const updateCommentFromDiscussion = (comments, commentId, update, parentId) => {
|
|
510
|
+
const updatedComments = [...comments];
|
|
511
|
+
if (parentId) {
|
|
512
|
+
const parentIndex = comments.findIndex((comment) => Number(comment.id) === Number(parentId));
|
|
513
|
+
if (parentIndex !== -1) {
|
|
514
|
+
const parentComment = updatedComments[parentIndex];
|
|
515
|
+
parentComment.replies = (parentComment.replies ?? []).map((reply) => Number(reply.id) === Number(commentId)
|
|
516
|
+
? { ...reply, ...update }
|
|
517
|
+
: reply);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
else {
|
|
521
|
+
const commentIndex = comments.findIndex((comment) => Number(comment.id) === Number(commentId));
|
|
522
|
+
if (commentIndex !== -1) {
|
|
523
|
+
updatedComments[commentIndex] = {
|
|
524
|
+
...updatedComments[commentIndex],
|
|
525
|
+
...update,
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
return updatedComments;
|
|
530
|
+
};
|
|
509
531
|
export const QUESTION_LIKE = gql `
|
|
510
532
|
mutation QuestionLike($marksheetId: Int, $questionId: Int!, $like: Int!) {
|
|
511
533
|
restricted {
|
|
@@ -747,7 +769,7 @@ export const updateQuestionCommentsRemove = (typeId) => (cache, result, options)
|
|
|
747
769
|
if (!variables || !questionCommentRemove) {
|
|
748
770
|
return;
|
|
749
771
|
}
|
|
750
|
-
const { questionId, id: commentId, parentId } = questionCommentRemove;
|
|
772
|
+
const { questionId, id: commentId, parentId, userId, user, } = questionCommentRemove;
|
|
751
773
|
try {
|
|
752
774
|
const dataFragment = cache.readFragment({
|
|
753
775
|
id: cache.identify({
|
|
@@ -765,7 +787,7 @@ export const updateQuestionCommentsRemove = (typeId) => (cache, result, options)
|
|
|
765
787
|
}),
|
|
766
788
|
data: {
|
|
767
789
|
...dataFragment,
|
|
768
|
-
comments:
|
|
790
|
+
comments: updateCommentFromDiscussion(comments, commentId, { userId, user }, parentId),
|
|
769
791
|
},
|
|
770
792
|
fragment: getQuestionFragment(typeId),
|
|
771
793
|
});
|