diff --git a/lionblog-taehyeong/src/App.js b/lionblog-taehyeong/src/App.js index 59c5f9c9..87f2c086 100644 --- a/lionblog-taehyeong/src/App.js +++ b/lionblog-taehyeong/src/App.js @@ -16,7 +16,7 @@ export const DarkModeContext = createContext(false); export const PostsDataContext = createContext(null); function App() { - const [darkMode, setDarkMode] = useState(false); + const [darkMode, setDarkMode] = useState(true); const darkModeToggle = () => setDarkMode(!darkMode); diff --git a/lionblog-taehyeong/src/components/Comment/CommentElement.jsx b/lionblog-taehyeong/src/components/Comment/CommentElement.jsx new file mode 100644 index 00000000..cb651fb4 --- /dev/null +++ b/lionblog-taehyeong/src/components/Comment/CommentElement.jsx @@ -0,0 +1,84 @@ +import { useState, useEffect } from "react"; + +const CommentElement = ({ comment, handleCommentDelete }) => { + const [isEditMode, setIsEditMode] = useState(false); + const [content, setContent] = useState(comment.content); + const [editInputValue, setEditInputValue] = useState(""); + + // comment created_at 전처리 + const date = new Intl.DateTimeFormat("en-CA", { + formatString: "yyyy.mm.dd", + + year: "numeric", + month: "2-digit", + day: "2-digit", + }) + .format(new Date(comment.created_at)) + .replaceAll("-", "."); + + const handleEditComment = (e) => { + e.preventDefault(); + setContent(editInputValue); + setIsEditMode(false); + setEditInputValue(""); + }; + + const toEditMode = (e) => { + e.preventDefault(); + setIsEditMode(true); + }; + + const toShowMode = (e) => { + e.preventDefault(); + setIsEditMode(false); + }; + + useEffect(() => { + // add api call to check if user is the author of the comment + }, []); + + return ( +
{content}
+ )} + + {date} +