diff --git a/client/package.json b/client/package.json index 48079c3..5090252 100644 --- a/client/package.json +++ b/client/package.json @@ -22,10 +22,13 @@ "react-chartjs-2": "^5.2.0", "react-dom": "^18.2.0", "react-hot-toast": "^2.4.1", + "react-markdown": "^9.0.1", "react-router-dom": "^6.23.1", + "remark-gfm": "^4.0.0", "yup": "^1.4.0" }, "devDependencies": { + "@tailwindcss/typography": "^0.5.14", "@types/react": "^18.2.66", "@types/react-dom": "^18.2.22", "@typescript-eslint/eslint-plugin": "^7.2.0", diff --git a/client/src/pages/CommunityPage.tsx b/client/src/pages/CommunityPage.tsx index 9760603..d4dca69 100644 --- a/client/src/pages/CommunityPage.tsx +++ b/client/src/pages/CommunityPage.tsx @@ -30,7 +30,8 @@ import { import { useNavigate } from "react-router-dom"; import { retrieveUserInformationById } from "../security/usersbyid"; import { retrieveUserInformation } from "../security/users"; -// import UserPostImage from "../components/UserPostImage"; +import Markdown from "react-markdown"; +import remarkGfm from "remark-gfm"; interface Post { title: string; @@ -58,8 +59,12 @@ export default function CommunityPage() { const [selectedPost, setSelectedPost] = useState(null); const [communityList, setCommunityList] = useState([]); const [search, setSearch] = useState(""); // Search Function - const [userInformation, setUserInformation] = useState>({}); - const [imageErrorFlags, setImageErrorFlags] = useState>({}); + const [userInformation, setUserInformation] = useState>( + {} + ); + const [imageErrorFlags, setImageErrorFlags] = useState< + Record + >({}); const [tags, setTags] = useState([]); const [selectedTag, setSelectedTag] = useState(null); const [currentUserId, setCurrentUserId] = useState(null); @@ -147,7 +152,7 @@ export default function CommunityPage() { const getCurrentUserInformation = async () => { try { const user = await retrieveUserInformation(); // Get the user information - console.log(user) + console.log(user); setCurrentUserId(user.id); // Store user ID } catch (error) { console.error(error); @@ -291,14 +296,17 @@ export default function CommunityPage() {
-

{post.content}

+ + {post.content} +
{imageErrorFlags[post.id] ? null : (
handleImageError(post.id)} /> + onError={() => handleImageError(post.id)} + />
)} @@ -362,7 +370,9 @@ export default function CommunityPage() { handleTagClick(tag.tag)} - className={selectedTag === tag.tag ? "bg-primary-500 text-white" : ""} + className={ + selectedTag === tag.tag ? "bg-primary-500 text-white" : "" + } > {tag.tag} @@ -370,10 +380,7 @@ export default function CommunityPage() {
{selectedTag && ( - )} diff --git a/client/src/pages/PostPage.tsx b/client/src/pages/PostPage.tsx index 444dab4..2b1ee3a 100644 --- a/client/src/pages/PostPage.tsx +++ b/client/src/pages/PostPage.tsx @@ -28,6 +28,8 @@ import { retrieveUserInformationById } from "../security/usersbyid"; import CommentInputModule from "../components/CommentInputModule"; import CommentsModule from "../components/CommentsModule"; import { retrieveUserInformation } from "../security/users"; +import remarkGfm from "remark-gfm"; +import Markdown from "react-markdown"; interface Post { title: string; @@ -55,14 +57,19 @@ const PostPage: React.FC = () => { const [post, setPost] = useState(null); const { isOpen, onOpen, onOpenChange } = useDisclosure(); const [selectedPost, setSelectedPost] = useState(null); - const [userInformation, setUserInformation] = useState>({}); - const [imageErrorFlags, setImageErrorFlags] = useState>({}); + const [userInformation, setUserInformation] = useState>( + {} + ); + const [imageErrorFlags, setImageErrorFlags] = useState< + Record + >({}); const [currentUserId, setCurrentUserId] = useState(null); useEffect(() => { if (id) { console.log("useEffect for fetching post called, id:", id); - instance.get(`${config.serverAddress}/post/${id}`) + instance + .get(`${config.serverAddress}/post/${id}`) .then((res) => { setPost(res.data); console.log("Post fetch successfully"); @@ -97,7 +104,7 @@ const PostPage: React.FC = () => { const getCurrentUserInformation = async () => { try { const user = await retrieveUserInformation(); // Get the user information - console.log(user) + console.log(user); setCurrentUserId(user.id); // Store user ID } catch (error) { console.error(error); @@ -169,23 +176,22 @@ const PostPage: React.FC = () => { key={post.id} >
- +

{post.title}

-

{userInformation[post.userId]?.firstName} {userInformation[post.userId]?.lastName}

+

+ {userInformation[post.userId]?.firstName}{" "} + {userInformation[post.userId]?.lastName} +

{currentUserId === post.userId && ( // Check if the current user is the post author - + @@ -215,17 +221,22 @@ const PostPage: React.FC = () => {
-

{post.content}

+ + {post.content} +
- {!imageErrorFlags[post.id] && post.postImage && post.postImage !== null && ( -
- PostImage handleImageError(post.id)} /> -
- )} + {!imageErrorFlags[post.id] && + post.postImage && + post.postImage !== null && ( +
+ PostImage handleImageError(post.id)} + /> +
+ )}
diff --git a/client/tailwind.config.js b/client/tailwind.config.js index de9c5c3..687d502 100644 --- a/client/tailwind.config.js +++ b/client/tailwind.config.js @@ -9,6 +9,7 @@ export default { ], darkMode: "class", plugins: [ + require("@tailwindcss/typography"), nextui({ themes: { "red-dark": {