-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bridge-ui): add transaction list pagination (#13586)
Co-authored-by: Francisco Ramos <jscriptcoder@gmail.com>
- Loading branch information
1 parent
c86f2cd
commit a3b7498
Showing
6 changed files
with
194 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<script lang="ts"> | ||
export let totalPages: number; | ||
export let page: number; | ||
const DISABLED_BUTTON_LABEL = '...'; | ||
function getPageButtons(pages: number) { | ||
if (pages <= 5) { | ||
return new Array(pages).fill(0).map((_, index) => ({ | ||
label: index + 1, | ||
onClick: () => (page = index + 1), | ||
value: index + 1, | ||
})); | ||
} else { | ||
return [ | ||
{ | ||
label: 1, | ||
onClick: () => (page = 1), | ||
value: 1, | ||
}, | ||
{ | ||
label: 2, | ||
onClick: () => (page = 2), | ||
value: 2, | ||
}, | ||
{ | ||
label: DISABLED_BUTTON_LABEL, | ||
onClick: () => { | ||
// do nothing | ||
}, | ||
}, | ||
{ | ||
label: pages - 1, | ||
onClick: () => (page = pages - 2), | ||
value: pages - 1, | ||
}, | ||
{ | ||
label: pages, | ||
onClick: () => (page = pages - 1), | ||
value: pages, | ||
}, | ||
]; | ||
} | ||
} | ||
function makeButtons(pages) { | ||
return [ | ||
{ | ||
label: '<<', | ||
onClick: () => (page = 1), | ||
}, | ||
{ | ||
label: '<', | ||
onClick: () => { | ||
if (page > 1) { | ||
page -= 1; | ||
} | ||
}, | ||
}, | ||
...getPageButtons(pages), | ||
{ | ||
label: '>', | ||
onClick: () => { | ||
if (page < totalPages) { | ||
page += 1; | ||
} | ||
}, | ||
}, | ||
{ | ||
label: '>>', | ||
onClick: () => (page = pages), | ||
}, | ||
]; | ||
} | ||
$: buttons = makeButtons(totalPages); | ||
</script> | ||
|
||
<div class="btn-group pagination justify-center mt-4"> | ||
{#each buttons as button} | ||
<button | ||
class={`btn btn-xs md:btn-md ${ | ||
button.value === page ? 'btn-active text-white' : '' | ||
} ${button.label === DISABLED_BUTTON_LABEL ? 'btn-disabled' : ''}`} | ||
on:click={button.onClick}>{button.label}</button> | ||
{/each} | ||
</div> | ||
|
||
<style> | ||
.pagination .btn-active { | ||
color: white; | ||
background-color: hsla(var(--af) / var(--tw-bg-opacity, 1)); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import type { RelayerAPI, RelayerBlockInfo } from '../domain/relayerApi'; | ||
import type { | ||
PaginationInfo, | ||
RelayerAPI, | ||
RelayerBlockInfo, | ||
} from '../domain/relayerApi'; | ||
import { writable } from 'svelte/store'; | ||
|
||
const relayerApi = writable<RelayerAPI>(); | ||
const relayerBlockInfoMap = writable<Map<number, RelayerBlockInfo>>(); | ||
const paginationInfo = writable<PaginationInfo>(); | ||
|
||
export { relayerApi, relayerBlockInfoMap }; | ||
export { relayerApi, relayerBlockInfoMap, paginationInfo }; |