-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListBoardComponent.jsx
162 lines (146 loc) · 5.56 KB
/
ListBoardComponent.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import React, { Component } from 'react';
import BoardService from '../service/BoardService';
class ListBoardComponent extends Component {
constructor(props) {
super(props)
this.state = {
p_num: 1,
paging: {},
boards: []
}
this.createBoard = this.createBoard.bind(this);
}
componentDidMount() {
BoardService.getBoards(this.state.p_num).then((res) => {
this.setState({
p_num: res.data.pagingData.currentPageNum,
paging: res.data.pagingData,
boards: res.data.list});
});
}
createBoard() {
this.props.history.push('/create-board/_create');
}
readBoard(no) {
this.props.history.push(`/read-board/${no}`);
}
listBoard(p_num) {
console.log("pageNum: "+p_num);
BoardService.getBoards(p_num).then((res) => {
console.log(res.data);
this.setState({
p_num: res.data.pagingData.currentPageNum,
paging: res.data.pagingData,
boards: res.data.list
});
});
}
viewPaging() {
const pageNums = [];
for (let i =this.state.paging.pageNumStart; i <= this.state.paging.pageNumEnd; i++ ) {
pageNums.push(i);
}
return (pageNums.map((page) =>
<li className='page-item' key={page.toString()} >
<a className='page-link' onClick={() => this.listBoard(page)}>{page}</a>
</li>));
}
isPagingPrev() {
if (this.state.paging.prev) {
return (
<li className='page-item'>
<a className='page-link' onClick={() => this.listBoard( (this.state.paging.currentPageNum - 1))} tabIndex="-1">Previous</a>
</li>
);
}
}
isPagingNext() {
if(this.state.paging.next) {
return (
<li className='page-item'>
<a className='page-link' onClick={() => this.listBoard( (this.state.paging.currentPageNum + 1))} tableIndex="-1">Next</a>
</li>
);
}
}
isMoveToFirstPage() {
if(this.state.p_num != 1) {
return (
<li className='page-item'>
<a className='page-link' onClick={() => this.listBoard(1)} tableIndex="-1">첫 번째 페이지로</a>
</li>
);
}
}
isMoveToLastPage() {
if(this.state.p_num != this.state.paging.pageNumCountTotal) {
return(
<li className='page-item'>
<a className='page-link' onClick={() => this.listBoard( (this.state.paging.pageNumCountTotal))} tableIndex="-1">마지막 페이지로</a>
</li>
);
}
}
render() {
return (
<div>
<h2 className='text-center'>후기 게시판</h2>
<div className='row'>
<button className='btn btn-primary' onClick={this.createBoard}>글 작성하기</button>
</div>
<div className='row'>
<table className='table table-striped table-bordered'>
<thead>
<tr>
<th>글 번호</th>
<th>타이틀</th>
<th>작성자</th>
<th>갱신일</th>
<th>좋아요 수</th>
<th>조회수</th>
</tr>
</thead>
<tbody>
{
this.state.boards.map(
board =>
<tr key = {board.no}>
<td> {board.no} </td>
<td> <a onClick = {() => this.readBoard(board.no)}>{board.title} </a></td>
<td> {board.memberNo} </td>
<td> {board.createdTime} </td>
<td> {board.updatedTime} </td>
<td> {board.likes} </td>
<td> {board.counts} </td>
</tr>
)
}
</tbody>
</table>
</div>
<div className='row'>
<nav aria-label="Page navigation example">
<ul className='pagination justify-content-center'>
{
this.isMoveToFirstPage()
}
{
this.isPagingPrev()
}
{
this.viewPaging()
}
{
this.isPagingNext()
}
{
this.isMoveToLastPage()
}
</ul>
</nav>
</div>
</div>
);
}
}
export default ListBoardComponent;