Skip to content

Commit

Permalink
Build improvements (solana-labs#427)
Browse files Browse the repository at this point in the history
* 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
abrzezinski94 authored Mar 9, 2022
1 parent 1d836ca commit 1b88644
Show file tree
Hide file tree
Showing 18 changed files with 503 additions and 1,119 deletions.
4 changes: 0 additions & 4 deletions components/AssetsList/types.ts

This file was deleted.

9 changes: 0 additions & 9 deletions components/GradientText.tsx

This file was deleted.

1 change: 0 additions & 1 deletion components/Members/MemberOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ const MemberOverview = () => {
<div className="font-normal mr-1 text-xs text-fgd-3 mb-4 mt-4">
Recent votes
</div>
{/* TODO virtual scroll */}
<div style={{ maxHeight: '350px' }} className="overflow-auto">
{ownVoteRecords.map((x) => (
<a
Expand Down
2 changes: 1 addition & 1 deletion components/Members/MembersCompactWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const MembersCompactWrapper = () => {
<h3 className="mb-0">{totalVotesCast}</h3>
</div>

<div style={{ maxHeight: '350px' }}>
<div>
<MembersItems activeMembers={activeMembers} />
</div>

Expand Down
65 changes: 28 additions & 37 deletions components/Members/MembersItems.tsx
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
49 changes: 49 additions & 0 deletions components/Pagination.tsx
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
1 change: 0 additions & 1 deletion components/RealmHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const RealmHeader = () => {
target="_blank"
rel="noopener noreferrer"
>
Realms v1
<ExternalLinkIcon className="flex-shrink-0 h-4 w-4 ml-1" />
</a>
</div>
Expand Down
6 changes: 0 additions & 6 deletions components/TreasuryAccount/Types.ts

This file was deleted.

25 changes: 0 additions & 25 deletions components/WalletIcon.jsx

This file was deleted.

2 changes: 1 addition & 1 deletion components/explorer/inspectorButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function InspectorButton({
disabled={!connected && !wasExecuted}
onClick={() => showInspector()}
>
{!wasExecuted ? 'Inspect' : 'Inspect executed instruction'}
{!wasExecuted ? 'Inspect' : 'View transaction'}
</SecondaryButton>
)
}
36 changes: 21 additions & 15 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@ const withTM = require('next-transpile-modules')([
'@solana/wallet-adapter-sollet',
])

module.exports = withTM({
webpack: (config, { isServer }) => {
config.module.rules.push({
test: /\.svg$/,
use: ['@svgr/webpack'],
})
if (!isServer) config.resolve.fallback.fs = false
return config
},
env: {
REALM: process.env.REALM,
MAINNET_RPC: process.env.MAINNET_RPC,
DEVNET_RPC: process.env.DEVNET_RPC,
DEFAULT_GOVERNANCE_PROGRAM_ID: process.env.DEFAULT_GOVERNANCE_PROGRAM_ID,
},
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
})

module.exports = withBundleAnalyzer(
withTM({
webpack: (config, { isServer }) => {
config.module.rules.push({
test: /\.svg$/,
use: ['@svgr/webpack'],
})
if (!isServer) config.resolve.fallback.fs = false
return config
},
env: {
REALM: process.env.REALM,
MAINNET_RPC: process.env.MAINNET_RPC,
DEVNET_RPC: process.env.DEVNET_RPC,
DEFAULT_GOVERNANCE_PROGRAM_ID: process.env.DEFAULT_GOVERNANCE_PROGRAM_ID,
},
})
)
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"build": "next build",
"start": "next start",
"prepare": "husky install",
"analyze": "ANALYZE=true next build",
"tc": "yarn type-check --watch",
"type-check": "tsc --pretty --noEmit",
"format": "prettier --write .",
Expand All @@ -30,6 +31,7 @@
"@headlessui/react": "^1.4.2",
"@heroicons/react": "^1.0.1",
"@marinade.finance/marinade-ts-sdk": "^2.0.9",
"@next/bundle-analyzer": "^12.1.0",
"@nfteyez/sol-rayz": "^0.8.0",
"@project-serum/anchor": "^0.20.1",
"@project-serum/common": "^0.0.1-beta.3",
Expand All @@ -49,16 +51,16 @@
"classnames": "^2.3.1",
"dayjs": "^1.10.7",
"immer": "^9.0.1",
"next": "^12.0.4",
"next": "^12.1.0",
"next-themes": "^0.0.14",
"next-transpile-modules": "^8.0.0",
"node-fetch": "^2.6.1",
"rc-slider": "^9.7.2",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-headless-pagination": "^0.1.0",
"react-markdown": "^7.0.0",
"react-portal": "^4.2.1",
"react-virtualized": "^9.22.3",
"superstruct": "^0.15.3",
"ts-node": "^10.5.0",
"tsconfig-paths": "^3.12.0",
Expand Down
10 changes: 4 additions & 6 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ import { WalletIdentityProvider } from '@cardinal/namespaces-components'
import useVoteStakeRegistryClientStore from 'VoteStakeRegistry/stores/voteStakeRegistryClientStore'
import useMarketStore from 'Strategies/store/marketStore'
import handleGovernanceAssetsStore from '@hooks/handleGovernanceAssetsStore'
import tokenService from '@utils/services/token'

function App({ Component, pageProps }) {
useHydrateStore()
useWallet()
useRouterHistory()
useVoteRegistry()
handleGovernanceAssetsStore()
useEffect(() => {
tokenService.fetchSolanaTokenList()
}, [])
const { loadMarket } = useMarketStore()
const { getOwnedDeposits, resetDepositState } = useDepositStore()
const { realm, realmInfo, symbol, ownTokenRecord } = useRealm()
Expand Down Expand Up @@ -74,11 +78,6 @@ function App({ Component, pageProps }) {
<div className="relative">
<Head>
<title>{title}</title>
<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"
/>

{faviconUrl && <link rel="icon" href={faviconUrl} />}

Expand All @@ -89,7 +88,6 @@ function App({ Component, pageProps }) {
)}

<meta name="description" content={description} />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<meta name="msapplication-TileColor" content="#ffffff" />
<meta name="theme-color" content="#ffffff" />

Expand Down
23 changes: 23 additions & 0 deletions pages/_document.tsx
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
Loading

0 comments on commit 1b88644

Please sign in to comment.