intopost.tsx 2.71 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
        <div>
Lee Soobeom's avatar
Lee Soobeom committed
27
28
29
30
31
32
33
          <div className="flex flex-row h-8 gap-x-1 place-content-end">
            <div className="w-8">
              <button
                id={post._id}
                onClick={handleDeleteClick}
                className="border-2 border-sky-300 rounded-full h-8 w-8 text-xs text-center transition ease-in-out delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-red-300 duration-300"
              >
Lee Soobeom's avatar
Lee Soobeom committed
34
                삭제
Lee Soobeom's avatar
Lee Soobeom committed
35
36
              </button>
            </div>
Lee Soobeom's avatar
Lee Soobeom committed
37
            <div className="w-8">
Lee Soobeom's avatar
Lee Soobeom committed
38
              <Link to="/edit" state={post}>
Lee Soobeom's avatar
Lee Soobeom committed
39
40
41
                <button className="border-2 border-sky-300 rounded-full h-8 w-8 text-xs transition ease-in-out delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-sky-300 duration-300">
                  수정
                </button>
Lee Soobeom's avatar
Lee Soobeom committed
42
43
              </Link>
            </div>
Lee Soobeom's avatar
Lee Soobeom committed
44
          </div>
Lee Soobeom's avatar
Lee Soobeom committed
45
46
          <div className="flex flex-row h-8 gap-x-1 place-content-between">
            <div className="flex basis-3/6 border-2 border-sky-300 rounded">
Lee Soobeom's avatar
Lee Soobeom committed
47
48
              제목: {post.title}
            </div>
Lee Soobeom's avatar
Lee Soobeom committed
49
            <div className="flex basis-2/6 border-2 border-sky-300 rounded">
Lee Soobeom's avatar
css    
Lee Soobeom committed
50
              작성자: {post.user}
Lee Soobeom's avatar
Lee Soobeom committed
51
            </div>
Lee Soobeom's avatar
Lee Soobeom committed
52
53
54
            <div className="flex basis-2/6 border-2 border-sky-300 rounded">
              작성일: {post.date}
            </div>
Lee Soobeom's avatar
Lee Soobeom committed
55
          </div>
Lee Soobeom's avatar
Lee Soobeom committed
56
57
          <div className="flex flex-row h-8 gap-x-1 place-content-start">
            <div className="flex basis-1/6 border-2 border-sky-300 rounded">
Lee Soobeom's avatar
Lee Soobeom committed
58
59
              도시: {post.city}
            </div>
Lee Soobeom's avatar
Lee Soobeom committed
60
            <div className="flex basis-1/6 border-2 border-sky-300 rounded">
Lee Soobeom's avatar
Lee Soobeom committed
61
62
              테마: {post.theme}
            </div>
Lee Soobeom's avatar
Lee Soobeom committed
63
            <div className="flex basis-1/6 border-2 border-sky-300 rounded">
Lee Soobeom's avatar
Lee Soobeom committed
64
65
              조회수: {post.counts}
            </div>
Lee Soobeom's avatar
Lee Soobeom committed
66
          </div>
Lee Soobeom's avatar
Lee Soobeom committed
67
        </div>
Lee Soobeom's avatar
Lee Soobeom committed
68
        <div className="border-2 border-sky-300 rounded h-48">files</div>
Lee Soobeom's avatar
css    
Lee Soobeom committed
69
        <div className="border-2 border-sky-300 rounded h-96">{post.text}</div>
Lee Soobeom's avatar
Lee Soobeom committed
70
71
72
73
      </div>
    </div>
  );
}