Created
February 25, 2020 19:36
-
-
Save Porter97/194528ef6ca24bdfce384fa28f07910a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
document.addEventListener("DOMContentLoaded", function() { | |
const client = stream.connect( | |
'Your Public Key Here', | |
'{{ token }}' | |
); | |
const user = client.feed('User', '{{ user.id }}'); | |
let collection_template = document.querySelector("#collection-template"); | |
let collection_scroller = document.querySelector("#collection-scroller"); | |
let collection_sentinel = document.querySelector("#collection-sentinel"); | |
let collection_loading = false; | |
let last_id = null; | |
function loadCollection() { | |
if (!collection_loading) { | |
collection_loading = true; | |
if (!last_id) { | |
request = user.get({ limit:10 }) | |
} else { | |
request = user.get({ limit:10, id_lt: last_id }) | |
} | |
request.then((data) => { | |
if (data.results.length < 1) { | |
collection_sentinel.innerHTML = `<p>That's All!<p>`; | |
collection_loading = false; | |
return; | |
} | |
for (var i = 0; i < data.results.length; i++) { | |
let template_clone = collection_template.content.cloneNode(true); | |
<!-- Author Info --> | |
template_clone.querySelector('#user-profile-img').src = data.results[i]['actor']['data']['gravatar']; | |
template_clone.querySelector('#user-profile-img').alt = 'None'; | |
template_clone.querySelector('#user-profile-link').href = '/user/' + data.results[i]['actor']['data']['username']; | |
template_clone.querySelector('#user-profile-link').innerHTML = data.results[i]['actor']['data']['username']; | |
<!-- Collection Info --> | |
template_clone.querySelector('#collection-name').innerHTML = data.results[i]['create']; | |
template_clone.querySelector('#collection-name').href = '/collection/' + data.results[i]['object'].slice(11); | |
template_clone.querySelector('#collection-description').innerHTML = data.results[i]['description']; | |
<!-- Collection Metadata --> | |
template_clone.querySelector('#collection-timestamp').innerHTML = moment(data.results[i]['time'] + 'Z').fromNow(); | |
collection_scroller.appendChild(template_clone) | |
} | |
last_id = data.results[data.results.length - 1].id; | |
collection_loading = false | |
}) | |
} | |
} | |
var collectionIntersectionObserver = new IntersectionObserver(entries => { | |
if (entries[0].intersectionRatio <= 0) { | |
return; | |
} | |
loadCollection(); | |
}); | |
collectionIntersectionObserver.observe(collection_sentinel) | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment