[wip] category selector for article composer
This commit is contained in:
parent
20579e2c17
commit
7fe7ddcfac
@ -16,7 +16,7 @@
|
||||
const { session } = stores();
|
||||
|
||||
let editor;
|
||||
let title = '', image = '';
|
||||
let title = '', image = '', category = '';
|
||||
|
||||
let actions = [
|
||||
{
|
||||
@ -26,6 +26,7 @@
|
||||
result: function save() {
|
||||
window.localStorage['title'] = title;
|
||||
window.localStorage['image'] = image;
|
||||
window.localStorage['category'] = category;
|
||||
window.localStorage['html'] = editor.getHtml(true);
|
||||
alert('Successfully saved draft to browser local storage');
|
||||
}
|
||||
@ -53,6 +54,7 @@
|
||||
onMount(function load() {
|
||||
title = window.localStorage['title'] || '';
|
||||
image = window.localStorage['image'] || '';
|
||||
category = window.localStorage['category'] || '';
|
||||
editor.setHtml(window.localStorage['html'] || '', false);
|
||||
});
|
||||
|
||||
@ -88,6 +90,15 @@
|
||||
<form method="POST" action="/cms/article">
|
||||
<p>Article Title: <input type="text" name="title" bind:value={title} required placeholder="How to Assassinate the Governor of California"></p>
|
||||
<p>Article Author: <strong>{$session.user.realname}</strong></p>
|
||||
<p>Article Category: <select>
|
||||
{#await fetch('/c').then(r => r.json())}
|
||||
Loading...
|
||||
{:then categories}
|
||||
{#each categories as category}
|
||||
<option value={category}>{category}</option>
|
||||
{/each}
|
||||
{/await}
|
||||
</select></p>
|
||||
<p>Article Header Image URL: <input type="text" name="image" bind:value={image} required placeholder="http:// ..."></p>
|
||||
</form>
|
||||
<Editor bind:this={editor} {actions} />
|
||||
|
@ -205,16 +205,25 @@ express()
|
||||
isAuthor,
|
||||
async function(req, res, next) {
|
||||
try {
|
||||
const { html, title, image } = req.body;
|
||||
if (!title || !image || !html) {
|
||||
const { html, title, image, category } = req.body;
|
||||
if (!title || !image || !html || !category) {
|
||||
res.writeHead(422, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
res.end(JSON.stringify({
|
||||
message: `You must supply an article title, image URL, and content.`
|
||||
message: `You must supply an article title, image URL, category, and content.`
|
||||
}));
|
||||
}
|
||||
const article = await new Article({ html, title, image, author: req.user._id });
|
||||
const cat = await Category.findOne({ name: category });
|
||||
if (!cat) {
|
||||
res.writeHead(404, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
res.end(JSON.stringify({
|
||||
message: `That category does not exist.`
|
||||
}));
|
||||
}
|
||||
const article = await new Article({ html, title, image, category: cat, author: req.user._id });
|
||||
await article.save();
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/json'
|
||||
@ -288,7 +297,14 @@ express()
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
res.end(JSON.stringify(articles));
|
||||
})
|
||||
|
||||
.get('/c', async function (req, res, next) {
|
||||
let categories = await Category.find();
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
res.end(JSON.stringify(categories));
|
||||
})
|
||||
|
||||
.get('/me', function(req, res, next) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user