diff --git a/frontend/src/components/comment_input.tsx b/frontend/src/components/comment_input.tsx
index b9cdfe6..26b7f41 100644
--- a/frontend/src/components/comment_input.tsx
+++ b/frontend/src/components/comment_input.tsx
@@ -173,7 +173,7 @@ export function CommentInput({
)}
-
+
{t("Use markdown format")}
diff --git a/frontend/src/components/comment_tile.tsx b/frontend/src/components/comment_tile.tsx
index d99f45e..a3066f5 100644
--- a/frontend/src/components/comment_tile.tsx
+++ b/frontend/src/components/comment_tile.tsx
@@ -1,22 +1,15 @@
-import { useState } from "react";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router";
import {
MdOutlineComment,
- MdOutlineDelete,
- MdOutlineEdit,
} from "react-icons/md";
-import { TextArea } from "./input";
import { Comment } from "../network/models";
import { network } from "../network/network";
import Badge from "./badge";
-import { app } from "../app";
-import showToast from "./toast";
import Markdown from "react-markdown";
export function CommentTile({
comment,
- onUpdated,
elevation,
}: {
comment: Comment;
@@ -79,196 +72,11 @@ export function CommentTile({
{comment.reply_count}
)}
- {app.user?.id === comment.user.id && (
- <>
-
-
- >
- )}
);
}
-function EditCommentDialog({
- comment,
- onUpdated,
-}: {
- comment: Comment;
- onUpdated?: () => void;
-}) {
- const [isLoading, setLoading] = useState(false);
- const [content, setContent] = useState(comment.content);
- const { t } = useTranslation();
-
- const handleUpdate = async () => {
- if (isLoading) {
- return;
- }
- setLoading(true);
- const res = await network.updateComment(comment.id, content);
- const dialog = document.getElementById(
- `edit_comment_dialog_${comment.id}`,
- ) as HTMLDialogElement;
- dialog.close();
- if (res.success) {
- showToast({
- message: t("Comment updated successfully"),
- type: "success",
- });
- if (onUpdated) {
- onUpdated();
- }
- } else {
- showToast({
- message: res.message,
- type: "error",
- parent: document.getElementById(`dialog_box`),
- });
- }
- setLoading(false);
- };
-
- return (
- <>
-
-
- >
- );
-}
-
-function DeleteCommentDialog({
- commentId,
- onUpdated,
-}: {
- commentId: number;
- onUpdated?: () => void;
-}) {
- const [isLoading, setLoading] = useState(false);
- const { t } = useTranslation();
-
- const id = `delete_comment_dialog_${commentId}`;
-
- const handleDelete = async () => {
- if (isLoading) return;
- setLoading(true);
- const res = await network.deleteComment(commentId);
- const dialog = document.getElementById(id) as HTMLDialogElement;
- dialog.close();
- if (res.success) {
- showToast({
- message: t("Comment deleted successfully"),
- type: "success",
- });
- if (onUpdated) {
- onUpdated();
- }
- } else {
- showToast({ message: res.message, type: "error" });
- }
- setLoading(false);
- };
-
- return (
- <>
-
-
- >
- );
-}
-
export function CommentContent({ content }: { content: string }) {
const lines = content.split("\n");
for (let i = 0; i < lines.length; i++) {
diff --git a/frontend/src/pages/comment_page.tsx b/frontend/src/pages/comment_page.tsx
index 517494b..60f150b 100644
--- a/frontend/src/pages/comment_page.tsx
+++ b/frontend/src/pages/comment_page.tsx
@@ -11,6 +11,9 @@ import { CommentInput } from "../components/comment_input";
import { CommentTile } from "../components/comment_tile";
import { Comment } from "../network/models";
import Pagination from "../components/pagination";
+import { MdOutlineDelete, MdOutlineEdit } from "react-icons/md";
+import { TextArea } from "../components/input";
+import { app } from "../app";
export default function CommentPage() {
const params = useParams();
@@ -41,6 +44,39 @@ export default function CommentPage() {
});
}, [commentId]);
+ const onUpdated = useCallback(() => {
+ setComment(null);
+ const id = parseInt(commentId || "0");
+ if (isNaN(id) || id <= 0) {
+ showToast({
+ message: t("Invalid comment ID"),
+ type: "error",
+ });
+ return;
+ }
+ network.getComment(id).then((res) => {
+ if (res.success) {
+ setComment(res.data!);
+ } else {
+ showToast({
+ message: res.message,
+ type: "error",
+ });
+ }
+ });
+ }, []);
+
+ const onDeleted = useCallback(() => {
+ // check history length
+ if (window.history.length > 1) {
+ // go back to the previous page
+ navigate(-1);
+ } else {
+ // if there is no previous page, go to the home page
+ navigate("/");
+ }
+ }, [navigate]);
+
useEffect(() => {
document.title = t("Comment Details");
});
@@ -52,6 +88,8 @@ export default function CommentPage() {
return (
{comment.resource &&
}
+ {comment.reply_to &&
}
+