Browse Source

use zipper module for cycling through posts to edit

pull/1/head
wes 8 years ago
parent
commit
ef02c131c2
  1. 3
      src/posts.py
  2. 69
      src/scripts/editor.tag
  3. 7
      src/scripts/zipper.js
  4. 4
      src/styles/riotblog.scss
  5. 5
      src/website.py

3
src/posts.py

@ -49,3 +49,6 @@ class Posts:
def getpost(self, _id): def getpost(self, _id):
return jsonify(self.db[_id]) return jsonify(self.db[_id])
def delete(self, _id):
return self.db[_id].delete()

69
src/scripts/editor.tag

@ -2,43 +2,56 @@
<div class="centered container"> <div class="centered container">
<div class="columns"> <div class="columns">
<div class="column col-6"> <div class="column col-6">
<ul> <div>
<li each={this.currentPosts}> <span>
<p> {this.currentPost().title} by {this.currentPost().author}
{title} by {author} </span>
</p>
<button <button
class="btn btn-primary" class="btn btn-primary"
onclick={loadPost(this._id)}> onclick={loadPost(this.currentPost()._id)}>
Load it Load it
</button> </button>
</li> </div>
</ul> <button
class="btn btn-primary"
onclick={goLeft}
>
Prev
</button>
<button
class="btn btn-primary"
onclick={goRight}
>
Next
</button>
<p>
<button <button
class="btn btn-primary" class="btn btn-primary"
onclick={newPost} onclick={newPost}
> >
New Post New Post
</button> </button>
</p>
<p>
<span>title</span><input ref="title"> <span>title</span><input ref="title">
<span>author</span><input ref="author"></input> <span>author</span><input ref="author"></input>
<span>Editing post {_id}</span> <span>Editing post {this.currentPost()._id}</span>
<textarea onfocus={clearplaceholder} <textarea onfocus={clearplaceholder}
onblur={checkplaceholder} onblur={checkplaceholder}
oninput={echo} oninput={echo}
rows="30" rows="10"
cols="10" cols="10"
__disabled={""} __disabled={""}
class="editor form-input centered" class="editor form-input centered"
ref="textarea" ref="textarea">
maxlength={this.maxlength}>
{ placeholder } { placeholder }
</textarea> </textarea>
<button onclick={submit} <button onclick={submit}
class="btn post-submit centered"> class="btn post-submit centered">
Submit Post Submit Post
</button> </button>
</p>
</div> </div>
<div class="column col-6"> <div class="column col-6">
@ -66,9 +79,28 @@ this.placeholderText = "Write a post!"
this.placeholder = this.placeholderText; this.placeholder = this.placeholderText;
this.focused = false; this.focused = false;
this.currentPosts = []; this.currentPosts = Z.empty;
var self = this; var self = this;
currentPost() {
var defaultPost = {
"_id" : "",
"title" : "",
"author" : ""
};
return Z.focus(self.currentPosts, defaultPost);
}
goRight() {
self.update({"currentPosts" : Z.goRight(self.currentPosts)});
}
goLeft() {
self.update({"currentPosts" : Z.goLeft(self.currentPosts)});
}
clearplaceholder() { clearplaceholder() {
if (!this.focused) { if (!this.focused) {
this.update({ this.update({
@ -90,8 +122,7 @@ checkplaceholder() {
echo(ev) { echo(ev) {
this.update({ this.update({
"converted" : this.converter.makeHtml( "converted" : this.converter.makeHtml(
this.refs.textarea.value.trim() this.refs.textarea.value.trim())
)
}); });
} }
@ -138,7 +169,7 @@ submit() {
loadPost(_id) { loadPost(_id) {
return function() { return function() {
axios.get(`/blog/getpost/${_id}`) axios.get(`/blog/getpost/${self.currentPost()._id}`)
.then(function(resp) { .then(function(resp) {
self.refs.textarea.value = resp.data.content; self.refs.textarea.value = resp.data.content;
@ -159,7 +190,11 @@ loadPost(_id) {
listPosts() { listPosts() {
axios.get("/blog/allposts") axios.get("/blog/allposts")
.then(function(resp) { .then(function(resp) {
self.update({"currentPosts" : resp.data}); self.update(
{
"currentPosts" : Z.extend(self.currentPosts, resp.data)
}
);
}) })
.catch(function(err) { .catch(function(err) {
console.log(err); console.log(err);

7
src/scripts/zipper.js

@ -43,6 +43,10 @@ function goLeft(z) {
z.right.unshift(z.left.first())); z.right.unshift(z.left.first()));
} }
function extend(z, xs) {
return Zipper(z.left, z.right.concat(xs));
}
var empty = fromList([]); var empty = fromList([]);
export default { export default {
@ -51,5 +55,6 @@ export default {
"goRight" : goRight, "goRight" : goRight,
"goLeft" : goLeft, "goLeft" : goLeft,
"empty" : empty, "empty" : empty,
"fromList" : fromList "fromList" : fromList,
"extend" : extend
}; };

4
src/styles/riotblog.scss

@ -86,6 +86,4 @@ $branding: #5764c6;
margin-top: 10%; margin-top: 10%;
} }
.editor { .editor {}
height: 100% !important;
}

5
src/website.py

@ -101,6 +101,11 @@ def NeverWhere(configfile=None):
def getpost(_id): def getpost(_id):
return posts.getpost(_id) return posts.getpost(_id)
@app.route("/blog/del/<_id>")
@login_required
def delete(_id):
return posts.delete(_id)
# editor routes # editor routes
@app.route("/blog/editor/", methods=("GET", "POST")) @app.route("/blog/editor/", methods=("GET", "POST"))

Loading…
Cancel
Save