diff options
Diffstat (limited to 'lib/serve.js')
-rw-r--r-- | lib/serve.js | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/lib/serve.js b/lib/serve.js index 5f5a97e..8e563fb 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -530,58 +530,69 @@ function mergeOpts(a, b) { } Serve.prototype.renderThreadPaginated = function (opts, feedId, q) { - function link(opts, name, cb) { - cb(null, h('tr', h('td.paginate', {colspan: 2}, - h('a', {href: '?' + qs.stringify(mergeOpts(q, opts))}, name)))) + var self = this + function linkA(opts, name) { + var q1 = mergeOpts(q, opts) + return h('a', {href: '?' + qs.stringify(q1)}, name || q1.limit) + } + function links(opts) { + var limit = opts.limit || q.limit || 10 + return h('tr', h('td.paginate', {colspan: 2}, + opts.forwards ? '↑ newer ' : '↓ older ', + linkA(mergeOpts(opts, {limit: 1})), ' ', + linkA(mergeOpts(opts, {limit: 10})), ' ', + linkA(mergeOpts(opts, {limit: 100})) + )) } + return pull( paginate( function onFirst(msg, cb) { var num = feedId ? msg.value.sequence : msg.timestamp || msg.ts if (q.forwards) { - link({ + cb(null, links({ lt: num, gt: null, forwards: null, - }, '↓ older', cb) + })) } else { - link({ + cb(null, links({ lt: null, gt: num, forwards: 1, - }, '↑ newer', cb) + })) } }, this.app.render.renderFeeds(), function onLast(msg, cb) { var num = feedId ? msg.value.sequence : msg.timestamp || msg.ts if (q.forwards) { - link({ + cb(null, links({ lt: null, gt: num, forwards: 1, - }, '↑ newer', cb) + })) } else { - link({ + cb(null, links({ lt: num, gt: null, forwards: null, - }, '↓ older', cb) + })) } }, function onEmpty(cb) { if (q.forwards) { - link({ + cb(null, links({ gt: null, lt: opts.gt + 1, forwards: null, - }, '↓ older', cb) + })) } else { - link({ + cb(null, links({ gt: opts.lt - 1, lt: null, forwards: 1, - }, '↑ newer', cb) + })) } } ), |