forked from solana-labs/governance-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build improvements (solana-labs#427)
* dynamic import + remove of virtualization * pagination instand of virtual scrolling * add analyzer + upgrade next * perfromance fixes * remove link warning * hide pagination when there is only 1 page
- Loading branch information
1 parent
1d836ca
commit 1b88644
Showing
18 changed files
with
503 additions
and
1,119 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,46 +1,37 @@ | ||
import MemberItem from './MemberItem' | ||
import { List, AutoSizer } from 'react-virtualized' | ||
import PaginationComponent from '@components/Pagination' | ||
import { Member } from '@utils/uiTypes/members' | ||
import dynamic from 'next/dynamic' | ||
import { useEffect, useState } from 'react' | ||
const MemberItem = dynamic(() => import('./MemberItem')) | ||
|
||
const MembersItems = ({ activeMembers }: { activeMembers: Member[] }) => { | ||
const minRowHeight = 84 | ||
const listHeight = | ||
activeMembers.length > 4 | ||
? 350 | ||
: activeMembers.reduce((acc, member) => { | ||
const hasBothVotes = | ||
!member?.communityVotes.isZero() && !member?.councilVotes.isZero() | ||
|
||
return acc + (hasBothVotes ? 100 : minRowHeight) | ||
}, 0) | ||
const getRowHeight = ({ index }) => { | ||
const currentMember = activeMembers[index] | ||
const hasBothVotes = | ||
!currentMember?.communityVotes.isZero() && | ||
!currentMember?.councilVotes.isZero() | ||
return hasBothVotes ? 100 : minRowHeight | ||
const perPage = 7 | ||
const [members, setMembers] = useState<Member[]>([]) | ||
const totalPages = Math.ceil(activeMembers.length / perPage) | ||
const onPageChange = (page) => { | ||
setMembers(paginateMembers(page)) | ||
} | ||
function rowRenderer({ key, index, style }) { | ||
return ( | ||
<div key={key} style={style}> | ||
<MemberItem item={activeMembers[index]}></MemberItem> | ||
</div> | ||
) | ||
const paginateMembers = (page) => { | ||
return activeMembers.slice(page * perPage, (page + 1) * perPage) | ||
} | ||
useEffect(() => { | ||
setMembers(paginateMembers(0)) | ||
}, [activeMembers.length]) | ||
|
||
return ( | ||
<div className="space-y-3"> | ||
<AutoSizer disableHeight> | ||
{({ width }) => ( | ||
<List | ||
width={width} | ||
height={listHeight} | ||
rowCount={activeMembers.length} | ||
rowHeight={getRowHeight} | ||
rowRenderer={rowRenderer} | ||
/> | ||
)} | ||
</AutoSizer> | ||
</div> | ||
<> | ||
<div className="space-y-3 overflow-auto" style={{ maxHeight: 350 }}> | ||
{members.map((x) => ( | ||
<MemberItem item={x} key={x.walletAddress}></MemberItem> | ||
))} | ||
</div> | ||
<div> | ||
<PaginationComponent | ||
totalPages={totalPages} | ||
onPageChange={onPageChange} | ||
></PaginationComponent> | ||
</div> | ||
</> | ||
) | ||
} | ||
export default MembersItems |
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,49 @@ | ||
import { ArrowLeftIcon, ArrowRightIcon } from '@heroicons/react/outline' | ||
import React from 'react' | ||
import { Pagination } from 'react-headless-pagination' | ||
|
||
const PaginationComponent = ({ totalPages = 5, onPageChange }) => { | ||
const [page, setPage] = React.useState<number>(0) | ||
|
||
const handlePageChange = (page: number) => { | ||
setPage(page) | ||
onPageChange(page) | ||
} | ||
|
||
return ( | ||
<> | ||
{totalPages > 1 ? ( | ||
<Pagination | ||
currentPage={page} | ||
setCurrentPage={handlePageChange} | ||
totalPages={totalPages} | ||
edgePageCount={2} | ||
middlePagesSiblingCount={2} | ||
className="" | ||
truncableText="..." | ||
truncableClassName="" | ||
> | ||
<div className="flex flex-wrap pt-3 text-xs"> | ||
<Pagination.PrevButton className=""> | ||
<ArrowLeftIcon className="w-4 h-4 text-primary-light"></ArrowLeftIcon> | ||
</Pagination.PrevButton> | ||
|
||
<div className="flex items-center justify-center flex-grow"> | ||
<Pagination.PageButton | ||
activeClassName="opacity-60" | ||
inactiveClassName="" | ||
className="text-primary-light mx-1 hover:opacity-60 cursor-pointer" | ||
/> | ||
</div> | ||
|
||
<Pagination.NextButton className=""> | ||
<ArrowRightIcon className="w-4 h-4 text-primary-light"></ArrowRightIcon> | ||
</Pagination.NextButton> | ||
</div> | ||
</Pagination> | ||
) : null} | ||
</> | ||
) | ||
} | ||
|
||
export default PaginationComponent |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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,23 @@ | ||
// pages/_document.js | ||
import { Html, Head, Main, NextScript } from 'next/document' | ||
|
||
const Document = () => { | ||
return ( | ||
<Html> | ||
<Head> | ||
<link rel="preconnect" href="https://fonts.gstatic.com" /> | ||
<link | ||
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&family=PT+Mono&display=swap" | ||
rel="stylesheet" | ||
/> | ||
<link rel="apple-touch-icon" href="/apple-touch-icon.png" /> | ||
</Head> | ||
<body> | ||
<Main /> | ||
<NextScript /> | ||
</body> | ||
</Html> | ||
) | ||
} | ||
|
||
export default Document |
Oops, something went wrong.