Skip to content

Commit

Permalink
fix: fix existing comments sometimes jumping around after adding new …
Browse files Browse the repository at this point in the history
…comment
  • Loading branch information
sunaurus committed Apr 13, 2024
1 parent e752c34 commit 8e12ef5
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 17 deletions.
3 changes: 1 addition & 2 deletions src/app/comment/Comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const Comment = (props: {
const [editedContent, setEditedContent] = useState<string | null>(null);
const [deleted, setDeleted] = useState(props.commentView.comment.deleted);
const [addedReplies, setAddedReplies] = useState<CommentNode[]>([]);
const [saved, setSaved] = useOptimistic(props.commentView.saved);
const [saved, setSaved] = useState(props.commentView.saved);

const markdownProps =
editedContent !== null ? { content: editedContent } : props.markdown;
Expand Down Expand Up @@ -192,7 +192,6 @@ export const Comment = (props: {
action={async () => {
const action = toggleSaveCommentAction.bind(
null,
props.commentView.post.id,
props.commentView.comment.id,
!saved,
);
Expand Down
15 changes: 0 additions & 15 deletions src/app/comment/commentActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { CommentView } from "lemmy-js-client";
import { MarkdownProps } from "@/app/(ui)/markdown/Markdown";
import { ROOT_NODES_BATCH_SIZE } from "@/app/comment/constants";
import { redirect } from "next/navigation";
import { revalidatePath } from "next/cache";
import { getMarkdownWithRemoteImagesAction } from "@/app/(ui)/markdown/markdownActions";
import {
isLoggedIn,
Expand Down Expand Up @@ -111,8 +110,6 @@ export const createCommentAction = async (
content: data.get("content")?.toString() ?? "",
});

revalidatePath(`/comment/[id]`, "page");
revalidatePath(`/post/[id]`, "page");
if (parentId) {
return response.comment_view;
} else {
Expand All @@ -130,31 +127,22 @@ export const editCommentAction = async (
content,
});

revalidatePath(`/comment/[id]`, "page");
revalidatePath(`/post/[id]`, "page");
return response.comment_view;
};
export const deleteCommentAction = async (commentId: number) => {
await apiClient.deleteComment({
comment_id: commentId,
deleted: true,
});

revalidatePath(`/comment/[id]`, "page");
revalidatePath(`/post/[id]`, "page");
};
export const restoreCommentAction = async (commentId: number) => {
await apiClient.deleteComment({
comment_id: commentId,
deleted: false,
});

revalidatePath(`/comment/[id]`, "page");
revalidatePath(`/post/[id]`, "page");
};

export const toggleSaveCommentAction = async (
postId: number,
commentId: number,
currentlySaved: boolean,
) => {
Expand All @@ -167,7 +155,4 @@ export const toggleSaveCommentAction = async (
comment_id: commentId,
save: currentlySaved,
});
revalidatePath(`/post/${postId}`);
revalidatePath(`/comment/${commentId}`);
revalidatePath(`/saved`);
};
1 change: 1 addition & 0 deletions src/app/post/[id]/PostPageWithSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const Comments = async (props: {
<CommentsSection
commentRequestForm={commentRequestForm}
initialCommentTrees={initialCommentTrees}
loggedInUser={props.loggedInUser}
postId={props.postId}
singleCommentThreadRootId={props.singleCommentThreadRootId}
voteConfig={props.voteConfig}
Expand Down

0 comments on commit 8e12ef5

Please sign in to comment.