You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1008 B
52 lines
1008 B
import React from 'react'; |
|
|
|
const SERVER_URL = 'http://localhost:3000/' |
|
|
|
export default class Site extends React.Component { |
|
|
|
state = { |
|
classes: [], |
|
psboard: [], |
|
componentMounted: false |
|
} |
|
|
|
callAPI = (targetUrl) => { |
|
let url = SERVER_URL + 'api/data/'+ targetUrl |
|
let data = "" |
|
console.log(url); |
|
|
|
fetch(url) |
|
.then(response => response.json()) |
|
.then(body => |
|
this.setState({ |
|
[targetUrl]: body |
|
})); |
|
} |
|
|
|
componentDidMount() { |
|
this.callAPI('classes') |
|
this.callAPI('psboard') |
|
|
|
} |
|
|
|
render() { |
|
console.log(this.state) |
|
return ( |
|
<div className="mainContainer"> |
|
<div className="left"> |
|
<div className="heading">Upcoming Classes</div> |
|
|
|
{this.state.psboard.map((item, i) => |
|
<div className='course-list'> |
|
<div className='subject'>{item.subject}</div> |
|
<div className='date'>{item.date}</div> |
|
</div>)} |
|
|
|
</div> |
|
<div className="right"> |
|
<div className="heading">Posts</div> |
|
</div> |
|
</div> |
|
); |
|
} |
|
}
|
|
|