gitalk-react 1.0.0-beta.5 → 1.0.0-beta.6
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/dist/gitalk.js +2182 -2171
- package/dist/gitalk.umd.cjs +13 -13
- package/lib/gitalk.tsx +52 -32
- package/lib/i18n/index.ts +1 -1
- package/package.json +6 -2
package/lib/gitalk.tsx
CHANGED
|
@@ -267,7 +267,7 @@ const Gitalk: React.FC<GitalkProps> = (props) => {
|
|
|
267
267
|
() => (propsPerPage > 100 ? 100 : propsPerPage < 0 ? 10 : propsPerPage),
|
|
268
268
|
[propsPerPage],
|
|
269
269
|
);
|
|
270
|
-
|
|
270
|
+
/** Current sort order, have effect when user is logged */
|
|
271
271
|
const [commentsPagerDirection, setCommentsPagerDirection] =
|
|
272
272
|
useState(pagerDirection);
|
|
273
273
|
const defaultUser = useMemo(
|
|
@@ -490,6 +490,7 @@ const Gitalk: React.FC<GitalkProps> = (props) => {
|
|
|
490
490
|
const {
|
|
491
491
|
data: comments = [],
|
|
492
492
|
mutate: setComments,
|
|
493
|
+
run: runGetComments,
|
|
493
494
|
loading: getCommentsLoading,
|
|
494
495
|
} = useRequest(
|
|
495
496
|
async (): Promise<CommentType[]> => {
|
|
@@ -500,7 +501,7 @@ const Gitalk: React.FC<GitalkProps> = (props) => {
|
|
|
500
501
|
if (user) {
|
|
501
502
|
// Get comments via GraphQL, witch requires being logged and able to sort
|
|
502
503
|
const query = getIssueCommentsQL({
|
|
503
|
-
pagerDirection,
|
|
504
|
+
pagerDirection: commentsPagerDirection,
|
|
504
505
|
});
|
|
505
506
|
|
|
506
507
|
const getIssueCommentsRes: IssueCommentsQLResponse =
|
|
@@ -540,11 +541,14 @@ const Gitalk: React.FC<GitalkProps> = (props) => {
|
|
|
540
541
|
_comments,
|
|
541
542
|
);
|
|
542
543
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
544
|
+
const commentsPageInfo =
|
|
545
|
+
getIssueCommentsRes.repository.issue.comments.pageInfo;
|
|
546
|
+
const commentsPageCursor =
|
|
547
|
+
commentsPageInfo.startCursor || commentsPageInfo.endCursor || "";
|
|
548
|
+
setCommentsCursor(commentsPageCursor);
|
|
546
549
|
|
|
547
|
-
if (
|
|
550
|
+
if (commentsPagerDirection === "last")
|
|
551
|
+
return [..._comments, ...comments];
|
|
548
552
|
else return [...comments, ..._comments];
|
|
549
553
|
} else {
|
|
550
554
|
setAlert(
|
|
@@ -589,9 +593,7 @@ const Gitalk: React.FC<GitalkProps> = (props) => {
|
|
|
589
593
|
_comments,
|
|
590
594
|
);
|
|
591
595
|
|
|
592
|
-
|
|
593
|
-
setCommentsLoaded(true);
|
|
594
|
-
}
|
|
596
|
+
setCommentsPage((prev) => prev + 1);
|
|
595
597
|
|
|
596
598
|
return [...comments, ..._comments];
|
|
597
599
|
} else {
|
|
@@ -608,8 +610,8 @@ const Gitalk: React.FC<GitalkProps> = (props) => {
|
|
|
608
610
|
return comments;
|
|
609
611
|
},
|
|
610
612
|
{
|
|
611
|
-
|
|
612
|
-
|
|
613
|
+
manual: true,
|
|
614
|
+
ready: !!owner && !!repo && !!issue && !getUserLoading,
|
|
613
615
|
},
|
|
614
616
|
);
|
|
615
617
|
|
|
@@ -649,6 +651,8 @@ const Gitalk: React.FC<GitalkProps> = (props) => {
|
|
|
649
651
|
logger.s(`Create issue comment successfully.`);
|
|
650
652
|
|
|
651
653
|
setInputComment("");
|
|
654
|
+
setCommentsCount((prev) => prev + 1);
|
|
655
|
+
|
|
652
656
|
onCreateComment?.(createdIssueComment);
|
|
653
657
|
|
|
654
658
|
return localComments.concat([createdIssueComment]);
|
|
@@ -666,34 +670,50 @@ const Gitalk: React.FC<GitalkProps> = (props) => {
|
|
|
666
670
|
|
|
667
671
|
useEffect(() => {
|
|
668
672
|
setComments([]);
|
|
669
|
-
setCommentsCount(0);
|
|
673
|
+
setCommentsCount(issue?.comments ?? 0);
|
|
670
674
|
setCommentsCursor("");
|
|
671
675
|
setCommentsPage(1);
|
|
672
|
-
setCommentsLoaded(false);
|
|
673
676
|
setLocalComments([]);
|
|
674
677
|
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
}
|
|
678
|
-
}, [issue,
|
|
678
|
+
setTimeout(() => {
|
|
679
|
+
runGetComments();
|
|
680
|
+
});
|
|
681
|
+
}, [issue, runGetComments, setComments, setLocalComments]);
|
|
682
|
+
|
|
683
|
+
useEffect(() => {
|
|
684
|
+
setComments([]);
|
|
685
|
+
setCommentsCursor("");
|
|
686
|
+
setCommentsPage(1);
|
|
687
|
+
|
|
688
|
+
setTimeout(() => {
|
|
689
|
+
runGetComments();
|
|
690
|
+
});
|
|
691
|
+
}, [user, commentsPagerDirection, setComments, runGetComments]);
|
|
679
692
|
|
|
680
693
|
/** sorted all comments */
|
|
681
|
-
const
|
|
682
|
-
const
|
|
694
|
+
const loadedComments = useMemo(() => {
|
|
695
|
+
const _loadedComments: CommentType[] = [];
|
|
696
|
+
|
|
697
|
+
// filter duplicate comments if exist
|
|
698
|
+
const commentIdsSet = new Set();
|
|
699
|
+
for (const comment of comments.concat(localComments)) {
|
|
700
|
+
if (!commentIdsSet.has(comment.id)) {
|
|
701
|
+
commentIdsSet.add(comment.id);
|
|
702
|
+
_loadedComments.push(comment);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
683
705
|
|
|
684
|
-
if (commentsPagerDirection === "last"
|
|
706
|
+
if (!!user && commentsPagerDirection === "last") {
|
|
685
707
|
// sort comments by date DESC
|
|
686
|
-
|
|
708
|
+
_loadedComments.reverse();
|
|
687
709
|
}
|
|
688
710
|
|
|
689
|
-
return
|
|
711
|
+
return _loadedComments;
|
|
690
712
|
}, [comments, commentsPagerDirection, localComments, user]);
|
|
691
713
|
|
|
692
|
-
const allCommentsCount = commentsCount + (localComments ?? []).length;
|
|
693
|
-
|
|
694
714
|
useEffect(() => {
|
|
695
|
-
updateCountCallback?.(
|
|
696
|
-
}, [
|
|
715
|
+
updateCountCallback?.(commentsCount);
|
|
716
|
+
}, [commentsCount, updateCountCallback]);
|
|
697
717
|
|
|
698
718
|
const {
|
|
699
719
|
data: commentHtml = "",
|
|
@@ -1127,20 +1147,20 @@ const Gitalk: React.FC<GitalkProps> = (props) => {
|
|
|
1127
1147
|
return (
|
|
1128
1148
|
<div className="gt-comments" key="comments">
|
|
1129
1149
|
<FlipMove {...flipMoveOptions}>
|
|
1130
|
-
{
|
|
1150
|
+
{loadedComments.map((comment) => (
|
|
1131
1151
|
<CommentWithForwardedRef key={comment.id} comment={comment} />
|
|
1132
1152
|
))}
|
|
1133
1153
|
</FlipMove>
|
|
1134
|
-
{!
|
|
1154
|
+
{!commentsCount && (
|
|
1135
1155
|
<p className="gt-comments-null">
|
|
1136
1156
|
{polyglot.t("first-comment-person")}
|
|
1137
1157
|
</p>
|
|
1138
1158
|
)}
|
|
1139
|
-
{
|
|
1159
|
+
{commentsCount > loadedComments.length ? (
|
|
1140
1160
|
<div className="gt-comments-controls">
|
|
1141
1161
|
<Button
|
|
1142
1162
|
className="gt-btn-loadmore"
|
|
1143
|
-
onClick={
|
|
1163
|
+
onClick={runGetComments}
|
|
1144
1164
|
isLoading={getCommentsLoading}
|
|
1145
1165
|
text={polyglot.t("load-more")}
|
|
1146
1166
|
/>
|
|
@@ -1159,8 +1179,8 @@ const Gitalk: React.FC<GitalkProps> = (props) => {
|
|
|
1159
1179
|
className="gt-counts"
|
|
1160
1180
|
dangerouslySetInnerHTML={{
|
|
1161
1181
|
__html: polyglot.t("counts", {
|
|
1162
|
-
counts: `<a class="gt-link gt-link-counts" href="${issue?.html_url}" target="_blank" rel="noopener noreferrer">${
|
|
1163
|
-
smart_count:
|
|
1182
|
+
counts: `<a class="gt-link gt-link-counts" href="${issue?.html_url}" target="_blank" rel="noopener noreferrer">${commentsCount}</a>`,
|
|
1183
|
+
smart_count: commentsCount,
|
|
1164
1184
|
}),
|
|
1165
1185
|
}}
|
|
1166
1186
|
/>
|
package/lib/i18n/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gitalk-react",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.6",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "LolipopJ",
|
|
7
7
|
"email": "mail@towind.fun",
|
|
8
8
|
"url": "https://github.com/LolipopJ"
|
|
9
9
|
},
|
|
10
|
-
"
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/LolipopJ/gitalk-react.git"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://lolipopj.github.io/gitalk-react",
|
|
11
15
|
"license": "MIT",
|
|
12
16
|
"type": "module",
|
|
13
17
|
"files": [
|