diff --git a/client/src/pages/CommunityPage.tsx b/client/src/pages/CommunityPage.tsx index f700dc1..bbf1886 100644 --- a/client/src/pages/CommunityPage.tsx +++ b/client/src/pages/CommunityPage.tsx @@ -30,6 +30,7 @@ import { } from "../icons"; import { useNavigate } from "react-router-dom"; import { retrieveUserInformationById } from "../security/usersbyid"; +import { retrieveUserInformation } from "../security/users"; import { number } from "yup"; // import UserPostImage from "../components/UserPostImage"; @@ -38,12 +39,12 @@ interface Post { postImage: Blob; content: string; tags: string; - id: number; - userId: number; + id: string; + userId: string; } type User = { - id: number; + id: string; firstName: string; lastName: string; }; @@ -54,7 +55,9 @@ export default function CommunityPage() { const [selectedPost, setSelectedPost] = useState(null); const [communityList, setCommunityList] = useState([]); const [search, setSearch] = useState(""); // Search Function - const [userInformation, setUserInformation] = useState>({}); + const [userInformation, setUserInformation] = useState>({}); + const [currentUserInfo, setCurrentUserInfo] = useState(null); + let accessToken = localStorage.getItem("accessToken"); if (!accessToken) { @@ -84,7 +87,7 @@ export default function CommunityPage() { }, []); useEffect(() => { - const fetchUserInformation = async (userId: number) => { + const fetchUserInformation = async (userId: string) => { try { const user = await retrieveUserInformationById(userId); setUserInformation((prevMap) => ({ @@ -103,6 +106,19 @@ export default function CommunityPage() { }); }, [communityList]); + useEffect(() => { + const getCurrentUserInformation = async () => { + try { + const user = await retrieveUserInformation(); // Get the user ID + setCurrentUserInfo(user); // Set the user ID in the state + console.log(currentUserInfo); + } catch (error) { + console.error(error); + } + }; + getCurrentUserInformation(); + }, []); + const onSearchChange = (e: { target: { value: SetStateAction } }) => { setSearch(e.target.value); }; @@ -149,7 +165,7 @@ export default function CommunityPage() { } }; - const handlePostClick = (id: number) => { + const handlePostClick = (id: string) => { navigate(`post/${id}`); }; diff --git a/client/src/pages/PostPage.tsx b/client/src/pages/PostPage.tsx index 453f4cf..256852e 100644 --- a/client/src/pages/PostPage.tsx +++ b/client/src/pages/PostPage.tsx @@ -31,12 +31,12 @@ interface Post { postImage: Blob; content: string; tags: string; - id: number; - userId: number; + id: string; + userId: string; } type User = { - id: number; + id: string; firstName: string; lastName: string; }; @@ -47,7 +47,7 @@ const PostPage: React.FC = () => { const [post, setPost] = useState(null); const { isOpen, onOpen, onOpenChange } = useDisclosure(); const [selectedPost, setSelectedPost] = useState(null); - const [userInformation, setUserInformation] = useState>({}); + const [userInformation, setUserInformation] = useState>({}); useEffect(() => { if (id) { diff --git a/client/src/security/usersbyid.ts b/client/src/security/usersbyid.ts index 3ccd3d8..1cdfb26 100644 --- a/client/src/security/usersbyid.ts +++ b/client/src/security/usersbyid.ts @@ -2,7 +2,7 @@ import { AxiosError } from "axios"; import config from "../config"; import instance from "./http"; -export async function retrieveUserInformationById(userId: number) { +export async function retrieveUserInformationById(userId: string) { if (!localStorage.getItem("accessToken")) { throw "No access token"; } diff --git a/server/models/Post.js b/server/models/Post.js index 57712cc..ee79dc6 100644 --- a/server/models/Post.js +++ b/server/models/Post.js @@ -8,7 +8,7 @@ module.exports = (sequelize, DataTypes) => { }, title: { type: DataTypes.STRING(100), - allowNull: false + allowNull: false, }, postImage: { type: DataTypes.BLOB("long"), @@ -16,14 +16,15 @@ module.exports = (sequelize, DataTypes) => { }, content: { type: DataTypes.TEXT, - allowNull: false + allowNull: false, }, userId: { type: DataTypes.UUID, allowNull: false, }, }, { - tableName: 'posts' + tableName: 'posts', + timestamps: true, }); return Post;