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

View File

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