Created news index
This commit is contained in:
Generated
+9
-10
@@ -2689,6 +2689,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"firstline": {
|
||||||
|
"version": "2.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/firstline/-/firstline-2.0.2.tgz",
|
||||||
|
"integrity": "sha512-8KcmfI0jgSECnzdhucm0i7vrwef3BWwgjimW2YkRC5eSFwjb5DibVoA0YvgkYwwxuJi9c+7M7X3b3lX8o9B6wg=="
|
||||||
|
},
|
||||||
"flatiron": {
|
"flatiron": {
|
||||||
"version": "0.4.3",
|
"version": "0.4.3",
|
||||||
"resolved": "https://registry.npmjs.org/flatiron/-/flatiron-0.4.3.tgz",
|
"resolved": "https://registry.npmjs.org/flatiron/-/flatiron-0.4.3.tgz",
|
||||||
@@ -3024,8 +3029,7 @@
|
|||||||
},
|
},
|
||||||
"code-point-at": {
|
"code-point-at": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"bundled": true,
|
"bundled": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"concat-map": {
|
"concat-map": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
@@ -3033,8 +3037,7 @@
|
|||||||
},
|
},
|
||||||
"console-control-strings": {
|
"console-control-strings": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"bundled": true,
|
"bundled": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"core-util-is": {
|
"core-util-is": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
@@ -3137,8 +3140,7 @@
|
|||||||
},
|
},
|
||||||
"inherits": {
|
"inherits": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.3",
|
||||||
"bundled": true,
|
"bundled": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"ini": {
|
"ini": {
|
||||||
"version": "1.3.5",
|
"version": "1.3.5",
|
||||||
@@ -3148,7 +3150,6 @@
|
|||||||
"is-fullwidth-code-point": {
|
"is-fullwidth-code-point": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"number-is-nan": "^1.0.0"
|
"number-is-nan": "^1.0.0"
|
||||||
}
|
}
|
||||||
@@ -3260,8 +3261,7 @@
|
|||||||
},
|
},
|
||||||
"number-is-nan": {
|
"number-is-nan": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"bundled": true,
|
"bundled": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"object-assign": {
|
"object-assign": {
|
||||||
"version": "4.1.1",
|
"version": "4.1.1",
|
||||||
@@ -3376,7 +3376,6 @@
|
|||||||
"string-width": {
|
"string-width": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"code-point-at": "^1.0.0",
|
"code-point-at": "^1.0.0",
|
||||||
"is-fullwidth-code-point": "^1.0.0",
|
"is-fullwidth-code-point": "^1.0.0",
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
"cron": "^1.7.1",
|
"cron": "^1.7.1",
|
||||||
"dotenv": "^8.0.0",
|
"dotenv": "^8.0.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
|
"firstline": "^2.0.2",
|
||||||
"forever": "^1.0.0",
|
"forever": "^1.0.0",
|
||||||
"formidable": "^1.2.1",
|
"formidable": "^1.2.1",
|
||||||
"mysql": "^2.17.1",
|
"mysql": "^2.17.1",
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ Major
|
|||||||
* Implement admin panel (write posts without having to commit).
|
* Implement admin panel (write posts without having to commit).
|
||||||
* Implement bug tracker.
|
* Implement bug tracker.
|
||||||
* Ads / monetisation research.
|
* Ads / monetisation research.
|
||||||
|
* github pages hosting?
|
||||||
|
|
||||||
Minor
|
Minor
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ app.use(bodyParser.json());
|
|||||||
let news = require('./news.js');
|
let news = require('./news.js');
|
||||||
app.get('/newsrequest', news.newsRequest());
|
app.get('/newsrequest', news.newsRequest());
|
||||||
app.post('/newsrequest', news.newsRequest());
|
app.post('/newsrequest', news.newsRequest());
|
||||||
|
app.get('/newsheadersrequest', news.newsHeadersRequest());
|
||||||
|
app.post('/newsheadersrequest', news.newsHeadersRequest());
|
||||||
|
|
||||||
//database
|
//database
|
||||||
let { connectToDatabase } = require('./database.js');
|
let { connectToDatabase } = require('./database.js');
|
||||||
|
|||||||
+24
-1
@@ -4,6 +4,7 @@ require('dotenv').config();
|
|||||||
//libraries
|
//libraries
|
||||||
let fs = require('fs');
|
let fs = require('fs');
|
||||||
let path = require('path');
|
let path = require('path');
|
||||||
|
let firstline = require('firstline');
|
||||||
|
|
||||||
let { log } = require('../common/utilities.js');
|
let { log } = require('../common/utilities.js');
|
||||||
|
|
||||||
@@ -49,6 +50,28 @@ const newsRequest = () => (req, res) => {
|
|||||||
log('News sent', max, fileNames, JSON.stringify(json));
|
log('News sent', max, fileNames, JSON.stringify(json));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const newsHeadersRequest = () => (req, res) => {
|
||||||
|
let fpath = path.join(__dirname, '..', 'public', 'news');
|
||||||
|
let fileNames = fs.readdirSync(fpath);
|
||||||
|
|
||||||
|
let json = {};
|
||||||
|
|
||||||
|
let promises = [];
|
||||||
|
|
||||||
|
for(let i = 0; i < fileNames.length; i++) {
|
||||||
|
promises.push(firstline(path.join(fpath, fileNames[i])).then(fl => json[fileNames[i]] = { firstline: fl }));
|
||||||
|
}
|
||||||
|
|
||||||
|
Promise.all(promises)
|
||||||
|
.then(() => {
|
||||||
|
res.status(200).json(json);
|
||||||
|
res.end();
|
||||||
|
|
||||||
|
log('News headers sent', fileNames.length);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
newsRequest: newsRequest
|
newsRequest: newsRequest,
|
||||||
|
newsHeadersRequest: newsHeadersRequest
|
||||||
};
|
};
|
||||||
@@ -77,6 +77,7 @@ export default class App extends React.Component {
|
|||||||
<LazyRoute path='/tasklist' component={() => import('./pages/task_list.jsx')} />
|
<LazyRoute path='/tasklist' component={() => import('./pages/task_list.jsx')} />
|
||||||
<LazyRoute path='/patronlist' component={() => import('./pages/patron_list.jsx')} />
|
<LazyRoute path='/patronlist' component={() => import('./pages/patron_list.jsx')} />
|
||||||
<LazyRoute path='/news/:postId' component={() => import('./pages/news.jsx')} />
|
<LazyRoute path='/news/:postId' component={() => import('./pages/news.jsx')} />
|
||||||
|
<LazyRoute path='/news' component={() => import('./pages/news_index.jsx')} />
|
||||||
<LazyRoute path='/rules' component={() => import('./pages/rules.jsx')} />
|
<LazyRoute path='/rules' component={() => import('./pages/rules.jsx')} />
|
||||||
<LazyRoute path='/statistics' component={() => import('./pages/statistics.jsx')} />
|
<LazyRoute path='/statistics' component={() => import('./pages/statistics.jsx')} />
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { withRouter, Link } from 'react-router-dom';
|
||||||
|
|
||||||
//panels
|
//panels
|
||||||
import CommonLinks from '../panels/common_links.jsx';
|
import CommonLinks from '../panels/common_links.jsx';
|
||||||
@@ -39,6 +40,7 @@ class Home extends React.Component {
|
|||||||
<Blurb />
|
<Blurb />
|
||||||
<h1 className='centered'>News</h1>
|
<h1 className='centered'>News</h1>
|
||||||
<News setWarning={this.setWarning.bind(this)} getFetch={ (fn) => this.setState({ fetch: fn }) } />
|
<News setWarning={this.setWarning.bind(this)} getFetch={ (fn) => this.setState({ fetch: fn }) } />
|
||||||
|
<p className='centered'><Link to='/news'>See all news...</Link></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -50,4 +52,4 @@ class Home extends React.Component {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Home;
|
export default withRouter(Home);
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { withRouter, Link } from 'react-router-dom';
|
||||||
|
|
||||||
|
//panels
|
||||||
|
import CommonLinks from '../panels/common_links.jsx';
|
||||||
|
|
||||||
|
class NewsIndex extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
data: {},
|
||||||
|
warning: '' //TODO: unified warning?
|
||||||
|
};
|
||||||
|
|
||||||
|
this.sendRequest('/newsheadersrequest');
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
let warningStyle = {
|
||||||
|
display: this.state.warning.length > 0 ? 'flex' : 'none'
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='page'>
|
||||||
|
<div className='sidePanelPage'>
|
||||||
|
<div className='sidePanel'>
|
||||||
|
<CommonLinks />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='mainPanel'>
|
||||||
|
<div className='warning' style={warningStyle}>
|
||||||
|
<p>{this.state.warning}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ul className='panel'>
|
||||||
|
{Object.keys(this.state.data).map((fname) => <li key={fname} style={{paddingBottom: '0.5em'}}><Link to={`/news/${fname}`}>{fname}</Link> - {this.state.data[fname].firstline}</li>).reverse()}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
sendRequest(url, args = {}) { //send a unified request, using my credentials
|
||||||
|
//build the XHR
|
||||||
|
let xhr = new XMLHttpRequest();
|
||||||
|
xhr.open('POST', url, true);
|
||||||
|
|
||||||
|
xhr.onreadystatechange = () => {
|
||||||
|
if (xhr.readyState === 4) {
|
||||||
|
if (xhr.status === 200) {
|
||||||
|
let json = JSON.parse(xhr.responseText);
|
||||||
|
|
||||||
|
//on success
|
||||||
|
this.setState({ data: json });
|
||||||
|
}
|
||||||
|
else if (xhr.status === 400 && this.props.setWarning) {
|
||||||
|
this.props.setWarning(xhr.responseText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
|
||||||
|
xhr.send(JSON.stringify({
|
||||||
|
//NOTE: No id or token needed for the news
|
||||||
|
...args
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
setWarning(s) {
|
||||||
|
this.setState({ warning: s });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default withRouter(NewsIndex);
|
||||||
Reference in New Issue
Block a user