import React from "react"; import { Box, Divider, Flex, Heading, HStack, Image, Text, useColorModeValue, Wrap, WrapItem, } from "@chakra-ui/react"; import CustomAvatar from "../../utils/CustomAvatar"; import ManangePost from "../post/ManangePost"; import { nanoid } from "@reduxjs/toolkit"; import LangTag from "../../utils/LangTag"; import { htmlToJsx } from "../../helper/htmlToJsx"; import converter from "../../helper/converter"; import Discussion from "../discussion/Discussion"; import { useNavigate } from "react-router-dom"; import { useAuth } from "../../context/auth"; import AllComment from "../comment/AllComment"; import { dateFormat, showEditedDate } from "../../helper/calcTimestamp"; import { useRef } from "react"; import { useEffect } from "react"; import { useSelector } from "react-redux"; import useClickTag from "../../hooks/useClickTag"; import hljs from "highlight.js"; const MainContent = ({ postDetail }) => { const navigate = useNavigate(); const user = useAuth(); const discussionBoxRef = useRef(); const { clickComment } = useSelector((state) => state.scrollDiscussion); const handleClickTag = useClickTag(); // scroll to useEffect(() => { const scrollHeight = window.pageYOffset + discussionBoxRef.current?.getBoundingClientRect().top - 60; if (clickComment) { setTimeout(() => window.scrollTo({ top: scrollHeight }), 0); } else { window.scrollTo(0, 0); } }, [clickComment, postDetail.id]); // syntax highlighting useEffect(() => { hljs.highlightAll(); }, [postDetail.id]); const isAuthor = user?.userId === postDetail?.userId; const dividerColor = useColorModeValue("light.cardBorder", "dark.cardBorder"); const headingHover = useColorModeValue( "light.headingHover", "dark.headingHover" ); const ghostColor = useColorModeValue("light.ghostColor", "dark.ghostColor"); const colorTertiary = useColorModeValue( "light.colorTertiary", "dark.colorTertiary" ); return ( {/* coverImgae */} {postDetail.cvImg && ( cover_image )} {/* content */} navigate(`/${postDetail.username}`)} /> navigate(`/${postDetail.username}`)} > {postDetail.name} {postDetail.draft && ( Draft )} {postDetail.createdAt && ( Posted on {dateFormat(postDetail.createdAt)}{" "} {postDetail.updatedAt && ( {showEditedDate( postDetail.createdAt, postDetail.updatedAt ) ? `• Updated on ${dateFormat(postDetail.updatedAt)}` : "• Updated"} )} )} {/* manage post */} {isAuthor && postDetail && ( )} {postDetail.title} {postDetail.tags.length > 0 && ( {postDetail.tags.map((tag) => ( postDetail.draft ? () => {} // don't allow view tag if it's a draft : handleClickTag(e, tag.tagName) } > ))} )} {htmlToJsx(converter().makeHtml(postDetail.MDEValue))} {!postDetail.draft && ( )} {!postDetail.draft && ( )} {postDetail.comments.length !== 0 && ( )} ); }; export default MainContent;