From 1ab6891e89c18fc5cfcd1f7582e85ff9d3725b75 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 23 Nov 2019 10:06:03 -0600 Subject: load only 25 posts at a time into the DOM --- views.js | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/views.js b/views.js index fcab7dc..521de8d 100644 --- a/views.js +++ b/views.js @@ -79,11 +79,25 @@ function profilePage (src, keys) { } }, ['Delete feed'])) + async function addPosts (posts, keys) { + posts.forEach(function (msg) { + if (msg.author === src) { + scroller.appendChild(render(msg, keys)) + } + }) + } bog().then(log => { + var index = 0 if (log) { - log.forEach(function (msg) { - if (msg.author === src) { - scroller.appendChild(render(msg, keys)) + var posts = log.slice(index, index + 25) + addPosts(posts, keys).then(done => { + window.onscroll = function(ev) { + if ((window.innerHeight + window.scrollY) >= document.body.scrollHeight) { + posts = log.slice(index, index + 25) + index = index + 25 + addPosts(posts, keys) + console.log("Bottom of page"); + } } }) } @@ -145,10 +159,26 @@ function publicPage (keys) { scroller.appendChild(div) scroller.appendChild(composer(keys)) + + async function addPosts (posts, keys) { + posts.forEach(function (msg) { + scroller.appendChild(render(msg, keys)) + }) + } + bog().then(log => { + var index = 0 if (log) { - log.forEach(function (msg) { - scroller.appendChild(render(msg, keys)) + var posts = log.slice(index, index + 25) + addPosts(posts, keys).then(done => { + window.onscroll = function(ev) { + if ((window.innerHeight + window.scrollY) >= document.body.scrollHeight) { + posts = log.slice(index, index + 25) + index = index + 25 + addPosts(posts, keys) + console.log("Bottom of page"); + } + } }) } }) -- cgit v1.2.3-70-g09d2