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

View file

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

View file

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