From d790961a5ddd034bed3e704fec9f0e1936737753 Mon Sep 17 00:00:00 2001 From: Tom Date: Wed, 31 May 2023 15:44:15 +0200 Subject: [PATCH] add edit label and original comment modal --- src/components/EditLabel.jsx | 40 ++++++++++++ src/components/modals/EditModal.jsx | 2 +- .../modals/OriginalCommentModal.jsx | 64 +++++++++++++++++++ src/components/views/Board.jsx | 62 ++++++++++++++---- src/components/views/Thread.jsx | 15 ++++- 5 files changed, 167 insertions(+), 16 deletions(-) create mode 100644 src/components/EditLabel.jsx create mode 100644 src/components/modals/OriginalCommentModal.jsx diff --git a/src/components/EditLabel.jsx b/src/components/EditLabel.jsx new file mode 100644 index 00000000..af872279 --- /dev/null +++ b/src/components/EditLabel.jsx @@ -0,0 +1,40 @@ +import React from "react"; +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 }) => { + const [isOriginalCommentModalOpen, setIsOriginalCommentModalOpen] = React.useState(false); + const comment = useComment({commentCid}); + const timestamp = getDate(comment.edit?.timestamp); + const {state: editedCommentState, editedComment} = useEditedComment({comment}); + + return ( + <> + setIsOriginalCommentModalOpen(false)} + comment={comment}/> + {editedComment && ( + <> +
+ + {editedCommentState === 'succeeded' && ( + <> + (Edited at {timestamp}, setIsOriginalCommentModalOpen(true) + }>show original) + + )} + {editedCommentState === 'pending' && ("(Pending Edit)")} + {editedCommentState === 'failed' && ("(Failed Edit)")} + + + )} + + ); +}; + +export default EditLabel; \ No newline at end of file diff --git a/src/components/modals/EditModal.jsx b/src/components/modals/EditModal.jsx index b7fa6713..b97a363d 100644 --- a/src/components/modals/EditModal.jsx +++ b/src/components/modals/EditModal.jsx @@ -21,7 +21,6 @@ const EditModal = ({ isOpen, closeModal, originalCommentContent }) => { const handleResize = () => setIsMobile(window.innerWidth <= 480); window.addEventListener('resize', handleResize); - // Cleanup function return () => { window.removeEventListener('resize', handleResize); }; @@ -33,6 +32,7 @@ const EditModal = ({ isOpen, closeModal, originalCommentContent }) => { closeModal(); }; + return ( { + const { + selectedStyle, + } = useGeneralStore(state => state); + + const [isMobile, setIsMobile] = useState(window.innerWidth <= 480); + const nodeRef = React.useRef(null); + const originalCommentContent = comment.original?.content; + const timestamp = getDate(comment.timestamp); + + + useEffect(() => { + const handleResize = () => setIsMobile(window.innerWidth <= 480); + window.addEventListener('resize', handleResize); + + return () => { + window.removeEventListener('resize', handleResize); + }; + }, [setIsMobile]); + + + return ( + + +
+
+ Original at {timestamp} +
+
+
+