Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
#30 react IBoard & NoticeBoard
Browse files Browse the repository at this point in the history
  • Loading branch information
ByungJin-Lee committed Aug 27, 2022
1 parent 4f8a9f5 commit 607d54f
Show file tree
Hide file tree
Showing 10 changed files with 415 additions and 48 deletions.
53 changes: 53 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@
"devDependencies": {
"@babel/core": "^7.18.13",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-transform-runtime": "^7.18.10",
"@babel/preset-env": "^7.18.10",
"@babel/preset-react": "^7.18.6",
"@babel/runtime": "^7.18.9",
"@types/crypto-js": "^4.1.1",
"@types/express": "^4.17.13",
"@types/express-session": "^1.17.5",
Expand Down
210 changes: 210 additions & 0 deletions public/admin/assets/components/NoticeBoard.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions public/admin/assets/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@ body {

table {
border: 2px solid #eee;
border-collapse: collapse;
}

td, th {
padding: 5px;

border: 2px solid #eee;
}
34 changes: 2 additions & 32 deletions public/admin/noticeboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,7 @@
<link rel="stylesheet" href="./assets/css/index.css">
</head>
<body>
<div id="board"></div>
<script type="module">
import setupBoard from './assets/js/board.js';

setupBoard({
selectorQuery: '#board',
getUrl: (page, per)=>{
return `/api/v1/notice/get/list?page=${page}&per=${per}`
},
getRecord: (notice) => {
return `
<td>${notice.identifier}</td>
<td>${notice.header}</td>
<td>${notice.title}</td>
<td>${notice.writer}</td>
<td>${notice.numOfView}</td>
<td>${notice.postedAt}</td>
`
},
onRecordClick: async (divView, tr) => {
const fTd = tr.querySelector('td');

const id = fTd.textContent.trim();

const res = await fetch(`/api/v1/notice/get/${id}`);

if(res.status != 200) throw Error('error');

divView.setText((await res.json()).content)
}
});
</script>
<div id="noticeTable"></div>
<script src="./assets/components/NoticeBoard.js"></script>
</body>
</html>
84 changes: 84 additions & 0 deletions src/Components/IBoard.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@

import React, { Component, Fragment } from "react";

export default class IBoard extends Component {

constructor() {
super();

this.state = {
currentPage: 1,
currentPerPage: 15,
totalLength: 0,
items: [],
};
}

async componentDidMount() {
await this.fetchBoardData();
}

/**
* Calculator page limit using state information.
*/
getPageLimit() {
return Math.ceil(this.state.totalLength / this.state.currentPerPage);
}

/**
* Must override in subclass.
* return table head
*/
renderHead() {
return (
<tr>
<th>Board Template</th>
</tr>
)
}

/**
* Must override in subclass.
* @param {object} item
*/
renderItem(item) {
return (
<tr>
<td>{item}</td>
</tr>
)
}

/**
* Must override in subclass.
*/
async fetchBoardData() {
console.log('fetch');
}

onClickRefresh() {
console.log('hello');
}

render() {
return (
<Fragment>
<h2>{this.state.boardName}</h2>
<div>
<button onClick={()=> this.onClickRefresh()}>Refresh</button>
</div>
<table>
<thead>
{ this.renderHead() }
</thead>
<tbody>
{ this.state.items.map(item=>this.renderItem(item)) }
</tbody>
</table>
<div>

</div>
</Fragment>
)
}
}
45 changes: 45 additions & 0 deletions src/Components/NoticeBoard.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

import IBoard from "./IBoard";

export default class NoticeBoard extends IBoard {

renderHead() {
return (
<tr>
<th>Notice Id</th>
<th>Notice Header</th>
<th>Notice Title</th>
<th>Notice Writer</th>
<th>Notice View</th>
</tr>)
}

renderItem(item) {
return <tr key={item.identifier}>
<td>{item.identifier}</td>
<td>{item.header}</td>
<td>{item.title}</td>
<td>{item.writer}</td>
<td>{item.numOfView}</td>
</tr>
}

async fetchBoardData() {
const res = await fetch(`/api/v1/notice/get/list?page=${this.state.currentPage}&per=${this.state.currentPerPage}`);

if(res.status != 200) throw Error('error!');

const data = await res.json();

this.setState({
currentPage : data.currentPage,
currentPerPage : data.countPerPage,
totalLength: data.totalCount,
items: data.values
});
}

onClickRefresh() {

}
}
10 changes: 0 additions & 10 deletions src/Components/WordRelay.jsx

This file was deleted.

8 changes: 4 additions & 4 deletions src/Components/client.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const React = require('react');
const ReactDom = require('react-dom');
const { default: WordRelay } = require('./WordRelay');
import React from 'react';
import ReactDOM from 'react-dom';
import NoticeBoard from './NoticeBoard';

ReactDom.render(<WordRelay/>, document.querySelector('#root'));
ReactDOM.render(<NoticeBoard/>, document.querySelector('#noticeTable'));
10 changes: 8 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ module.exports = {
test: /\.jsx?/,
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react'],
plugins: ['@babel/plugin-proposal-class-properties']
presets: [
'@babel/preset-env',
['@babel/preset-react', { 'runtime': 'automatic' }]
],
plugins: [
'@babel/plugin-proposal-class-properties',
// '@babel/plugin-transform-runtime'
]
}
}]
},
Expand Down

0 comments on commit 607d54f

Please sign in to comment.