Skip to content

Commit 0ae9f48

Browse files
authored
Merge pull request #5 from Science-assignment-reps-for-student/sema
Board style 작업 완료 및 에러 수정
2 parents 32f846c + e62ff9c commit 0ae9f48

35 files changed

+986
-16
lines changed

src/App.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React, { useState, useCallback, useEffect, useRef } from 'react'
1+
import React, { useState, useCallback, useEffect } from 'react'
22
import { Route, Switch, withRouter, useHistory } from 'react-router-dom';
3-
import { PeerEvaluation, Task, TaskGuide, AdminLogin, Homework, AdminMain, Main, QnA, AdminChatting, ChattingList } from './components';
3+
import { PeerEvaluation, Task, TaskGuide, AdminLogin, Homework, AdminMain, Main, QnA, AdminChatting, ChattingList, Board, BoardDetail, BoardInput } from './components';
44
import { AuthConsumer, AuthProvider } from './context/Auth';
55
import { TaskProvider, TaskConsumer } from './context/AppContext';
66
import { AccessTokenProvider, AccessTokenConsumer } from './context/AccessTokenContext';
@@ -57,7 +57,6 @@ const App = () => {
5757
const setSocket = () => {
5858
const socket = new SockJS(socketURL);
5959
const stomp = Stomp.over(socket);
60-
// getNotificationPermission();
6160
stompChange(stomp);
6261
socketChange(socket);
6362
stomp.connect(
@@ -149,6 +148,30 @@ const App = () => {
149148
/>
150149
}
151150
/>
151+
<Route
152+
path="/board/:number"
153+
render={()=> <BoardDetail
154+
state={taskState}
155+
getUserInfo={getUserInfo}
156+
isLogin={isLogin}
157+
/>}
158+
/>
159+
<Route
160+
exact
161+
path="/board"
162+
render={()=> <Board
163+
state={taskState}
164+
getUserInfo={getUserInfo}
165+
isLogin={isLogin}
166+
/>}
167+
/>
168+
<Route path="/write" render={()=>
169+
<BoardInput
170+
state={taskState}
171+
getUserInfo={getUserInfo}
172+
isLogin={isLogin}
173+
/>}
174+
/>
152175
<AccessTokenProvider>
153176
<AccessTokenConsumer>
154177
{

src/components/Admin_Main/Main.js

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Header, BackgroundWhite } from '../public';
33
import * as S from './style/MainStyle';
44
import { MainContent, MainNav } from './component';
55
import { personalHomeworkURL, teamHomeworkURL, getUserInfoURL, experimentHomeworkURL, allFileDownloadURL, getFileCodeURL, excelFileDownloadURL } from '../resource/serverURL.js';
6-
import { getUserInfo, getSubscribe, errorTypeCheck } from '../resource/publicFunction';
6+
import { getUserInfo, getSubscribe, errorTypeCheck, getIsExpiration, refreshAccessToken } from '../resource/publicFunction';
77
import { withRouter } from 'react-router-dom'
88
import axios from 'axios';
99

@@ -90,8 +90,12 @@ const AdminMain = ({ state, actions, history, stomp }) => {
9090
// not admin
9191
history.push('/');
9292
})
93-
.catch(()=> {
94-
history.push('/admin/Login');
93+
.catch((err)=> {
94+
if(!getIsExpiration(err)){
95+
history.push('/admin/Login');
96+
} else {
97+
refreshAccessToken(refreshToken,actions);
98+
}
9599
})
96100
},[]);
97101

@@ -126,14 +130,16 @@ const AdminMain = ({ state, actions, history, stomp }) => {
126130

127131
const fileErrorCheck = (errResponse) => {
128132
try{
129-
const statusCode = errResponse.response.status
133+
const statusCode = errResponse.response.status;
130134
if(statusCode === 404){
131135
alert("파일이 없습니다");
136+
} else if(statusCode === 412) {
137+
alert("파일이 생성되지 않았습니다.");
132138
} else {
133139
errorTypeCheck(errResponse,refreshToken,actions);
134140
}
135141
} catch{
136-
alert("네트워크를 확인해 주세요.")
142+
alert("네트워크를 확인해 주세요.");
137143
}
138144
}
139145

@@ -272,15 +278,32 @@ const AdminMain = ({ state, actions, history, stomp }) => {
272278
}
273279
};
274280

281+
const excelFileUpdate = (contentId) => new Promise((resolve,reject) => {
282+
axios.put(`${excelFileDownloadURL}/${contentId}`,{},header)
283+
.then(()=> {
284+
resolve();
285+
})
286+
.catch((err)=> {
287+
reject(err);
288+
})
289+
})
290+
275291
const getExcelFile = (contentId) => {
276292
const fileCodePromise = getFileCodePromise(contentId);
277293
fileCodePromise
278294
.then((e)=> {
279-
const { file_excel_name } = e.data;
280-
axios.get(`${excelFileDownloadURL}/${contentId}`,fileHeader
281-
).then((e)=> {
282-
const excelFile = e.data;
283-
downloadFile(file_excel_name,excelFile);
295+
const excelFileUpdatePromise = excelFileUpdate(contentId);
296+
excelFileUpdatePromise
297+
.then(()=> {
298+
const { file_excel_name } = e.data;
299+
axios.get(`${excelFileDownloadURL}/${contentId}`,fileHeader)
300+
.then((e)=> {
301+
const excelFile = e.data;
302+
downloadFile(file_excel_name,excelFile);
303+
})
304+
.catch((err)=> {
305+
fileErrorCheck(err);
306+
})
284307
})
285308
.catch((err)=> {
286309
fileErrorCheck(err);

src/components/Board/Board.js

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
import React, { useState, useEffect } from 'react';
2+
import { Header } from '../Header';
3+
import * as S from './style/boardStyle';
4+
import { BoardComponent } from './components';
5+
import { withRouter } from 'react-router-dom';
6+
7+
const Board = ({ state, getUserInfo, history }) => {
8+
const { limServer, wooServer, accessToken, refreshToken } = state;
9+
const [search, searchChange] = useState();
10+
const [postList, postListChange] = useState([
11+
{
12+
title: "이성진 바보",
13+
writer: "오준상",
14+
createDate: "2020-03-16",
15+
comment: 3,
16+
viewCount: 3,
17+
isNew: true,
18+
},
19+
{
20+
title: "이성진 바보",
21+
writer: "오준상",
22+
createDate: "2020-03-16",
23+
comment: 3,
24+
viewCount: 3,
25+
isNew: true,
26+
},
27+
{
28+
title: "이성진 바보",
29+
writer: "오준상",
30+
createDate: "2020-03-16",
31+
comment: 3,
32+
viewCount: 3,
33+
isNew: true,
34+
},
35+
{
36+
title: "이성진 바보",
37+
writer: "오준상",
38+
createDate: "2020-03-16",
39+
comment: 3,
40+
viewCount: 3,
41+
isNew: true,
42+
},
43+
{
44+
title: "이성진 바보",
45+
writer: "오준상",
46+
createDate: "2020-03-16",
47+
comment: 3,
48+
viewCount: 3,
49+
isNew: true,
50+
},
51+
{
52+
title: "이성진 바보",
53+
writer: "오준상",
54+
createDate: "2020-03-16",
55+
comment: 3,
56+
viewCount: 3,
57+
isNew: true,
58+
},
59+
{
60+
title: "이성진 바보",
61+
writer: "오준상",
62+
createDate: "2020-03-16",
63+
comment: 3,
64+
viewCount: 3,
65+
isNew: true,
66+
},{
67+
title: "이성진 바보",
68+
writer: "오준상",
69+
createDate: "2020-03-16",
70+
comment: 3,
71+
viewCount: 3,
72+
isNew: true,
73+
}
74+
,{
75+
title: "이성진 바보",
76+
writer: "오준상",
77+
createDate: "2020-03-16",
78+
comment: 3,
79+
viewCount: 3,
80+
isNew: true,
81+
}
82+
,{
83+
title: "이성진 바보",
84+
writer: "오준상",
85+
createDate: "2020-03-16",
86+
comment: 3,
87+
viewCount: 3,
88+
isNew: true,
89+
}
90+
,{
91+
title: "이성진 바보",
92+
writer: "오준상",
93+
createDate: "2020-03-16",
94+
comment: 3,
95+
viewCount: 3,
96+
isNew: true,
97+
}
98+
,{
99+
title: "이성진 바보",
100+
writer: "오준상",
101+
createDate: "2020-03-16",
102+
comment: 3,
103+
viewCount: 3,
104+
isNew: true,
105+
}
106+
107+
])
108+
const [page, pageChange] = useState(0);
109+
const createList = (postList) => {
110+
let buffer = [];
111+
const pageMaxComponent = 8;
112+
for(let i = getComponentCount();i < getComponentCount() + pageMaxComponent;i++){
113+
if(!postList[i]){break;}
114+
const { title, writer, createDate, viewCount, comment, isNew } = postList[i];
115+
buffer.push(
116+
<BoardComponent
117+
title={title}
118+
writer={writer}
119+
createDate={createDate}
120+
viewCount={viewCount}
121+
comment={comment}
122+
isNew = {isNew}
123+
key={title+viewCount}
124+
/>
125+
)
126+
}
127+
return buffer;
128+
}
129+
130+
const getBottomPageList = () => {
131+
const list = [];
132+
for (let i = 0; i < getPageMax(page); i++) {
133+
list.push(<li
134+
key={i}
135+
className={page === i ? "clicked" : ""}
136+
onClick={() => pageChange(i)}
137+
>
138+
<span>{i+1}</span>
139+
</li>
140+
)
141+
}
142+
return list;
143+
}
144+
145+
const setPageNext = (page) => {
146+
if(page + 1 >= getPageMax()) { return; }
147+
pageChange(page + 1);
148+
}
149+
150+
const setPageCurrent = (page) => {
151+
if(page - 1 === -1) { return; }
152+
pageChange(page - 1);
153+
}
154+
155+
const getPageMax = () => {
156+
const postCount = postList.length;
157+
return Math.ceil(postCount / 8);
158+
}
159+
160+
const getComponentCount = () => {
161+
return page * 8;
162+
}
163+
164+
useEffect(()=> {
165+
const userInfoPro = getUserInfo(limServer,accessToken);
166+
if(!userInfoPro){ history.push('/'); }
167+
},[])
168+
169+
return (
170+
<>
171+
<Header/>
172+
<S.BoardGuide>
173+
<div>
174+
<div className="task-guide-top">
175+
<h1>n반 게시판</h1>
176+
<div>
177+
<div>
178+
<input
179+
type="text"
180+
onChange={(e) => {
181+
searchChange(e);
182+
}}
183+
value={search}
184+
/>
185+
</div>
186+
<div><button>검색</button></div>
187+
<div className="button" onClick={()=> history.push('/write')}>글쓰기</div>
188+
</div>
189+
</div>
190+
<div className="task-guide-table">
191+
<table>
192+
<tbody>
193+
<tr>
194+
<th></th>
195+
<th className="writer">작성이</th>
196+
<th className="title">제목</th>
197+
<th className="creationDate">작성일</th>
198+
<th className="viewCount">조회수</th>
199+
<th className="comment">댓글</th>
200+
</tr>
201+
{createList(postList)}
202+
</tbody>
203+
</table>
204+
</div>
205+
<div className="task-guide-page">
206+
<ul>
207+
<li className="clicked" onClick={() => setPageCurrent(page)}><i></i></li>
208+
{getBottomPageList()}
209+
<li className="clicked" onClick={() => setPageNext(page)}><i></i></li>
210+
</ul>
211+
</div>
212+
</div>
213+
</S.BoardGuide>
214+
</>
215+
)
216+
}
217+
218+
export default withRouter(Board);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react';
2+
import New from '../img/New.png'
3+
4+
const BoardComponent = ({ title, writer, createDate, viewCount, comment, isNew }) => {
5+
return (
6+
<tr>
7+
{isNew ? <td><div><i/></div></td> : <td/>}
8+
<td>{writer}</td>
9+
<td>{title}</td>
10+
<td>{createDate}</td>
11+
<td>{viewCount}</td>
12+
<td>{comment}</td>
13+
</tr>
14+
)
15+
}
16+
17+
export default BoardComponent;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as BoardComponent } from './BoardComponent';
2.63 MB
Loading
17.5 KB
Loading

src/components/Board/img/New.png

536 Bytes
Loading

src/components/Board/img/O.png

422 Bytes
Loading
1.79 KB
Loading

0 commit comments

Comments
 (0)