From 7088758cc706e9bb58de7ed36ce731eea816f2ff Mon Sep 17 00:00:00 2001 From: wes Date: Sat, 12 Aug 2017 13:11:44 -0400 Subject: [PATCH] load projects ondemand --- src/scripts/app.tag | 42 ++------------------------------------- src/scripts/links.tag | 2 +- src/scripts/post.tag | 12 +++++------ src/scripts/projects.tag | 43 ++++++++++++++++++++++++++-------------- src/scripts/riotblog.js | 17 ++++++++++++++++ 5 files changed, 53 insertions(+), 63 deletions(-) diff --git a/src/scripts/app.tag b/src/scripts/app.tag index 2abe4df..115d6c8 100644 --- a/src/scripts/app.tag +++ b/src/scripts/app.tag @@ -50,10 +50,9 @@
- @@ -62,7 +61,6 @@
@@ -87,12 +84,7 @@ import './projectsview.tag'; import './postsview.tag'; import './about.tag'; import './links.tag'; -import './loading.tag'; -import fetchCached from 'fetch-cached'; -import 'whatwg-fetch'; -import Z from './zipper.js'; -import pathEq from 'ramda/src/pathEq'; import route from 'riot-route'; import lens from './lenses.js'; import { throttle } from 'lodash-es'; @@ -101,8 +93,6 @@ const hashLength = 8; var self = this; -self.cache = {}; - self.showBorder = false; self.route = route; self.riot = riot; @@ -124,18 +114,6 @@ document.addEventListener("click", function(event) { } }); -self.cached = fetchCached({ - fetch: fetch, - cache: { - get: ((k) => { - return new Promise((resolve, reject) => { - resolve(self.cache[k]); - }); - }), - set: (k, v) => { self.cache[k] = v; } - } -}); - RiotControl.on("postswitch", (ev) => { self.update( @@ -149,7 +127,6 @@ self.state = { "_id" : self.opts.postid.slice(-hashLength), "author" : self.opts.author, "title" : self.opts.title, - "projects" : Z.empty, "loaded" : false, "initial" : decodeURIComponent(self.opts.initial_post) }; @@ -233,22 +210,8 @@ self.one("updated", () => { route.start(true); }); -function loaduser() { - /* https://api.github.com/users/${self.username}/repos?sort=updated&direction=desc */ - self.cached("/blog/ghprojects") - .then((resp) => resp.json()) - .then((resp) => { - self.state.projects = Z.fromList( - resp.filter( - pathEq(["fork"], false))); - - self.state.loaded = true; - self.update(); - }); -} - function getcategories() { - self.cached("/blog/categories") + window.cached("/blog/categories") .then((resp) => resp.json()) .then((resp) => { self.categories = resp; @@ -256,7 +219,6 @@ function getcategories() { }); } -self.on("mount", loaduser); self.on("mount", getcategories); self.on("mount", () => { diff --git a/src/scripts/links.tag b/src/scripts/links.tag index 7c385bd..c73a91b 100644 --- a/src/scripts/links.tag +++ b/src/scripts/links.tag @@ -45,7 +45,7 @@ self.groups = [] getLinks() { self.update({"loading" : true}); - self.opts.cached("/blog/links/") + window.cached("/blog/links/") .then((resp) => resp.text()) .then((resp) => { self.update( diff --git a/src/scripts/post.tag b/src/scripts/post.tag index c71083f..9ccd0b4 100644 --- a/src/scripts/post.tag +++ b/src/scripts/post.tag @@ -10,12 +10,11 @@ next={next} >
- +
{ @@ -73,9 +74,6 @@ RiotControl.on("filtercategory", console.log(category); }); -self.start = false; -self.end = false; - prev(ev) { ev.preventDefault(); self.end = false; @@ -148,7 +146,7 @@ updatePost(postcontent) { nextPost(_id) { self.update({"loading" : true}); - self.opts.cached(`/blog/switchpost/${_id.slice(-hashLength)}/${self.category}`) + window.cached(`/blog/switchpost/${_id.slice(-hashLength)}/${self.category}`) .then((resp) => resp.text()) .then((resp) => { var content = JSON.parse(resp); @@ -168,7 +166,7 @@ nextPost(_id) { prevPost(_id) { self.update({"loading" : true}); - self.opts.cached(`/blog/prevpost/${_id.slice(-hashLength)}/${self.category}`) + window.cached(`/blog/prevpost/${_id.slice(-hashLength)}/${self.category}`) .then((resp) => resp.text()) .then((resp) => { self.updatePost(JSON.parse(resp)) diff --git a/src/scripts/projects.tag b/src/scripts/projects.tag index b21ae4e..6b40edd 100644 --- a/src/scripts/projects.tag +++ b/src/scripts/projects.tag @@ -6,15 +6,16 @@
- +
-
+ +

{ this.project().name }

@@ -60,23 +61,19 @@
diff --git a/src/scripts/riotblog.js b/src/scripts/riotblog.js index 0feee6d..9dc62f8 100644 --- a/src/scripts/riotblog.js +++ b/src/scripts/riotblog.js @@ -9,6 +9,23 @@ import './grid.js'; import { default as promise } from 'es6-promise'; import { default as smooth } from 'smoothscroll-polyfill'; import 'element-closest'; +import fetchCached from 'fetch-cached'; +import 'whatwg-fetch'; + + +window.cache = {}; + +window.cached = fetchCached({ + fetch: fetch, + cache: { + get: ((k) => { + return new Promise((resolve, reject) => { + resolve(window.cache[k]); + }); + }), + set: (k, v) => { window.cache[k] = v; } + } +}); window.addEventListener("load", () => {