Compare commits
2 Commits
ecade5608e
...
9d2597f7a4
Author | SHA1 | Date |
---|---|---|
ktyl | 9d2597f7a4 | |
ktyl | 5f62b08fd1 |
40
main.js
40
main.js
|
@ -6,45 +6,22 @@ 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?
|
||||||
postTotalElem.innerHTML = postLimit;
|
function getPageCount() {
|
||||||
|
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;
|
||||||
|
@ -140,8 +117,8 @@ function addPosts(pageIdx) {
|
||||||
currentPage = pageIdx;
|
currentPage = pageIdx;
|
||||||
|
|
||||||
const startRange = (pageIdx - 1) * postIncrease;
|
const startRange = (pageIdx - 1) * postIncrease;
|
||||||
const endRange = currentPage == pageCount
|
const endRange = currentPage == getPageCount()
|
||||||
? postLimit
|
? posts.length
|
||||||
: pageIdx * postIncrease;
|
: pageIdx * postIncrease;
|
||||||
|
|
||||||
postCountElem.innerHTML = endRange;
|
postCountElem.innerHTML = endRange;
|
||||||
|
@ -162,7 +139,7 @@ function handleInfiniteScroll() {
|
||||||
addPosts(currentPage + 1);
|
addPosts(currentPage + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentPage === pageCount) {
|
if (currentPage === getPageCount()) {
|
||||||
removeInfiniteScroll();
|
removeInfiniteScroll();
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
@ -225,7 +202,6 @@ 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 = {
|
||||||
|
@ -305,4 +281,6 @@ 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