Commit f21493ca authored by Lee Soobeom's avatar Lee Soobeom
Browse files

board

parent a6e57583
......@@ -17,6 +17,7 @@ export default function BoardPage() {
const [posts, setPosts] = useState<PostType[]>();
const location = useLocation() as Newpost;
const newPost = location.state;
const deletePostId = location.state._id;
const navigate = useNavigate();
const { user } = useAuth();
......@@ -34,29 +35,28 @@ export default function BoardPage() {
setNewPosts(newPost);
}, []);
// posts
const getDataList = async () => {
const res = await postApi.getData();
setPosts(res); //posts = res
};
const titleHandleClick = async (event: MouseEvent<HTMLButtonElement>) => {
if (!user.isLoggedIn) {
alert("로그인이 필요합니다.");
navigate("/login", { replace: true });
} else {
const postId = event.currentTarget.id;
const newpost = posts?.find((element) => {
if (element._id === postId) {
return element;
}
});
if (!(newpost?._id === undefined)) {
const post = newpost;
const res = await postApi.addCounts(post._id, post.counts);
// console.log(res);
setPosts(res);
const deletePost = async (postId: string) => {
const res = await postApi.deletePost(postId);
return res;
};
const handleClick = async (event: MouseEvent<HTMLButtonElement>) => {
const postId = event.currentTarget.id;
const newpost = posts?.find((element) => {
if (element._id === postId) {
return element;
}
});
if (!(newpost?._id === undefined)) {
const post = newpost;
const res = await postApi.addCounts(post._id, post.counts);
// console.log(res);
// setPosts(res);
}
};
......@@ -94,7 +94,7 @@ export default function BoardPage() {
</div>
<div>
{posts?.map((post, i) => (
<Post key={i} post={post} handleClick={titleHandleClick} />
<Post key={i} post={post} handleClick={handleClick} />
))}
</div>
</div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment