* 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:
parent
698bd5eef1
commit
e5795baa10
3 changed files with 14 additions and 11 deletions
|
@ -35,6 +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,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function CommentCreate(props: Props) {
|
export function CommentCreate(props: Props) {
|
||||||
|
@ -53,6 +54,7 @@ export function CommentCreate(props: Props) {
|
||||||
toast,
|
toast,
|
||||||
claimIsMine,
|
claimIsMine,
|
||||||
sendTip,
|
sendTip,
|
||||||
|
setjustCommented,
|
||||||
} = props;
|
} = props;
|
||||||
const buttonref: ElementRef<any> = React.useRef();
|
const buttonref: ElementRef<any> = React.useRef();
|
||||||
const {
|
const {
|
||||||
|
@ -151,6 +153,7 @@ export function CommentCreate(props: Props) {
|
||||||
setLastCommentTime(Date.now());
|
setLastCommentTime(Date.now());
|
||||||
setIsReviewingSupportComment(false);
|
setIsReviewingSupportComment(false);
|
||||||
setIsSupportComment(false);
|
setIsSupportComment(false);
|
||||||
|
setjustCommented(true);
|
||||||
|
|
||||||
if (onDoneReplying) {
|
if (onDoneReplying) {
|
||||||
onDoneReplying();
|
onDoneReplying();
|
||||||
|
|
|
@ -58,6 +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 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;
|
||||||
|
@ -146,7 +147,7 @@ function CommentList(props: Props) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default to newest first for apps that don't have comment reactions
|
// 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
|
const displayedComments = readyToDisplayComments
|
||||||
? prepareComments(sortedComments, linkedComment).slice(start, end)
|
? prepareComments(sortedComments, linkedComment).slice(start, end)
|
||||||
: [];
|
: [];
|
||||||
|
@ -209,7 +210,7 @@ function CommentList(props: Props) {
|
||||||
}
|
}
|
||||||
actions={
|
actions={
|
||||||
<>
|
<>
|
||||||
<CommentCreate uri={uri} />
|
<CommentCreate uri={uri} setjustCommented={setjustCommented} />
|
||||||
|
|
||||||
{!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?')} />
|
||||||
|
|
|
@ -10,14 +10,13 @@ type SortProps = {
|
||||||
reactionsById: {},
|
reactionsById: {},
|
||||||
sort: string,
|
sort: string,
|
||||||
isMyComment: string => boolean,
|
isMyComment: string => boolean,
|
||||||
|
justCommented: boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function sortComments(sortProps: SortProps): Array<Comment> {
|
export function sortComments(sortProps: SortProps): Array<Comment> {
|
||||||
const { comments, reactionsById, sort, isMyComment } = sortProps;
|
const { comments, reactionsById, sort, isMyComment, justCommented } = sortProps;
|
||||||
|
|
||||||
if (!comments) {
|
if (!comments) return [];
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return comments.slice().sort((a: Comment, b: Comment) => {
|
return comments.slice().sort((a: Comment, b: Comment) => {
|
||||||
if (a.is_pinned) {
|
if (a.is_pinned) {
|
||||||
|
@ -26,16 +25,16 @@ export function sortComments(sortProps: SortProps): Array<Comment> {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sort === SORT_COMMENTS_NEW) {
|
if (sort === SORT_COMMENTS_NEW) return 0;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 bIsMyRecent = b.comment_id === comments[0].comment_id;
|
||||||
|
|
||||||
if (aIsMine) {
|
if (aIsMine && justCommented && aIsMyRecent) {
|
||||||
return -1;
|
return -1;
|
||||||
} else if (bIsMine) {
|
} else if (bIsMine && justCommented && bIsMyRecent) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue