board.tsx 2.7 KB
Newer Older
Lee Soobeom's avatar
Lee Soobeom committed
1
2
import React, { useState, MouseEvent } from "react";
import { Link } from "react-router-dom";
3
4
import { PostType } from "../types";
import Post from "../post/post";
Lee Soobeom's avatar
Lee Soobeom committed
5

6
interface Posts {
Kim, MinGyu's avatar
Kim, MinGyu committed
7
  posts: PostType[];
8
9
}

Lee Soobeom's avatar
Lee Soobeom committed
10
export const fakes = [
Kim, MinGyu's avatar
Kim, MinGyu committed
11
  {
Lee Soobeom's avatar
.    
Lee Soobeom committed
12
    userId: "lsb",
Kim, MinGyu's avatar
Kim, MinGyu committed
13
14
15
16
17
18
19
    title: "여행가고싶다...",
    date: "2022-06-30",
    counts: 0,
    theme: "surfing",
    city: "seoul",
  },
  {
Lee Soobeom's avatar
.    
Lee Soobeom committed
20
    userId: "lsb",
Kim, MinGyu's avatar
Kim, MinGyu committed
21
22
23
24
25
26
27
    title: "바다!바다!바다!",
    date: "2022-08-01",
    counts: 0,
    theme: "surfing",
    city: "seoul",
  },
  {
Lee Soobeom's avatar
.    
Lee Soobeom committed
28
    userId: "lsb",
Kim, MinGyu's avatar
Kim, MinGyu committed
29
30
31
32
33
34
35
    title: "Jeju-island",
    date: "2022-9-10",
    counts: 0,
    theme: "surfing",
    city: "seoul",
  },
  {
Lee Soobeom's avatar
.    
Lee Soobeom committed
36
    userId: "lsb",
Kim, MinGyu's avatar
Kim, MinGyu committed
37
38
39
40
41
42
43
    title: "마! 부싼 가봤나!",
    date: "2022-9-22",
    counts: 0,
    theme: "surfing",
    city: "seoul",
  },
  {
Lee Soobeom's avatar
.    
Lee Soobeom committed
44
    userId: "lsb",
Kim, MinGyu's avatar
Kim, MinGyu committed
45
46
47
    title: "Daegu",
    date: "2022-10-1",
    counts: 0,
48
49
    theme: "ski",
    city: "Daegu",
Kim, MinGyu's avatar
Kim, MinGyu committed
50
51
  },
  {
Lee Soobeom's avatar
.    
Lee Soobeom committed
52
    userId: "lsb",
Kim, MinGyu's avatar
Kim, MinGyu committed
53
54
55
    title: "강원도 감자는 맛있다.",
    date: "2022-12-12",
    counts: 0,
56
57
    theme: "camping",
    city: "강원도",
Kim, MinGyu's avatar
Kim, MinGyu committed
58
59
  },
  {
Lee Soobeom's avatar
.    
Lee Soobeom committed
60
    userId: "lsb",
Kim, MinGyu's avatar
Kim, MinGyu committed
61
62
63
    title: "부산남자의 서울여행",
    date: "2022-12-25",
    counts: 0,
64
    theme: "activity",
Kim, MinGyu's avatar
Kim, MinGyu committed
65
66
    city: "seoul",
  },
Lee Soobeom's avatar
Lee Soobeom committed
67
68
];

Lee Soobeom's avatar
Lee Soobeom committed
69
export default function BoardPage() {
Kim, MinGyu's avatar
Kim, MinGyu committed
70
  const [posts, setPosts] = useState<PostType[]>(fakes);
Lee Soobeom's avatar
Lee Soobeom committed
71

Kim, MinGyu's avatar
Kim, MinGyu committed
72
73
74
75
  const titleHandleClick = (event: MouseEvent<HTMLButtonElement>) => {
    const postId = event.currentTarget.id;
    const newposts = [...posts];
    newposts.forEach((post) => {
Lee Soobeom's avatar
.    
Lee Soobeom committed
76
      if (post.userId === postId) {
Kim, MinGyu's avatar
Kim, MinGyu committed
77
78
79
80
81
82
        post.counts = post.counts + 1;
        return;
      }
    });
    setPosts(newposts);
  };
83

Kim, MinGyu's avatar
Kim, MinGyu committed
84
85
86
87
88
89
  return (
    <div className="flex flex-col items-center">
      <div className="flex flex-col items-center mt-6">
        <div>`Travel Report's Board`</div>
        <div>`여행지 후기를 남겨주세요!`</div>
      </div>
Lee Soobeom's avatar
Lee Soobeom committed
90

Kim, MinGyu's avatar
Kim, MinGyu committed
91
92
93
94
95
96
97
98
      <div className="flex flex-col w-10/12 mt-16">
        <div className="flex justify-end">
          <div className="border-2 mb-2">
            <Link to="/posting">
              <button>글쓰기+</button>
            </Link>
          </div>{" "}
          {/* Link */}
Lee Soobeom's avatar
Lee Soobeom committed
99
        </div>
Kim, MinGyu's avatar
Kim, MinGyu committed
100
101
102
103
104
105
106
107
        <div className="sm:overflow-y-scroll">
          <div className="flex flex-row divide-x-2 border-2 border-solid bg-gray-500 border-y-2 h-10 ">
            <div className="basis-full">Title</div>
            <div className="basis-3/12">Date</div>
            <div className="basis-2/12">Clicks</div>
          </div>
          <div>
            {posts.map((post) => (
Lee Soobeom's avatar
.    
Lee Soobeom committed
108
109
110
111
112
              <Post
                key={post.userId}
                post={post}
                handleClick={titleHandleClick}
              />
Kim, MinGyu's avatar
Kim, MinGyu committed
113
114
115
116
117
118
119
            ))}
          </div>
        </div>
      </div>
    </div>
  );
}