intopost.tsx 2.16 KB
Newer Older
Lee Soobeom's avatar
Lee Soobeom committed
1
import React, { MouseEvent } from "react";
Lee Soobeom's avatar
Lee Soobeom committed
2
import { useLocation, useNavigate, Link, Outlet } from "react-router-dom";
Lee Soobeom's avatar
Lee Soobeom committed
3
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>
          <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="/edit" state={post}>
                <button>update</button>
              </Link>
            </div>
Lee Soobeom's avatar
Lee Soobeom committed
38
          </div>
Lee Soobeom's avatar
Lee Soobeom committed
39
40
41
42
43
44
45
          <div className="flex flex-row">
            <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
46
          </div>
Lee Soobeom's avatar
Lee Soobeom committed
47
48
49
50
51
52
53
54
55
56
57
58
59
          <div className="flex flex-row">
            <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
60
          </div>
Lee Soobeom's avatar
Lee Soobeom committed
61
        </div>
Lee Soobeom's avatar
Lee Soobeom committed
62
        <div className="border-2 border-black rounded h-full">{post.text}</div>
Lee Soobeom's avatar
Lee Soobeom committed
63
      </div>
Lee Soobeom's avatar
Lee Soobeom committed
64
      {/* <Outlet /> */}
Lee Soobeom's avatar
Lee Soobeom committed
65
66
67
    </div>
  );
}