fix: correct pagination issues

This commit is contained in:
Damillora 2021-05-10 10:17:42 +07:00
parent 5123bc8a24
commit c978c6eb50
2 changed files with 9 additions and 9 deletions

View File

@ -20,14 +20,14 @@
let queryParams;
$: queryParams = queryString.parse(location.search);
if(queryParams.page) {
page = queryParams.page;
page = parseInt(queryParams.page);
}
getData();
})
const handlePage = (i) => {
return () => {
page = 1;
page = i;
getData();
}
}
@ -51,7 +51,7 @@
<a class="pagination-next">Next page</a>
{/if}
<ul class="pagination-list">
{#if page > 2}
{#if page > 3}
<li>
<Link on:click="{handlePage(1)}" to="/posts?page={1}" class="pagination-link" aria-label="Goto page 1">1</Link>
</li>
@ -72,7 +72,7 @@
{/if}
{/if}
{/each}
{#if (totalPages - page) > 2}
{#if (totalPages - page) > 3}
<li>
<span class="pagination-ellipsis">&hellip;</span>
</li>

View File

@ -15,21 +15,21 @@
const data = await getPostsTag({page, tag: id});
if(Array.isArray(data.posts)) {
posts = data.posts;
totalPages = data.totalPage;
}
}
onMount(() => {
let queryParams;
queryParams = queryString.parse(location.search);
if(queryParams.page) {
page = queryParams.page;
totalPages = data.totalPage;
page = parseInt(queryParams.page);
}
getData();
})
const handlePage = (i) => {
return () => {
page = 1;
page = i;
getData();
}
}
@ -56,7 +56,7 @@
<a class="pagination-next">Next page</a>
{/if}
<ul class="pagination-list">
{#if page > 2}
{#if page > 3}
<li>
<Link on:click="{handlePage(1)}" to="/tag/{id}?page={1}" class="pagination-link" aria-label="Goto page 1">1</Link>
</li>
@ -77,7 +77,7 @@
{/if}
{/if}
{/each}
{#if (totalPages - page) > 2}
{#if (totalPages - page) > 3}
<li>
<span class="pagination-ellipsis">&hellip;</span>
</li>