Wrote the news rendering module

This commit is contained in:
2019-05-22 06:53:25 +10:00
parent 2298cb7e16
commit 12016a3fbf
9 changed files with 439 additions and 16 deletions
+43
View File
@@ -0,0 +1,43 @@
import React from 'react';
import ReactMarkdown from 'react-markdown';
class NewsPanel extends React.Component {
constructor(props) {
super(props);
this.state = {
data: {}
};
this.fetchNews();
}
render() {
return (
<div>
{Object.keys(this.state.data).map((key, index) => <div key={key}><ReactMarkdown source={this.state.data[key]} escapeHTML={false} /><hr /></div> )}
</div>
);
}
fetchNews() {
//build the XHR
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
this.setState({data: JSON.parse(xhr.responseText)});
}
}
}
xhr.open('POST', '/newsrequest', true);
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
xhr.send(JSON.stringify({
max: 3
}));
}
};
export default NewsPanel;