Browse Source

make buttons disabled when there are no more posts in a given direction

pull/1/head
wes 8 years ago
parent
commit
a2c708ce90
  1. 6
      src/posts.py
  2. 77
      src/scripts/post.tag
  3. 4
      src/scripts/postcontrols.tag
  4. 3
      src/styles/riotblog.scss

6
src/posts.py

@ -48,11 +48,11 @@ class Posts:
doc_ids = [result.doc for result in results] doc_ids = [result.doc for result in results]
if not doc_ids: if not doc_ids:
return jsonify(False) return jsonify("end")
if endkey and not startkey: if endkey and not startkey:
if len(doc_ids) < 2 or doc_ids[0] == endkey: if len(doc_ids) < 2 or doc_ids[0] == endkey:
return jsonify(False) return jsonify("start")
return jsonify(doc_ids[-2]) return jsonify(doc_ids[-2])
if len(doc_ids) == 1: if len(doc_ids) == 1:
@ -62,7 +62,7 @@ class Posts:
# if no startkey or endkey were specified, return the 0th post # if no startkey or endkey were specified, return the 0th post
return jsonify(doc_ids[1 if startkey else 0]) return jsonify(doc_ids[1 if startkey else 0])
return jsonify(False) return jsonify("end")
def allposts(self): def allposts(self):
result = self.db.iterview("blogPosts/blog-posts", 10, include_docs=True) result = self.db.iterview("blogPosts/blog-posts", 10, include_docs=True)

77
src/scripts/post.tag

@ -1,5 +1,15 @@
<post> <post>
<div class="posts-box post centered"> <div class="posts-box post centered">
<div
data-is="postcontrols"
prevloading={this.prevloading}
prev={this.prev}
atstart={this.start}
atend={this.end}
nextloading={this.nextloading}
next={this.next}
>
</div>
<div class="text-break animated fadeIn"> <div class="text-break animated fadeIn">
<loading if={this.loading}></loading> <loading if={this.loading}></loading>
<div <div
@ -16,7 +26,8 @@
data-is="postcontrols" data-is="postcontrols"
prevloading={this.prevloading} prevloading={this.prevloading}
prev={this.prev} prev={this.prev}
nomore={this.nomore} atstart={this.start}
atend={this.end}
nextloading={this.nextloading} nextloading={this.nextloading}
next={this.next} next={this.next}
> >
@ -45,13 +56,18 @@ self.title = "";
self.content = ""; self.content = "";
self.prevloading = ""; self.prevloading = "";
self.nextloading = ""; self.nextloading = "";
self.nomore = false;
self.content = ""; self.content = "";
self.swipe = false; self.swipe = false;
self.loading = self.opts.state.loaded; self.loading = self.opts.state.loaded;
this.start = false;
this.end = false;
const hashLength = 8;
prev(ev) { prev(ev) {
ev.preventDefault(); ev.preventDefault();
self.end = false;
if (self.prevloading || self.nextloading) { if (self.prevloading || self.nextloading) {
return; return;
} }
@ -62,11 +78,12 @@ prev(ev) {
next(ev) { next(ev) {
ev.preventDefault(); ev.preventDefault();
self.start = false;
if (self.nextloading || self.prevloading) { if (self.nextloading || self.prevloading) {
return; return;
} }
self.nextloading = " loader-branded"; self.nextloading = " loader-branded";
if (!self.nomore) { if (!self.end) {
self.update(); self.update();
} }
self.update({"swipe" : !self.swipe}); self.update({"swipe" : !self.swipe});
@ -79,36 +96,30 @@ toTop() {
}, 1000); }, 1000);
} }
updatePost(body) { updatePost(postcontent) {
if (body === "false") { if (postcontent == "end" || postcontent == "start") {
self.nomore = true;
self.prevloading = "";
self.nextloading = "";
self.loading = false;
self.update();
return;
}
else {
var postcontent = JSON.parse(body);
if (!postcontent) {
self.prevloading = ""; self.prevloading = "";
self.nextloading = ""; self.nextloading = "";
self.nomore = true;
self.swipe = !self.swipe; self.swipe = !self.swipe;
self.loading = false; self.loading = false;
self[postcontent] = true;
if (postcontent == "start") {
self.start = true;
}
else if (postcontent == "end") {
self.end = true;
}
self.update(); self.update();
return; return;
} }
self._id = postcontent._id.slice(-8); self._id = postcontent._id.slice(-hashLength);
self.author = postcontent.author; self.author = postcontent.author;
self.content = postcontent.content; self.content = postcontent.content;
self.title = postcontent.title; self.title = postcontent.title;
self.swipe = !self.swipe; self.swipe = !self.swipe;
self.nomore = false;
self.loading = false; self.loading = false;
self.one("updated", self.toTop); self.one("updated", self.toTop);
self.update(); self.update();
}
self.prevloading = ""; self.prevloading = "";
self.nextloading = ""; self.nextloading = "";
@ -118,28 +129,44 @@ updatePost(body) {
} }
nextPost(_id) { nextPost(_id) {
fetch(`/blog/switchpost/${_id.slice(-8)}`) fetch(`/blog/switchpost/${_id.slice(-hashLength)}`)
.then((resp) => resp.text()) .then((resp) => resp.text())
.then((resp) => { self.updatePost(resp) }) .then((resp) => {
var content = JSON.parse(resp);
if (content._id.slice(-hashLength) == self._id) {
/* Reached the end of the iterator */
self.update({
end : true,
loading : false,
prevloading : "",
nextloading : ""
});
return;
}
self.updatePost(content)
})
} }
prevPost(_id) { prevPost(_id) {
fetch(`/blog/prevpost/${_id.slice(-8)}`) fetch(`/blog/prevpost/${_id.slice(-hashLength)}`)
.then((resp) => resp.text()) .then((resp) => resp.text())
.then((resp) => { self.updatePost(resp) }) .then((resp) => {
var content = JSON.parse(resp);
self.updatePost(JSON.parse(resp))
})
} }
getPost(_id) { getPost(_id) {
var url; var url;
if (_id !== undefined && _id) { if (_id !== undefined && _id) {
url = `/blog/getpost/${_id.slice(-8)}`; url = `/blog/getpost/${_id.slice(-hashLength)}`;
} }
else { else {
url = "/blog/switchpost/"; url = "/blog/switchpost/";
} }
fetch(url) fetch(url)
.then((resp) => resp.text()) .then((resp) => resp.text())
.then((resp) => {self.updatePost(resp) }) .then((resp) => { self.updatePost(JSON.parse(resp)) })
} }
this.getPost(this.opts.state._id, "fadeIn"); this.getPost(this.opts.state._id, "fadeIn");

4
src/scripts/postcontrols.tag

@ -2,7 +2,7 @@
<div class="controls container"> <div class="controls container">
<div class="columns"> <div class="columns">
<div class="column col-6"> <div class="column col-6">
<button class={"btn btn-lg nav-button float-right " + (false ? "disabled" : " ") + this.opts.prevloading} <button class={"btn btn-lg nav-button float-right " + (this.opts.atstart ? "disabled" : " ") + this.opts.prevloading}
onclick={this.opts.prev} onclick={this.opts.prev}
> >
@ -10,7 +10,7 @@
</button> </button>
</div> </div>
<div class="column col-6"> <div class="column col-6">
<button class={"btn btn-lg nav-button float-left " + (false ? "disabled" : " ") + this.opts.nextloading} <button class={"btn btn-lg nav-button float-left " + (this.opts.atend ? "disabled" : " ") + this.opts.nextloading}
onclick={this.opts.next} onclick={this.opts.next}
> >
<i class="fa fa-arrow-right" aria-hidden="true"></i> <i class="fa fa-arrow-right" aria-hidden="true"></i>

3
src/styles/riotblog.scss

@ -133,6 +133,9 @@ p, h6, h4 {
.mobile-menu { .mobile-menu {
left: -100% !important; left: -100% !important;
border-radius: 5px !important;
border: 1px solid !important;
border-color: $branding !important;
} }
.my-avatar { .my-avatar {

Loading…
Cancel
Save