intopost.tsx 2.04 KB
Newer Older
Lee Soobeom's avatar
Lee Soobeom committed
1
2
3
import React, { MouseEvent } from "react";
import { useLocation, useNavigate, Link } from "react-router-dom";
import { postApi } from "../apis";
Yoon, Daeki's avatar
Yoon, Daeki committed
4
import { PostType } from "../types";
Lee Soobeom's avatar
Lee Soobeom committed
5

Lee Soobeom's avatar
Lee Soobeom committed
6
export interface PostState {
Yoon, Daeki's avatar
Yoon, Daeki committed
7
  state: PostType;
Lee Soobeom's avatar
Lee Soobeom committed
8
9
10
11
12
}

export function IntoPost() {
  const location = useLocation() as PostState;
  const post = location.state;
Lee Soobeom's avatar
Lee Soobeom committed
13
  const navigate = useNavigate();
Lee Soobeom's avatar
Lee Soobeom committed
14
15
  // console.log(post);

Lee Soobeom's avatar
Lee Soobeom committed
16
17
18
19
20
21
22
  const handleDeleteClick = async (event: MouseEvent<HTMLButtonElement>) => {
    const postId = event.currentTarget.id;
    const res = await postApi.deletePost(postId);
    navigate("/board", { replace: true });
    console.log("delete post", res);
  };

Lee Soobeom's avatar
Lee Soobeom committed
23
24
25
  return (
    <div>
      <div>
Lee Soobeom's avatar
Lee Soobeom committed
26
27
28
29
30
31
32
33
34
35
36
37
        <div className="flex flex-row basis-8">
          <div className="border-2 border-current rounded">
            <button id={post._id} onClick={handleDeleteClick}>
              delete
            </button>
          </div>
          <div className="border-2 border-current rounded">
            <Link to={`/post/${post._id}/edit`} state={post}>
              <button>update</button>
            </Link>
          </div>
        </div>
Lee Soobeom's avatar
Lee Soobeom committed
38
        <div className="flex flex-row">
Lee Soobeom's avatar
Lee Soobeom committed
39
40
41
42
43
44
          <div className="flex basis-3/4 border-2 border-black rounded">
            제목: {post.title}
          </div>
          <div className="flex basis-1/4 border-2 border-black rounded">
            작성자: nickname
          </div>
Lee Soobeom's avatar
Lee Soobeom committed
45
46
        </div>
        <div className="flex flex-row">
Lee Soobeom's avatar
Lee Soobeom committed
47
48
49
50
51
52
53
54
55
56
57
58
          <div className="flex basis-1/4 border-2 border-black rounded">
            도시: {post.city}
          </div>
          <div className="flex basis-1/4 border-2 border-black rounded">
            테마: {post.theme}
          </div>
          <div className="flex basis-1/4 border-2 border-black rounded">
            작성일: {post.date}
          </div>
          <div className="flex basis-1/4 border-2 border-black rounded">
            조회수: {post.counts}
          </div>
Lee Soobeom's avatar
Lee Soobeom committed
59
60
        </div>
      </div>
Lee Soobeom's avatar
Lee Soobeom committed
61
      <div className="border-2 border-black rounded h-96">{post.text}</div>
Lee Soobeom's avatar
Lee Soobeom committed
62
63
64
    </div>
  );
}