improve logic for own comments showing first (#6073)

This commit is contained in:
saltrafael 2021-05-17 16:55:23 -03:00 committed by GitHub
parent 2a6df18b72
commit 31a84828cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 11 deletions

View file

@ -35,7 +35,7 @@ type Props = {
toast: (string) => void,
claimIsMine: boolean,
sendTip: ({}, (any) => void, (any) => void) => void,
setjustCommented: (boolean) => void,
justCommented: Array<string>,
};
export function CommentCreate(props: Props) {
@ -54,7 +54,7 @@ export function CommentCreate(props: Props) {
toast,
claimIsMine,
sendTip,
setjustCommented,
justCommented,
} = props;
const buttonref: ElementRef<any> = React.useRef();
const {
@ -153,7 +153,7 @@ export function CommentCreate(props: Props) {
setLastCommentTime(Date.now());
setIsReviewingSupportComment(false);
setIsSupportComment(false);
setjustCommented(true);
justCommented.push(res.comment_id);
if (onDoneReplying) {
onDoneReplying();

View file

@ -58,7 +58,7 @@ function CommentList(props: Props) {
const [readyToDisplayComments, setReadyToDisplayComments] = React.useState(
Boolean(reactionsById) || !ENABLE_COMMENT_REACTIONS
);
const [justCommented, setjustCommented] = React.useState(false);
const [justCommented] = React.useState([]);
const linkedCommentId = linkedComment && linkedComment.comment_id;
const hasNoComments = !totalComments;
const moreBelow = totalComments - end > 0;
@ -210,7 +210,7 @@ function CommentList(props: Props) {
}
actions={
<>
<CommentCreate uri={uri} setjustCommented={setjustCommented} />
<CommentCreate uri={uri} justCommented={justCommented} />
{!isFetchingComments && hasNoComments && (
<Empty padded text={__('That was pretty deep. What do you think?')} />

View file

@ -9,8 +9,8 @@ type SortProps = {
comments: ?Array<Comment>,
reactionsById: {},
sort: string,
isMyComment: string => boolean,
justCommented: boolean,
isMyComment: (string) => boolean,
justCommented: Array<string>,
};
export function sortComments(sortProps: SortProps): Array<Comment> {
@ -29,12 +29,12 @@ export function sortComments(sortProps: SortProps): Array<Comment> {
const aIsMine = isMyComment(a.channel_id);
const bIsMine = isMyComment(b.channel_id);
const aIsMyRecent = a.comment_id === comments[0].comment_id;
const bIsMyRecent = b.comment_id === comments[0].comment_id;
const aIsMyRecent = justCommented.includes(a.comment_id);
const bIsMyRecent = justCommented.includes(b.comment_id);
if (aIsMine && justCommented && aIsMyRecent) {
if (aIsMine && justCommented.length && aIsMyRecent) {
return -1;
} else if (bIsMine && justCommented && bIsMyRecent) {
} else if (bIsMine && justCommented.length && bIsMyRecent) {
return 1;
}