Fixed id, userId data type
This commit is contained in:
@@ -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<Post | null>(null);
|
||||
const [communityList, setCommunityList] = useState<Post[]>([]);
|
||||
const [search, setSearch] = useState(""); // Search Function
|
||||
const [userInformation, setUserInformation] = useState<Record<number, User>>({});
|
||||
const [userInformation, setUserInformation] = useState<Record<string, User>>({});
|
||||
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<string> } }) => {
|
||||
setSearch(e.target.value);
|
||||
};
|
||||
@@ -149,7 +165,7 @@ export default function CommunityPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handlePostClick = (id: number) => {
|
||||
const handlePostClick = (id: string) => {
|
||||
navigate(`post/${id}`);
|
||||
};
|
||||
|
||||
|
||||
@@ -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<Post | null>(null);
|
||||
const { isOpen, onOpen, onOpenChange } = useDisclosure();
|
||||
const [selectedPost, setSelectedPost] = useState<Post | null>(null);
|
||||
const [userInformation, setUserInformation] = useState<Record<number, User>>({});
|
||||
const [userInformation, setUserInformation] = useState<Record<string, User>>({});
|
||||
|
||||
useEffect(() => {
|
||||
if (id) {
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user