Compare commits
No commits in common. "9d2597f7a433c3f309714579d8b3bd8f8cfc8409" and "ecade5608e69057134979e2e2c66199bcb74c2ad" have entirely different histories.
9d2597f7a4
...
ecade5608e
40
main.js
40
main.js
|
@ -6,22 +6,45 @@ const postCountElem = document.getElementById("post-count");
|
||||||
const postTotalElem = document.getElementById("post-total");
|
const postTotalElem = document.getElementById("post-total");
|
||||||
const loader = document.getElementById("loader");
|
const loader = document.getElementById("loader");
|
||||||
|
|
||||||
|
// we'll need a value for the max numaer of posts to be added to the page
|
||||||
|
const postLimit = 99;
|
||||||
// then we'll define a variable for how many posts we want to increase the
|
// then we'll define a variable for how many posts we want to increase the
|
||||||
// page by
|
// page by
|
||||||
const postIncrease = 9;
|
const postIncrease = 9;
|
||||||
|
// how many times can we increase the content until we reach the max limit?
|
||||||
|
const pageCount = Math.ceil(postLimit / postIncrease);
|
||||||
// and define a value to determine which page we're on
|
// and define a value to determine which page we're on
|
||||||
let currentPage = 1;
|
let currentPage = 1;
|
||||||
|
|
||||||
// how many times can we increase the content until we reach the max limit?
|
|
||||||
function getPageCount() {
|
postTotalElem.innerHTML = postLimit;
|
||||||
return Math.ceil(Object.keys(posts).length / postIncrease);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getRandomColor() {
|
function getRandomColor() {
|
||||||
const h = Math.floor(Math.random() * 360);
|
const h = Math.floor(Math.random() * 360);
|
||||||
return `hsl(${h}deg, 90%, 85%)`;
|
return `hsl(${h}deg, 90%, 85%)`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getUsername() {
|
||||||
|
const r = Math.floor(Math.random() * users.length);
|
||||||
|
return users[r].username;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getContent(username) {
|
||||||
|
let user = null;
|
||||||
|
for (let i = 0; i < users.length; i++) {
|
||||||
|
if (users[i].username == username) {
|
||||||
|
user = users[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class Post {
|
class Post {
|
||||||
constructor(data) {
|
constructor(data) {
|
||||||
this.id = data.id;
|
this.id = data.id;
|
||||||
|
@ -117,8 +140,8 @@ function addPosts(pageIdx) {
|
||||||
currentPage = pageIdx;
|
currentPage = pageIdx;
|
||||||
|
|
||||||
const startRange = (pageIdx - 1) * postIncrease;
|
const startRange = (pageIdx - 1) * postIncrease;
|
||||||
const endRange = currentPage == getPageCount()
|
const endRange = currentPage == pageCount
|
||||||
? posts.length
|
? postLimit
|
||||||
: pageIdx * postIncrease;
|
: pageIdx * postIncrease;
|
||||||
|
|
||||||
postCountElem.innerHTML = endRange;
|
postCountElem.innerHTML = endRange;
|
||||||
|
@ -139,7 +162,7 @@ function handleInfiniteScroll() {
|
||||||
addPosts(currentPage + 1);
|
addPosts(currentPage + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentPage === getPageCount()) {
|
if (currentPage === pageCount) {
|
||||||
removeInfiniteScroll();
|
removeInfiniteScroll();
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
@ -202,6 +225,7 @@ function writePost() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log(firstPost);
|
||||||
|
|
||||||
// generate a post to insert before the first post
|
// generate a post to insert before the first post
|
||||||
const postData = {
|
const postData = {
|
||||||
|
@ -281,6 +305,4 @@ loadDataFromEndpoint("https://api.wayfarer.games/singularity/posts.json", json =
|
||||||
const parent = posts[post.replyTo];
|
const parent = posts[post.replyTo];
|
||||||
parent.addReply(post);
|
parent.addReply(post);
|
||||||
}
|
}
|
||||||
|
|
||||||
postTotalElem.innerHTML = Object.keys(posts).length;
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue