Added news editor
This commit is contained in:
@@ -40,17 +40,16 @@ TODO: more info.
|
|||||||
- Administration Panel
|
- Administration Panel
|
||||||
- ~~Exclusive to admin accounts~~
|
- ~~Exclusive to admin accounts~~
|
||||||
- inspect aggregate user data
|
- inspect aggregate user data
|
||||||
- News blog system (microservice)
|
- ~~News blog system (microservice)~~
|
||||||
- ~~build the microservice to provide the news feed~~
|
- ~~build the microservice to provide the news feed~~
|
||||||
- ~~access an external news feed~~
|
- ~~access an external news feed~~
|
||||||
- admin panel for publishing and editing news
|
- ~~admin panel for publishing and editing news~~
|
||||||
- "created at" and "updated at" in the response
|
- ~~"created at" and "updated at" in the response~~
|
||||||
- Chat system (microservice)
|
- Chat system (microservice)
|
||||||
- Based on usernames
|
- Based on usernames
|
||||||
- Chat logs
|
- Chat logs
|
||||||
- Direct Messages & rooms
|
- Direct Messages & rooms
|
||||||
- admin panel banning/unbanning (currently borked)
|
- admin panel banning/unbanning (currently borked)
|
||||||
- Achievements?
|
|
||||||
- Privacy policy & data collection notice
|
- Privacy policy & data collection notice
|
||||||
|
|
||||||
# Email settings
|
# Email settings
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useCookies } from 'react-cookie';
|
|||||||
|
|
||||||
//import BannedEmails from '../panels/banned-emails';
|
//import BannedEmails from '../panels/banned-emails';
|
||||||
import NewsPublisher from '../panels/news-publisher';
|
import NewsPublisher from '../panels/news-publisher';
|
||||||
|
import NewsEditor from '../panels/news-editor';
|
||||||
|
|
||||||
const Admin = props => {
|
const Admin = props => {
|
||||||
const [cookies, setCookie] = useCookies();
|
const [cookies, setCookie] = useCookies();
|
||||||
@@ -17,6 +18,7 @@ const Admin = props => {
|
|||||||
<div className='page'>
|
<div className='page'>
|
||||||
<h1 className='centered'>Administration</h1>
|
<h1 className='centered'>Administration</h1>
|
||||||
<NewsPublisher uri={process.env.NEWS_URI} newsKey={process.env.NEWS_KEY} />
|
<NewsPublisher uri={process.env.NEWS_URI} newsKey={process.env.NEWS_KEY} />
|
||||||
|
<NewsEditor uri={process.env.NEWS_URI} newsKey={process.env.NEWS_KEY} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import Select from 'react-dropdown-select';
|
||||||
|
|
||||||
|
//DOCS: props.uri is the address of a live news-server
|
||||||
|
//DOCS: props.newsKey is the key of the live news-server
|
||||||
|
const NewsEditor = props => {
|
||||||
|
let titleElement, authorElement, bodyElement;
|
||||||
|
const [articles, setArticles] = useState(null);
|
||||||
|
const [index, setIndex] = useState(null);
|
||||||
|
|
||||||
|
if (!articles) {
|
||||||
|
fetch(`${props.uri}/titles?limit=999`, { method: 'GET' })
|
||||||
|
.then(a => {
|
||||||
|
if (!a.ok) {
|
||||||
|
throw `Network error ${a.status}: ${a.statusText} ${a.url}`;
|
||||||
|
}
|
||||||
|
return a.json();
|
||||||
|
})
|
||||||
|
.then(a => setArticles(a))
|
||||||
|
.catch(e => console.error(e))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h2 className='centered'>News Editor</h2>
|
||||||
|
<div>
|
||||||
|
<label htmlFor='article'>Article: </label>
|
||||||
|
<Select
|
||||||
|
options={(articles || []).map(article => { return { label: article.title, value: article.index }; })}
|
||||||
|
onChange={values => setIndex(fetchSelection(values[0].value, titleElement, authorElement, bodyElement, props.uri))}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<form onSubmit={async e => {
|
||||||
|
e.preventDefault();
|
||||||
|
await handleSubmit(index, titleElement.value, authorElement.value, bodyElement.value, props.uri, props.newsKey);
|
||||||
|
titleElement.value = authorElement.value = bodyElement.value = '';
|
||||||
|
}}>
|
||||||
|
<div>
|
||||||
|
<label htmlFor='title'>Title: </label>
|
||||||
|
<input type='text' name='title' ref={ e => titleElement = e } />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label htmlFor='author'>Author: </label>
|
||||||
|
<input type='text' name='author' ref={ e => authorElement = e } />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label htmlFor='body'>Body: </label>
|
||||||
|
<textarea name='body' rows='10' cols='150' ref={ e => bodyElement = e } />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type='submit'>Update</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchSelection = (index, titleElement, authorElement, bodyElement, uri) => {
|
||||||
|
fetch(`${uri}/archive/${index}`, {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Access-Control-Allow-Origin': '*'
|
||||||
|
})
|
||||||
|
.then(blob => blob.json())
|
||||||
|
.then(article => {
|
||||||
|
titleElement.value = article.title;
|
||||||
|
authorElement.value = article.author;
|
||||||
|
bodyElement.value = article.body;
|
||||||
|
})
|
||||||
|
.catch(e => console.error(e))
|
||||||
|
;
|
||||||
|
|
||||||
|
return index; //this is admittedly odd
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = async (index, title, author, body, uri, newsKey) => {
|
||||||
|
title = title.trim();
|
||||||
|
author = author.trim();
|
||||||
|
body = body.trim();
|
||||||
|
uri = uri.trim();
|
||||||
|
newsKey = newsKey.trim();
|
||||||
|
|
||||||
|
//fetch POST json data
|
||||||
|
const raw = await fetch(
|
||||||
|
`${uri}/${index}`,
|
||||||
|
{
|
||||||
|
method: 'PATCH',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Access-Control-Allow-Origin': '*'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ title: title, author: author, body: body, key: newsKey })
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (raw.ok) {
|
||||||
|
const result = await raw.json();
|
||||||
|
|
||||||
|
if (result.ok) {
|
||||||
|
alert(`Updated article index ${index}`);
|
||||||
|
} else {
|
||||||
|
alert(result.error);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
alert(raw.statusText);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default NewsEditor;
|
||||||
@@ -20,7 +20,7 @@ const NewsFeed = props => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h2 className='centered'>News Feed</h2>
|
<h1 className='centered'>News Feed</h1>
|
||||||
{(articles || []).map((article, index) => {
|
{(articles || []).map((article, index) => {
|
||||||
return (
|
return (
|
||||||
<div key={index}>
|
<div key={index}>
|
||||||
@@ -31,7 +31,7 @@ const NewsFeed = props => {
|
|||||||
<span>Last Updated {dateFormat(articles.updatedAt, 'fullDate')} ({`${article.edits} edit${article.edits > 1 ? 's': ''}`})</span> :
|
<span>Last Updated {dateFormat(articles.updatedAt, 'fullDate')} ({`${article.edits} edit${article.edits > 1 ? 's': ''}`})</span> :
|
||||||
<span>Published {dateFormat(articles.createdAt, 'fullDate')}</span>
|
<span>Published {dateFormat(articles.createdAt, 'fullDate')}</span>
|
||||||
}</p>
|
}</p>
|
||||||
<p>{article.body}</p>
|
<p style={{whiteSpace: 'pre-wrap'}}>{article.body}</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
|
//DOCS: props.uri is the address of a live news-server
|
||||||
|
//DOCS: props.newsKey is the key of the live news-server
|
||||||
const NewsPublisher = props => {
|
const NewsPublisher = props => {
|
||||||
let titleElement, authorElement, bodyElement;
|
let titleElement, authorElement, bodyElement;
|
||||||
|
|
||||||
|
|||||||
Generated
+551
-63
File diff suppressed because it is too large
Load Diff
@@ -36,6 +36,7 @@
|
|||||||
"node-cron": "^2.0.3",
|
"node-cron": "^2.0.3",
|
||||||
"nodemailer": "^6.4.17",
|
"nodemailer": "^6.4.17",
|
||||||
"react-cookie": "^4.0.3",
|
"react-cookie": "^4.0.3",
|
||||||
|
"react-dropdown-select": "^4.7.3",
|
||||||
"regenerator-runtime": "^0.13.7",
|
"regenerator-runtime": "^0.13.7",
|
||||||
"sequelize": "^6.4.0"
|
"sequelize": "^6.4.0"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user