Retrieve profile picture
This commit is contained in:
@@ -3,19 +3,20 @@ import instance from "../security/http";
|
|||||||
import config from "../config";
|
import config from "../config";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Avatar, Button, Dropdown, DropdownItem, DropdownMenu, DropdownTrigger } from "@nextui-org/react";
|
import { Avatar, Button, Dropdown, DropdownItem, DropdownMenu, DropdownTrigger, User } from "@nextui-org/react";
|
||||||
import { ChatBubbleOvalLeftEllipsisIcon, EllipsisHorizontalIcon, HandThumbsUpIcon } from "../icons";
|
import { ChatBubbleOvalLeftEllipsisIcon, EllipsisHorizontalIcon, HandThumbsUpIcon } from "../icons";
|
||||||
|
|
||||||
interface Comment {
|
interface Comment {
|
||||||
id: string;
|
id: string;
|
||||||
content: string;
|
content: string;
|
||||||
|
user: User; // Make user optional
|
||||||
}
|
}
|
||||||
|
|
||||||
// type User = {
|
interface User {
|
||||||
// id: string;
|
id: string;
|
||||||
// firstName: string;
|
firstName: string;
|
||||||
// lastName: string;
|
lastName: string;
|
||||||
// };
|
}
|
||||||
|
|
||||||
export default function CommentsModule() {
|
export default function CommentsModule() {
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
@@ -27,6 +28,7 @@ export default function CommentsModule() {
|
|||||||
instance
|
instance
|
||||||
.get(config.serverAddress + `/post/${postId}/getComments`).then((res) => {
|
.get(config.serverAddress + `/post/${postId}/getComments`).then((res) => {
|
||||||
setCommentList(res.data);
|
setCommentList(res.data);
|
||||||
|
console.log(res.data);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -45,21 +47,24 @@ export default function CommentsModule() {
|
|||||||
<div className="w-8/12 mx-auto">
|
<div className="w-8/12 mx-auto">
|
||||||
{commentList.length > 0 ? (
|
{commentList.length > 0 ? (
|
||||||
commentList.map((comment) => {
|
commentList.map((comment) => {
|
||||||
|
// console.log(comment); // Log each comment to verify its structure
|
||||||
|
// // Check if `comment.user` is defined before accessing properties
|
||||||
|
// const user = comment.user || { firstName: "Unknown", lastName: "" };
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col w-full bg-primary-50 dark:bg-primary-950 rounded-xl mb-2 p-3 mx-auto"
|
<div className="flex flex-col w-full bg-primary-50 dark:bg-primary-950 rounded-xl mb-2 p-3 mx-auto"
|
||||||
key={comment.id}>
|
key={comment.id}>
|
||||||
<div className="flex flex-row w-full">
|
<div className="flex flex-row flex-shrink-0 w-full">
|
||||||
<div>
|
<div>
|
||||||
<Avatar
|
<Avatar
|
||||||
src="https://pbs.twimg.com/media/GOva9x5a0AAK8Bn?format=jpg&name=large"
|
src="https://pbs.twimg.com/media/GOva9x5a0AAK8Bn?format=jpg&name=large"
|
||||||
size="md"
|
size="md"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col w-10/12 text-sm ml-3">
|
<div className="flex flex-col w-10/12 flex-grow text-sm ml-3">
|
||||||
<div className="font-bold">Name</div>
|
<div className="font-bold">Name</div>
|
||||||
<div className="break-words whitespace-pre-wrap">{comment.content}</div>
|
<div className="break-words whitespace-pre-wrap">{comment.content}</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-10">
|
<div className="flex-shrink-0 ml-10">
|
||||||
<div className="flex flex-row-reverse justify-center items-center size-7">
|
<div className="flex flex-row-reverse justify-center items-center size-7">
|
||||||
<Dropdown>
|
<Dropdown>
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ type User = {
|
|||||||
id: string;
|
id: string;
|
||||||
firstName: string;
|
firstName: string;
|
||||||
lastName: string;
|
lastName: string;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function CommunityPage() {
|
export default function CommunityPage() {
|
||||||
@@ -57,7 +58,6 @@ export default function CommunityPage() {
|
|||||||
const [userInformation, setUserInformation] = useState<Record<string, User>>({});
|
const [userInformation, setUserInformation] = useState<Record<string, User>>({});
|
||||||
const [currentUserInfo, setCurrentUserInfo] = useState(null);
|
const [currentUserInfo, setCurrentUserInfo] = useState(null);
|
||||||
|
|
||||||
|
|
||||||
let accessToken = localStorage.getItem("accessToken");
|
let accessToken = localStorage.getItem("accessToken");
|
||||||
if (!accessToken) {
|
if (!accessToken) {
|
||||||
return (
|
return (
|
||||||
@@ -89,6 +89,7 @@ export default function CommunityPage() {
|
|||||||
const fetchUserInformation = async (userId: string) => {
|
const fetchUserInformation = async (userId: string) => {
|
||||||
try {
|
try {
|
||||||
const user = await retrieveUserInformationById(userId);
|
const user = await retrieveUserInformationById(userId);
|
||||||
|
|
||||||
setUserInformation((prevMap) => ({
|
setUserInformation((prevMap) => ({
|
||||||
...prevMap,
|
...prevMap,
|
||||||
[userId]: user,
|
[userId]: user,
|
||||||
@@ -168,6 +169,11 @@ export default function CommunityPage() {
|
|||||||
navigate(`post/${id}`);
|
navigate(`post/${id}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Get pfp from server directly(no need convert blob to url)
|
||||||
|
const getProfilePicture = (userId: string): string => {
|
||||||
|
return `${config.serverAddress}/users/profile-image/${userId}`;
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full h-full">
|
<div className="w-full h-full">
|
||||||
<div className="flex flex-row gap-4 m-10">
|
<div className="flex flex-row gap-4 m-10">
|
||||||
@@ -180,6 +186,7 @@ export default function CommunityPage() {
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
{communityList.map((post) => {
|
{communityList.map((post) => {
|
||||||
|
const profilePictureUrl = getProfilePicture(post.userId);
|
||||||
return (
|
return (
|
||||||
<section
|
<section
|
||||||
className="flex flex-row gap-4 bg-primary-50 dark:bg-primary-950 border border-none rounded-2xl p-4"
|
className="flex flex-row gap-4 bg-primary-50 dark:bg-primary-950 border border-none rounded-2xl p-4"
|
||||||
@@ -188,7 +195,7 @@ export default function CommunityPage() {
|
|||||||
>
|
>
|
||||||
<div onClick={(e) => e.stopPropagation()}>
|
<div onClick={(e) => e.stopPropagation()}>
|
||||||
<Avatar
|
<Avatar
|
||||||
src="https://pbs.twimg.com/media/GOva9x5a0AAK8Bn?format=jpg&name=large"
|
src={profilePictureUrl}
|
||||||
size="lg"
|
size="lg"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -77,6 +77,11 @@ const PostPage: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}, [post]);
|
}, [post]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Scroll to the top of the page when the component mounts
|
||||||
|
window.scrollTo(0, 0);
|
||||||
|
}, []);
|
||||||
|
|
||||||
if (!post) {
|
if (!post) {
|
||||||
return (
|
return (
|
||||||
<div className="flex justify-center min-h-screen">
|
<div className="flex justify-center min-h-screen">
|
||||||
@@ -102,6 +107,11 @@ const PostPage: React.FC = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getProfilePicture = (userId: string): string => {
|
||||||
|
return `${config.serverAddress}/users/profile-image/${userId}`;
|
||||||
|
};
|
||||||
|
const profilePictureUrl = post ? getProfilePicture(post.userId) : "";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full h-full">
|
<div className="w-full h-full">
|
||||||
<section className="flex">
|
<section className="flex">
|
||||||
@@ -124,7 +134,7 @@ const PostPage: React.FC = () => {
|
|||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<Avatar
|
<Avatar
|
||||||
src="https://pbs.twimg.com/media/GOva9x5a0AAK8Bn?format=jpg&name=large"
|
src={profilePictureUrl}
|
||||||
size="lg"
|
size="lg"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const { Post, Comment } = require('../models');
|
const { Post, Comment, User } = require('../models');
|
||||||
const { Op, where } = require("sequelize");
|
const { Op, where } = require("sequelize");
|
||||||
const yup = require("yup");
|
const yup = require("yup");
|
||||||
const multer = require("multer");
|
const multer = require("multer");
|
||||||
@@ -184,6 +184,12 @@ router.get("/:id/getComments", async (req, res) => {
|
|||||||
|
|
||||||
let condition = {
|
let condition = {
|
||||||
where: { postId: id },
|
where: { postId: id },
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: User,
|
||||||
|
attributes: ['id', 'firstName', 'lastName'] // Specify the attributes you need
|
||||||
|
}
|
||||||
|
],
|
||||||
order: [['createdAt', 'DESC']]
|
order: [['createdAt', 'DESC']]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user