Getting pagination on the screen, buttons do nothing.

This commit is contained in:
Bradley Shellnut 2022-09-01 23:16:29 -05:00
parent 80ed9354f9
commit ce3e469399
4 changed files with 36 additions and 6 deletions

View file

@ -1,12 +1,17 @@
<script lang="ts"> <script lang="ts">
import { boredState } from '$root/lib/stores/boredState'; import { boredState } from '$root/lib/stores/boredState';
const totalCount = $boredState.search.totalCount || 1; // TODO: Check default value const totalCount = $boredState.search.totalCount; // TODO: Check default value
console.log('totalCount', totalCount);
$: pageSize = $boredState.search.pageSize; $: pageSize = $boredState.search.pageSize;
console.log('pageSize', pageSize);
$: currentPage = $boredState.search.currentPage; $: currentPage = $boredState.search.currentPage;
console.log('currentPage', currentPage);
$: skip = $boredState.search.skip; $: skip = $boredState.search.skip;
console.log('skip', skip);
const totalPages: number = Math.ceil(totalCount / pageSize); const totalPages: number = Math.ceil(totalCount / pageSize);
console.log('totalPages', totalPages);
const prevPage: number = currentPage - 1; const prevPage: number = currentPage - 1;
const nextPage: number = currentPage + 1; const nextPage: number = currentPage + 1;
const hasNextPage: boolean = nextPage <= totalPages; const hasNextPage: boolean = nextPage <= totalPages;
@ -15,17 +20,41 @@
totalCount - currentPage * pageSize >= 0 ? totalCount - currentPage * pageSize : 0; totalCount - currentPage * pageSize >= 0 ? totalCount - currentPage * pageSize : 0;
const pageArray = Array.from({ length: 10 }, (_, i) => i + 1); const pageArray = Array.from({ length: 10 }, (_, i) => i + 1);
console.log('pageArray', pageArray); // console.log('pageArray', pageArray);
</script> </script>
<div class="container"> <div class="container">
<button type="button" class="btn" disabled={!hasPrevPage}>Prev</button>
{#each pageArray as page} {#each pageArray as page}
<p>{page}</p> <button
type="button"
class="btn"
aria-current={page === currentPage}
class:current={page === currentPage}>{page}</button
>
{/each} {/each}
<button type="button" class="btn" disabled={!hasNextPage}>Next</button>
</div> </div>
<style lang="scss"> <style lang="scss">
.container { .container {
display: grid; display: flex;
justify-content: center;
gap: 1rem;
margin: 3rem 0;
}
button {
/* min-width: 50px; */
&[aria-current],
&.current {
color: black; // TODO: Fix these colors
background: white;
}
&[disabled] {
pointer-events: none;
color: var(--lightGrey);
text-decoration: line-through;
}
} }
</style> </style>

View file

@ -11,6 +11,7 @@ const state = () => {
} }
const initial: BoredStore = { const initial: BoredStore = {
loading: false, dialog: initialDialog, search: { loading: false, dialog: initialDialog, search: {
totalCount: 1,
pageSize: 25, pageSize: 25,
skip: 0, skip: 0,
currentPage: 1 currentPage: 1

View file

@ -7,7 +7,7 @@ export type Dialog = {
} }
export type Search = { export type Search = {
totalCount?: number; totalCount: number;
pageSize: number; pageSize: number;
skip: number; skip: number;
currentPage: number; currentPage: number;

View file

@ -71,7 +71,7 @@
<Game on:removeGameEvent={handleRemoveGame} {game} /> <Game on:removeGameEvent={handleRemoveGame} {game} />
{/each} {/each}
</div> </div>
<!-- <Pagination /> --> <Pagination />
</div> </div>
{/if} {/if}