Fixed id, userId data type
This commit is contained in:
@@ -30,6 +30,7 @@ import {
|
|||||||
} from "../icons";
|
} from "../icons";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { retrieveUserInformationById } from "../security/usersbyid";
|
import { retrieveUserInformationById } from "../security/usersbyid";
|
||||||
|
import { retrieveUserInformation } from "../security/users";
|
||||||
import { number } from "yup";
|
import { number } from "yup";
|
||||||
// import UserPostImage from "../components/UserPostImage";
|
// import UserPostImage from "../components/UserPostImage";
|
||||||
|
|
||||||
@@ -38,12 +39,12 @@ interface Post {
|
|||||||
postImage: Blob;
|
postImage: Blob;
|
||||||
content: string;
|
content: string;
|
||||||
tags: string;
|
tags: string;
|
||||||
id: number;
|
id: string;
|
||||||
userId: number;
|
userId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
type User = {
|
type User = {
|
||||||
id: number;
|
id: string;
|
||||||
firstName: string;
|
firstName: string;
|
||||||
lastName: string;
|
lastName: string;
|
||||||
};
|
};
|
||||||
@@ -54,7 +55,9 @@ export default function CommunityPage() {
|
|||||||
const [selectedPost, setSelectedPost] = useState<Post | null>(null);
|
const [selectedPost, setSelectedPost] = useState<Post | null>(null);
|
||||||
const [communityList, setCommunityList] = useState<Post[]>([]);
|
const [communityList, setCommunityList] = useState<Post[]>([]);
|
||||||
const [search, setSearch] = useState(""); // Search Function
|
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");
|
let accessToken = localStorage.getItem("accessToken");
|
||||||
if (!accessToken) {
|
if (!accessToken) {
|
||||||
@@ -84,7 +87,7 @@ export default function CommunityPage() {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchUserInformation = async (userId: number) => {
|
const fetchUserInformation = async (userId: string) => {
|
||||||
try {
|
try {
|
||||||
const user = await retrieveUserInformationById(userId);
|
const user = await retrieveUserInformationById(userId);
|
||||||
setUserInformation((prevMap) => ({
|
setUserInformation((prevMap) => ({
|
||||||
@@ -103,6 +106,19 @@ export default function CommunityPage() {
|
|||||||
});
|
});
|
||||||
}, [communityList]);
|
}, [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> } }) => {
|
const onSearchChange = (e: { target: { value: SetStateAction<string> } }) => {
|
||||||
setSearch(e.target.value);
|
setSearch(e.target.value);
|
||||||
};
|
};
|
||||||
@@ -149,7 +165,7 @@ export default function CommunityPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handlePostClick = (id: number) => {
|
const handlePostClick = (id: string) => {
|
||||||
navigate(`post/${id}`);
|
navigate(`post/${id}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -31,12 +31,12 @@ interface Post {
|
|||||||
postImage: Blob;
|
postImage: Blob;
|
||||||
content: string;
|
content: string;
|
||||||
tags: string;
|
tags: string;
|
||||||
id: number;
|
id: string;
|
||||||
userId: number;
|
userId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
type User = {
|
type User = {
|
||||||
id: number;
|
id: string;
|
||||||
firstName: string;
|
firstName: string;
|
||||||
lastName: string;
|
lastName: string;
|
||||||
};
|
};
|
||||||
@@ -47,7 +47,7 @@ const PostPage: React.FC = () => {
|
|||||||
const [post, setPost] = useState<Post | null>(null);
|
const [post, setPost] = useState<Post | null>(null);
|
||||||
const { isOpen, onOpen, onOpenChange } = useDisclosure();
|
const { isOpen, onOpen, onOpenChange } = useDisclosure();
|
||||||
const [selectedPost, setSelectedPost] = useState<Post | null>(null);
|
const [selectedPost, setSelectedPost] = useState<Post | null>(null);
|
||||||
const [userInformation, setUserInformation] = useState<Record<number, User>>({});
|
const [userInformation, setUserInformation] = useState<Record<string, User>>({});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (id) {
|
if (id) {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { AxiosError } from "axios";
|
|||||||
import config from "../config";
|
import config from "../config";
|
||||||
import instance from "./http";
|
import instance from "./http";
|
||||||
|
|
||||||
export async function retrieveUserInformationById(userId: number) {
|
export async function retrieveUserInformationById(userId: string) {
|
||||||
if (!localStorage.getItem("accessToken")) {
|
if (!localStorage.getItem("accessToken")) {
|
||||||
throw "No access token";
|
throw "No access token";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
},
|
},
|
||||||
title: {
|
title: {
|
||||||
type: DataTypes.STRING(100),
|
type: DataTypes.STRING(100),
|
||||||
allowNull: false
|
allowNull: false,
|
||||||
},
|
},
|
||||||
postImage: {
|
postImage: {
|
||||||
type: DataTypes.BLOB("long"),
|
type: DataTypes.BLOB("long"),
|
||||||
@@ -16,14 +16,15 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
},
|
},
|
||||||
content: {
|
content: {
|
||||||
type: DataTypes.TEXT,
|
type: DataTypes.TEXT,
|
||||||
allowNull: false
|
allowNull: false,
|
||||||
},
|
},
|
||||||
userId: {
|
userId: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
tableName: 'posts'
|
tableName: 'posts',
|
||||||
|
timestamps: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
return Post;
|
return Post;
|
||||||
|
|||||||
Reference in New Issue
Block a user