mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-25 05:41:13 +00:00
Merge branch 'main' into add_open_links_in_new_tab_1
This commit is contained in:
commit
44bbd01fb7
2 changed files with 30 additions and 14 deletions
|
@ -389,6 +389,9 @@ export class Post extends Component<any, PostState> {
|
||||||
onMarkPostAsRead={this.handleMarkPostAsRead}
|
onMarkPostAsRead={this.handleMarkPostAsRead}
|
||||||
/>
|
/>
|
||||||
<div ref={this.state.commentSectionRef} className="mb-2" />
|
<div ref={this.state.commentSectionRef} className="mb-2" />
|
||||||
|
|
||||||
|
{/* Only show the top level comment form if its not a context view */}
|
||||||
|
{!this.state.commentId && (
|
||||||
<CommentForm
|
<CommentForm
|
||||||
node={res.post_view.post.id}
|
node={res.post_view.post.id}
|
||||||
disabled={res.post_view.post.locked}
|
disabled={res.post_view.post.locked}
|
||||||
|
@ -398,6 +401,7 @@ export class Post extends Component<any, PostState> {
|
||||||
onUpsertComment={this.handleCreateComment}
|
onUpsertComment={this.handleCreateComment}
|
||||||
finished={this.state.finished.get(0)}
|
finished={this.state.finished.get(0)}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
<div className="d-block d-md-none">
|
<div className="d-block d-md-none">
|
||||||
<button
|
<button
|
||||||
className="btn btn-secondary d-inline-block mb-2 me-3"
|
className="btn btn-secondary d-inline-block mb-2 me-3"
|
||||||
|
@ -1034,13 +1038,21 @@ export class Post extends Component<any, PostState> {
|
||||||
createAndUpdateComments(res: RequestState<CommentResponse>) {
|
createAndUpdateComments(res: RequestState<CommentResponse>) {
|
||||||
this.setState(s => {
|
this.setState(s => {
|
||||||
if (s.commentsRes.state === "success" && res.state === "success") {
|
if (s.commentsRes.state === "success" && res.state === "success") {
|
||||||
s.commentsRes.data.comments.unshift(res.data.comment_view);
|
// The comment must be inserted not at the very beginning of the list,
|
||||||
|
// because the buildCommentsTree needs a correct path ordering.
|
||||||
|
// It should be inserted right after its parent is found
|
||||||
|
const comments = s.commentsRes.data.comments;
|
||||||
|
const newComment = res.data.comment_view;
|
||||||
|
const newCommentParentId = getCommentParentId(newComment.comment);
|
||||||
|
|
||||||
|
const foundCommentParentIndex = comments.findIndex(
|
||||||
|
c => c.comment.id === newCommentParentId,
|
||||||
|
);
|
||||||
|
|
||||||
|
comments.splice(foundCommentParentIndex + 1, 0, newComment);
|
||||||
|
|
||||||
// Set finished for the parent
|
// Set finished for the parent
|
||||||
s.finished.set(
|
s.finished.set(newCommentParentId ?? 0, true);
|
||||||
getCommentParentId(res.data.comment_view.comment) ?? 0,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
});
|
});
|
||||||
|
|
|
@ -32,6 +32,10 @@ export default function buildCommentsTree(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This should not be sorted on the front end, in order to preserve the
|
||||||
|
// back end sorts. However, the parent ids must be sorted, so make sure
|
||||||
|
// When adding new comments to trees, that they're inserted right after
|
||||||
|
// their parent index. This is done in post.tsx
|
||||||
for (const comment_view of comments) {
|
for (const comment_view of comments) {
|
||||||
const child = map.get(comment_view.comment.id);
|
const child = map.get(comment_view.comment.id);
|
||||||
if (child) {
|
if (child) {
|
||||||
|
|
Loading…
Reference in a new issue