Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions front_end/src/components/comment_feed/comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ const Comment: FC<CommentProps> = ({
const [isDeleted, setIsDeleted] = useState(comment.is_soft_deleted);
const [isReplying, setIsReplying] = useState(false);
const [commentMarkdown, setCommentMarkdown] = useState(comment.text);
const [tempCommentMarkdown, setTempCommentMarkdown] = useState("");
const [isReportModalOpen, setIsReportModalOpen] = useState(false);

const { user } = useAuth();
Expand Down Expand Up @@ -218,6 +219,7 @@ const Comment: FC<CommentProps> = ({
id: "edit",
name: t("edit"),
onClick: () => {
setTempCommentMarkdown(commentMarkdown);
setIsEditing(true);
},
},
Expand Down Expand Up @@ -346,15 +348,19 @@ const Comment: FC<CommentProps> = ({
)} */}

<div className="break-anywhere">
<MarkdownEditor
markdown={commentMarkdown}
mode={isEditing ? "write" : "read"}
onChange={(text) => {
setCommentMarkdown(text);
}}
/>
{isEditing && (
<MarkdownEditor
markdown={commentMarkdown}
mode={"write"}
onChange={setCommentMarkdown}
/>
)}{" "}
{!isEditing && (
<MarkdownEditor markdown={commentMarkdown} mode={"read"} />
)}
</div>
{isEditing && (
<>
<Button
onClick={async () => {
const response = await editComment({
Expand All @@ -364,13 +370,23 @@ const Comment: FC<CommentProps> = ({
});
if (response && "errors" in response) {
console.error(t("errorDeletingComment"), response.errors);
} else {
} else {
setIsEditing(false);
}
}}
>
{t("save")}
</Button>
<Button
className="ml-2"
onClick={() => {
setCommentMarkdown(tempCommentMarkdown);
setIsEditing(false);
}
}}
>
{t("save")}
</Button>
}}
>
{t("cancel")}
</Button>
</>
)}
<div className="mb-2 mt-1 h-7 overflow-visible">
<div className="flex items-center justify-between text-sm leading-4 text-gray-900 dark:text-gray-900-dark">
Expand Down