Files
5chan/src/components/EditLabel.jsx
T

48 lines
1.5 KiB
React
Raw Normal View History

2023-06-08 21:41:27 +02:00
import React, { useState } from "react";
2023-05-31 15:44:15 +02:00
import { useComment, useEditedComment } from "@plebbit/plebbit-react-hooks";
import { Link } from "react-router-dom";
import OriginalCommentModal from "./modals/OriginalCommentModal";
import getDate from "../utils/getDate";
const EditLabel = ({ commentCid, className }) => {
2023-06-08 21:41:27 +02:00
const [isOriginalCommentModalOpen, setIsOriginalCommentModalOpen] = useState(false);
2023-05-31 15:44:15 +02:00
const comment = useComment({commentCid});
const timestamp = getDate(comment.edit?.timestamp);
const {state: editedCommentState, editedComment} = useEditedComment({comment});
2023-06-08 21:41:27 +02:00
2023-05-31 15:44:15 +02:00
return (
<>
<OriginalCommentModal
isOpen={isOriginalCommentModalOpen}
closeModal={() => setIsOriginalCommentModalOpen(false)}
comment={comment}/>
2023-06-08 21:41:27 +02:00
{editedComment || comment.edit ? (
2023-05-31 15:44:15 +02:00
<>
<br />
<span className={className}>
2023-06-08 21:41:27 +02:00
{comment.removed ? (
2023-05-31 15:44:15 +02:00
<>
2023-06-08 21:41:27 +02:00
(This post has been removed)
2023-05-31 15:44:15 +02:00
</>
2023-06-08 21:41:27 +02:00
) : (
<>
{comment.edit ? (
<>
(Edited at {timestamp}, <Link className="ttl-link" onClick={
() => setIsOriginalCommentModalOpen(true)
}>show original</Link>)
</>
) : null}
{editedCommentState === 'pending' && ("(Pending edit)")}
{editedCommentState === 'failed' && ("(Failed edit)")}
</>
)}
2023-05-31 15:44:15 +02:00
</span>
</>
2023-06-08 21:41:27 +02:00
) : null}
2023-05-31 15:44:15 +02:00
</>
);
};
export default EditLabel;