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

board

parent a6e57583
...@@ -17,6 +17,7 @@ export default function BoardPage() { ...@@ -17,6 +17,7 @@ export default function BoardPage() {
const [posts, setPosts] = useState<PostType[]>(); const [posts, setPosts] = useState<PostType[]>();
const location = useLocation() as Newpost; const location = useLocation() as Newpost;
const newPost = location.state; const newPost = location.state;
const deletePostId = location.state._id;
const navigate = useNavigate(); const navigate = useNavigate();
const { user } = useAuth(); const { user } = useAuth();
...@@ -34,29 +35,28 @@ export default function BoardPage() { ...@@ -34,29 +35,28 @@ export default function BoardPage() {
setNewPosts(newPost); setNewPosts(newPost);
}, []); }, []);
// posts
const getDataList = async () => { const getDataList = async () => {
const res = await postApi.getData(); const res = await postApi.getData();
setPosts(res); //posts = res setPosts(res); //posts = res
}; };
const titleHandleClick = async (event: MouseEvent<HTMLButtonElement>) => { const deletePost = async (postId: string) => {
if (!user.isLoggedIn) { const res = await postApi.deletePost(postId);
alert("로그인이 필요합니다."); return res;
navigate("/login", { replace: true }); };
} else {
const postId = event.currentTarget.id; const handleClick = async (event: MouseEvent<HTMLButtonElement>) => {
const newpost = posts?.find((element) => { const postId = event.currentTarget.id;
if (element._id === postId) { const newpost = posts?.find((element) => {
return 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);
} }
});
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() { ...@@ -94,7 +94,7 @@ export default function BoardPage() {
</div> </div>
<div> <div>
{posts?.map((post, i) => ( {posts?.map((post, i) => (
<Post key={i} post={post} handleClick={titleHandleClick} /> <Post key={i} post={post} handleClick={handleClick} />
))} ))}
</div> </div>
</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