Browse Source

make sure to use preloaded results

pull/1/head
wes 7 years ago
parent
commit
493072060c
  1. 10
      src/posts.py
  2. 26
      src/scripts/browse.tag
  3. 10
      src/scripts/editor.tag

10
src/posts.py

@ -118,7 +118,12 @@ class Posts:
return jsonify(posts)
def links(self, json=True):
"""
Get the links we want to show
"""
result = list(self.db.iterview("blogPosts/links", 1, include_docs=True))
# make sure there are results
if len(result) >= 1:
xs = result[0].doc.get("links", [])
return jsonify(xs) if json else xs
@ -134,6 +139,11 @@ class Posts:
return jsonify(False)
def categories(self):
"""
Get the full list of all categories
"""
# the view returns a list of lists of category names
# we want to get the unique ones in a flat list
return list(set(chain.from_iterable([
c["key"][1] for c in
self.db.view("blogPosts/categories",

26
src/scripts/browse.tag

@ -4,7 +4,11 @@
style={navStyle}
class="container"
>
<div class="columns">
<div
if={opts.state.pagenum > 0 ||
opts.state.results.length == pagesize}
class="columns"
>
<div class="col-4">
<button
disabled={(opts.state.pagenum == 0) || loading}
@ -18,7 +22,9 @@
<div class="col-4">
<button
class="btn btn-primary branded"
disabled={(opts.state.results.length != pagesize) || loading}
disabled={((opts.state.results.length != pagesize) ||
loading ||
disabled)}
style={nextStyle}
onclick={getmore}
>
@ -78,6 +84,7 @@ var self = this;
self.route = route;
self.loading = false;
self.disabled = false;
self.converter = new showdown.Converter();
self.pagesize = 4;
@ -116,6 +123,7 @@ self.filterCategories = (category) => {
self.route(`browse/${category}`);
self.update({
"disabled" : false,
"loading" : true
});
self.opts.state.pagenum = 0;
@ -142,11 +150,11 @@ self.getPrev = (endkey) => {
else {
endpoint = `/blog/prevbrowse/${self.pagesize}/${endkey}`;
}
self.opts.state.pagenum--;
window.cached(endpoint)
.then((resp) => { return resp.json() })
.then((results) => {
self.opts.state.pagenum--;
self.opts.state.results = results;
self.update({
"loading" : false
@ -164,12 +172,17 @@ self.getNext = (startkey) => {
else {
endpoint = `/blog/getbrowselim/${self.pagesize}/${startkey}`;
}
self.opts.state.pagenum++;
window.cached(endpoint)
.then((resp) => { return resp.json() })
.then((results) => {
self.opts.state.results = results;
if (results.length > 0) {
self.opts.state.results = results;
self.opts.state.pagenum++;
}
else {
self.disabled = true;
}
self.update({
"loading" : false
});
@ -204,6 +217,9 @@ self.on("mount", () => {
if (!self.opts.state.category_filter && !self.opts.state.category_tag) {
self.getInitial();
}
else if (self.opts.state.results.length > 0 && !self.opts.state.category_tag) {
return;
}
else if (self.opts.state.category_tag) {
self.filterCategories(self.opts.state.category_tag)();
}

10
src/scripts/editor.tag

@ -13,7 +13,7 @@
<div class="column col-6">
<button
style={{"float" : "right"}}
class="btn btn-primary"
class="btn btn-primary branded"
onclick={goLeft}
>
Prev
@ -22,7 +22,7 @@
<div class="column col-6">
<button
style={{"float" : "left"}}
class="btn btn-primary"
class="btn btn-primary branded"
onclick={goRight}
>
Next
@ -36,13 +36,13 @@
<span>Editing post {!this.isNewPost ? this._id : ""}</span>
<p>
<button
class="btn btn-primary"
class="btn btn-primary branded"
onclick={deletePost(!this.isNewPost ? this._id : false)}
>
Delete Post
</button>
<button
class="btn btn-primary"
class="btn btn-primary branded"
onclick={newPost}
>
New Post
@ -59,7 +59,7 @@
{ placeholder }
</textarea>
<button onclick={submit}
class="btn post-submit centered">
class="btn post-submit centered branded">
Submit Post
</button>
</p>

Loading…
Cancel
Save