@@ -32,10 +32,6 @@ import {
32
32
Form ,
33
33
Switch ,
34
34
MenuTrigger ,
35
- Select ,
36
- Popover ,
37
- ListBox ,
38
- ListBoxItem ,
39
35
} from "react-aria-components" ;
40
36
41
37
import { type States , StateType as ApiStateType } from "../../hooks/use-api" ;
@@ -50,15 +46,14 @@ import { ModalDialog } from "../ModalDialog";
50
46
import { OracleIntegrityStakingGuide } from "../OracleIntegrityStakingGuide" ;
51
47
import { ProgramSection } from "../ProgramSection" ;
52
48
import { PublisherFaq } from "../PublisherFaq" ;
49
+ import { Select } from "../Select" ;
53
50
import { SparkChart } from "../SparkChart" ;
54
51
import { StakingTimeline } from "../StakingTimeline" ;
55
52
import { Styled } from "../Styled" ;
56
53
import { Tokens } from "../Tokens" ;
57
54
import { AmountType , TransferButton } from "../TransferButton" ;
58
55
import { TruncatedKey } from "../TruncatedKey" ;
59
56
60
- const PAGE_SIZE = 10 ;
61
-
62
57
type Props = {
63
58
api : States [ ApiStateType . Loaded ] | States [ ApiStateType . LoadedNoStakeAccount ] ;
64
59
currentEpoch : bigint ;
@@ -582,6 +577,9 @@ const PublisherList = ({
582
577
totalStaked,
583
578
yieldRate,
584
579
} : PublisherListProps ) => {
580
+ const [ pageSize , setPageSize ] = useState < ( typeof PageSize ) [ number ] > (
581
+ PageSize [ 2 ] ,
582
+ ) ;
585
583
const scrollTarget = useRef < HTMLDivElement | null > ( null ) ;
586
584
const [ search , setSearch ] = useState ( "" ) ;
587
585
const [ yoursFirst , setYoursFirst ] = useState ( true ) ;
@@ -615,10 +613,10 @@ const PublisherList = ({
615
613
const paginatedPublishers = useMemo (
616
614
( ) =>
617
615
filteredSortedPublishers . slice (
618
- ( currentPage - 1 ) * PAGE_SIZE ,
619
- currentPage * PAGE_SIZE ,
616
+ ( currentPage - 1 ) * pageSize ,
617
+ currentPage * pageSize ,
620
618
) ,
621
- [ filteredSortedPublishers , currentPage ] ,
619
+ [ filteredSortedPublishers , currentPage , pageSize ] ,
622
620
) ;
623
621
624
622
const updatePage = useCallback < typeof setPage > (
@@ -656,8 +654,8 @@ const PublisherList = ({
656
654
) ;
657
655
658
656
const numPages = useMemo (
659
- ( ) => Math . floor ( filteredSortedPublishers . length / PAGE_SIZE ) ,
660
- [ filteredSortedPublishers ] ,
657
+ ( ) => Math . floor ( filteredSortedPublishers . length / pageSize ) ,
658
+ [ filteredSortedPublishers , pageSize ] ,
661
659
) ;
662
660
663
661
return (
@@ -687,48 +685,26 @@ const PublisherList = ({
687
685
</ div >
688
686
</ SearchField >
689
687
< Select
690
- className = "flex flex-row items-center gap-2 2xl:hidden"
688
+ className = "2xl:hidden"
689
+ label = "Sort by"
690
+ options = { [
691
+ SortOption . PublisherNameDescending ,
692
+ SortOption . PublisherNameAscending ,
693
+ SortOption . RemainingPoolDescending ,
694
+ SortOption . RemainingPoolAscending ,
695
+ SortOption . ApyDescending ,
696
+ SortOption . ApyAscending ,
697
+ SortOption . SelfStakeDescending ,
698
+ SortOption . SelfStakeAscending ,
699
+ SortOption . NumberOfFeedsDescending ,
700
+ SortOption . NumberOfFeedsAscending ,
701
+ SortOption . QualityRankingDescending ,
702
+ SortOption . QualityRankingAscending ,
703
+ ] }
691
704
selectedKey = { sort }
692
- // @ts -expect-error react-aria coerces everything to Key for some reason...
693
705
onSelectionChange = { updateSort }
694
- >
695
- < Label className = "whitespace-nowrap opacity-80" > Sort by</ Label >
696
- < Button
697
- className = "group flex flex-row items-center gap-2 px-2 py-3 text-xs transition sm:px-4"
698
- size = "nopad"
699
- >
700
- { getSortName ( sort ) }
701
- < ChevronDownIcon className = "size-4 flex-none opacity-60 transition duration-300 group-data-[pressed]:-rotate-180" />
702
- </ Button >
703
- < Popover
704
- placement = "bottom end"
705
- className = "data-[entering]:animate-in data-[exiting]:animate-out data-[entering]:fade-in data-[exiting]:fade-out"
706
- >
707
- < ListBox
708
- className = "flex origin-top-right flex-col border border-neutral-400 bg-pythpurple-100 py-2 text-sm text-pythpurple-950 shadow shadow-neutral-400 outline-none"
709
- items = { [
710
- SortOption . PublisherNameDescending ,
711
- SortOption . PublisherNameAscending ,
712
- SortOption . RemainingPoolDescending ,
713
- SortOption . RemainingPoolAscending ,
714
- SortOption . ApyDescending ,
715
- SortOption . ApyAscending ,
716
- SortOption . SelfStakeDescending ,
717
- SortOption . SelfStakeAscending ,
718
- SortOption . NumberOfFeedsDescending ,
719
- SortOption . NumberOfFeedsAscending ,
720
- SortOption . QualityRankingDescending ,
721
- SortOption . QualityRankingAscending ,
722
- ] . map ( ( id ) => ( { id } ) ) }
723
- >
724
- { ( { id } ) => (
725
- < ListBoxItem className = "flex cursor-pointer items-center gap-2 whitespace-nowrap px-4 py-2 text-left data-[disabled]:cursor-default data-[focused]:bg-pythpurple-800/20 data-[has-submenu]:data-[open]:bg-pythpurple-800/10 data-[has-submenu]:data-[open]:data-[focused]:bg-pythpurple-800/20 focus:outline-none focus-visible:outline-none" >
726
- { getSortName ( id ) }
727
- </ ListBoxItem >
728
- ) }
729
- </ ListBox >
730
- </ Popover >
731
- </ Select >
706
+ show = { getSortName }
707
+ />
732
708
< Switch
733
709
isSelected = { yoursFirst }
734
710
onChange = { updateYoursFirst }
@@ -841,11 +817,19 @@ const PublisherList = ({
841
817
) }
842
818
843
819
{ numPages > 1 && (
844
- < Paginator
845
- currentPage = { currentPage }
846
- numPages = { numPages }
847
- onPageChange = { updatePage }
848
- />
820
+ < div className = "flex flex-col items-center justify-between gap-4 border-t border-neutral-600/50 p-4 sm:flex-row" >
821
+ < Select
822
+ label = "Page size"
823
+ options = { PageSize }
824
+ selectedKey = { pageSize }
825
+ onSelectionChange = { setPageSize }
826
+ />
827
+ < Paginator
828
+ currentPage = { currentPage }
829
+ numPages = { numPages }
830
+ onPageChange = { updatePage }
831
+ />
832
+ </ div >
849
833
) }
850
834
</ div >
851
835
) ;
@@ -864,7 +848,7 @@ const Paginator = ({ currentPage, numPages, onPageChange }: PaginatorProps) => {
864
848
. map ( ( _ , i ) => i + first ) ;
865
849
866
850
return (
867
- < ul className = "sticky inset-x-0 flex flex-row items-center justify-end gap-2 border-t border-neutral-600/50 p-4 " >
851
+ < ul className = "sticky inset-x-0 flex flex-row gap-2" >
868
852
{ currentPage > 1 && (
869
853
< li >
870
854
< Button
@@ -1698,6 +1682,8 @@ const getSortName = (sortOption: SortOption) => {
1698
1682
}
1699
1683
} ;
1700
1684
1685
+ const PageSize = [ 10 , 20 , 30 , 40 , 50 ] as const ;
1686
+
1701
1687
class InvalidKeyError extends Error {
1702
1688
constructor ( ) {
1703
1689
super ( "Invalid public key" ) ;
0 commit comments