about page & load more button

This commit is contained in:
2024-06-23 19:32:19 +02:00
parent d269814488
commit f3bf7f6551
10 changed files with 95 additions and 22 deletions

View File

@@ -3,7 +3,31 @@
export let data;
let endOfArticle = false;
let { blog } = data;
let returnSize = blog.total_articles;
let offset = blog.articles.length;
function loadMore() {
if (offset >= returnSize) {
endOfArticle = true;
} else {
fetch(`/getPosts?offset=${offset}`)
.then(response => response.json())
.then(newArticles => {
if (newArticles.length > 0) {
blog.articles = [...blog.articles, ...newArticles];
offset += newArticles.length;
if(offset >= returnSize) endOfArticle = true;
} else {
endOfArticle = true;
}
})
.catch(error => console.error('Error loading more articles:', error));
}
}
</script>
<div>
@@ -39,6 +63,10 @@
</div>
</a>
{/each}
{#if !endOfArticle}
<button on:click={loadMore} class="px-8 py-3 bg-gray-200 hover:bg-gray-300 cursor-pointer duration-150 text-gray-900 rounded-lg font-semibold mt-6 mx-auto">Load more</button>
{/if}
</div>
</div>
</div>