Browse Source

Finished more posts load system

pull/98/head
jrtechs 3 years ago
parent
commit
30236674de
5 changed files with 56 additions and 13 deletions
  1. +1
    -0
      blog/category.js
  2. +1
    -1
      blog/homePage.js
  3. +25
    -11
      templates/blog/blogMain.html
  4. +0
    -1
      templates/blog/header.html
  5. +29
    -0
      utils/sql.js

+ 1
- 0
blog/category.js View File

@ -25,6 +25,7 @@ module.exports=
templateContext["title"] = category;
sql.getPostsFromCategory(category).then(function(posts)
{
templateContext["categoryID"] = posts[0].category_id;
Promise.all([blogBodyRenderer.renderBatchOfPosts(requestURL, posts, page, 5, templateContext),
require('./renderNextBar').main("/category" + request.url, page, 5, posts.length, templateContext)]).then(function()
{

+ 1
- 1
blog/homePage.js View File

@ -13,7 +13,7 @@ module.exports=
main: function(requestURL, request, templateContext)
{
var page = request.query.page;
templateContext["categoryID"] = 0;
return new Promise(function(resolve, reject)
{
sql.getAllPosts().then(function(posts)

+ 25
- 11
templates/blog/blogMain.html View File

@ -7,7 +7,7 @@
<script>
var postsToLoad= [1,3,4,5,6,7,8,12];
var postsToLoad= [];
/**
* Runs a get request using ajax
@ -63,14 +63,14 @@
{
pic = '<img src="/blogContent/headerImages/' + post.picture_url + '" style="width:100%;">';
}
return '<div class="blogPost">' + pic + '<div class="p-4"><b><h3>' + post.name + '</h3></b><h5>' + post.published + '</span></h5><div>' + post.blogBody + '<p class="text-center"><a class="btn btn-secondary btn-lg text-white" href="https://jrtechs.net/' + post.categoryURL + '"/"' + post.url + '"><b>Read More &raquo;</b></a></p></div></div></div><br><br><br>';
return '<div class="blogPost">' + pic + '<div class="p-4"><b><h3>' + post.name + '</h3></b><h5>' + post.published + '</span></h5><div>' + post.blogBody + '<p class="text-center"><a class="btn btn-secondary btn-lg text-white" href="https://jrtechs.net/' + post.categoryURL + '/' + post.url + '"><b>Read More &raquo;</b></a></p></div></div></div><br><br>';
}
function addPosts(id)
{
return new Promise(function(resolve, reject)
{
runAjax("api/preview/" + id,
runAjax("/api/preview/" + id,
(html)=>
{
var content = buildPostHTML(html)
@ -105,10 +105,26 @@
break;
}
await addPosts(postsToLoad.pop());
await addPosts(postsToLoad.shift());
}
console.log("Wham");
}
$(document).ready(function()
{
runAjax("/api/getPostsIds/{categoryID}",
(idsList)=>
{
postsToLoad=idsList;
},
(err)=>
{
console.log(err);
reject();
});
});
</script>
<br><br><br><br><br>
@ -155,13 +171,11 @@
<div id="newPosts"></div>
{if preview}
<div class="row justify-content-center w-100" id="morePostsBtn">
<div class="col-md-6 col-12">
<p class="text-center">
<a class="btn btn-secondary btn-lg text-white" id="readMore"
onclick="loadMore()"><b>More Posts &raquo;</b></a>
</p>
</div>
<div class="justify-content-center w-100 blogPost" id="morePostsBtn">
<a class="btn btn-secondary btn-lg btn-block text-white w-100 text-center" id="readMore"
onclick="loadMore()"><b>More Posts &raquo;</b></a>
</div>
{/if}
<br>

+ 0
- 1
templates/blog/header.html View File

@ -2,7 +2,6 @@
<html lang="en">
<head>
<!--fuck-->
{if title}
<title>Jrtechs: {title}</title>
{else}

+ 29
- 0
utils/sql.js View File

@ -178,6 +178,35 @@ module.exports=
});
},
getPostIds: function(categoryID)
{
return new Promise((resolve, reject)=>
{
if(categoryID == 0)
{
fetch("select post_id from posts order by published desc")
.then(function(ids)
{
resolve(ids);
}).catch((error)=>
{
reject(error);
});
}
else
{
fetch("select post_id from posts where category_id='" + categoryID + "' order by published desc")
.then(function(ids)
{
resolve(ids);
}).catch((error)=>
{
reject(error);
});
}
});
},
insert: function(sqlStatement)
{
return insert(sqlStatement);

Loading…
Cancel
Save