own comments show first in controversial / best #5905 (#5939)

* own comments show first in controversial / best #5905

* workaround to place my recent comment at the top

* only most recent comment

* lint fix

Co-authored-by: Thomas Zarebczan <thomas.zarebczan@gmail.com>
This commit is contained in:
saltrafael 2021-05-15 01:56:58 -03:00 committed by GitHub
parent 698bd5eef1
commit e5795baa10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 11 deletions

View file

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

View file

@ -58,6 +58,7 @@ function CommentList(props: Props) {
const [readyToDisplayComments, setReadyToDisplayComments] = React.useState(
Boolean(reactionsById) || !ENABLE_COMMENT_REACTIONS
);
const [justCommented, setjustCommented] = React.useState(false);
const linkedCommentId = linkedComment && linkedComment.comment_id;
const hasNoComments = !totalComments;
const moreBelow = totalComments - end > 0;
@ -146,7 +147,7 @@ function CommentList(props: Props) {
}
// Default to newest first for apps that don't have comment reactions
const sortedComments = reactionsById ? sortComments({ comments, reactionsById, sort, isMyComment }) : [];
const sortedComments = reactionsById ? sortComments({ comments, reactionsById, sort, isMyComment, justCommented }) : [];
const displayedComments = readyToDisplayComments
? prepareComments(sortedComments, linkedComment).slice(start, end)
: [];
@ -209,7 +210,7 @@ function CommentList(props: Props) {
}
actions={
<>
<CommentCreate uri={uri} />
<CommentCreate uri={uri} setjustCommented={setjustCommented} />
{!isFetchingComments && hasNoComments && (
<Empty padded text={__('That was pretty deep. What do you think?')} />

View file

@ -10,14 +10,13 @@ type SortProps = {
reactionsById: {},
sort: string,
isMyComment: string => boolean,
justCommented: boolean,
};
export function sortComments(sortProps: SortProps): Array<Comment> {
const { comments, reactionsById, sort, isMyComment } = sortProps;
const { comments, reactionsById, sort, isMyComment, justCommented } = sortProps;
if (!comments) {
return [];
}
if (!comments) return [];
return comments.slice().sort((a: Comment, b: Comment) => {
if (a.is_pinned) {
@ -26,16 +25,16 @@ export function sortComments(sortProps: SortProps): Array<Comment> {
return 1;
}
if (sort === SORT_COMMENTS_NEW) {
return 0;
}
if (sort === SORT_COMMENTS_NEW) return 0;
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;
if (aIsMine) {
if (aIsMine && justCommented && aIsMyRecent) {
return -1;
} else if (bIsMine) {
} else if (bIsMine && justCommented && bIsMyRecent) {
return 1;
}