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,17 +35,17 @@ export default function BoardPage() { ...@@ -34,17 +35,17 @@ 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 handleClick = async (event: MouseEvent<HTMLButtonElement>) => {
const postId = event.currentTarget.id; const postId = event.currentTarget.id;
const newpost = posts?.find((element) => { const newpost = posts?.find((element) => {
if (element._id === postId) { if (element._id === postId) {
...@@ -55,8 +56,7 @@ export default function BoardPage() { ...@@ -55,8 +56,7 @@ export default function BoardPage() {
const post = newpost; const post = newpost;
const res = await postApi.addCounts(post._id, post.counts); const res = await postApi.addCounts(post._id, post.counts);
// console.log(res); // console.log(res);
setPosts(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