Skip to content

Commit

Permalink
Merge pull request #473 from picsoritdidnthappen/database-staging
Browse files Browse the repository at this point in the history
adding lazy loading for bounties + claims
  • Loading branch information
picsoritdidnthappen authored Jan 13, 2025
2 parents 9a80dca + f304b07 commit aa42e24
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 20,521 deletions.
20,445 changes: 0 additions & 20,445 deletions package-lock.json

This file was deleted.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@trpc/next": "11.0.0-rc.592",
"@trpc/react-query": "11.0.0-rc.592",
"@trpc/server": "11.0.0-rc.592",
"@types/react-infinite-scroller": "^1.2.5",
"axios": "^1.6.8",
"clsx": "^2.0.0",
"framer-motion": "^11.0.12",
Expand All @@ -37,6 +38,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-dropzone": "^14.2.3",
"react-infinite-scroller": "^1.2.5",
"react-toastify": "^10.0.5",
"superjson": "^2.2.1",
"supports-color": "8.1.1",
Expand Down
29 changes: 26 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 36 additions & 34 deletions src/components/bounty/BountyClaims.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { useEffect, useState } from 'react';
import { trpc } from '@/trpc/client';
import { useGetChain } from '@/hooks/useGetChain';
import ClaimList from '@/components/bounty/ClaimList';
import InfiniteScroll from 'react-infinite-scroller';
import { bountyCurrentVotingClaim } from '@/utils/web3';

const PAGE_SIZE = 9;
Expand Down Expand Up @@ -77,41 +78,42 @@ export default function BountyClaims({ bountyId }: { bountyId: string }) {
</div>
</div>
{claims.data && (
<ClaimList
bountyId={bountyId}
isMultiplayer={bounty?.isMultiplayer || false}
votingClaim={
votingClaim
? {
...votingClaim,
accepted: votingClaim.is_accepted || false,
id: votingClaim.id.toString(),
bountyId: votingClaim.bounty_id.toString(),
issuer: votingClaim.issuer,
}
: null
<InfiniteScroll
loadMore={async () => await claims.fetchNextPage()}
hasMore={claims.hasNextPage && !claims.isFetchingNextPage}
loader={
<div key='loader' className='animate-pulse text-center'>
Loading more...
</div>
}
claims={claims.data.pages.flatMap((page) => {
return page.items.map((item) => ({
...item,
accepted: item.is_accepted || false,
id: item.id.toString(),
issuer: item.issuer,
bountyId: item.bounty_id.toString(),
}));
})}
/>
)}
{claims.hasNextPage && (
<div className='flex justify-center items-center'>
<button
onClick={() => claims.fetchNextPage()}
className='border border-white rounded-full px-5 backdrop-blur-sm bg-[#D1ECFF]/20 py-2'
disabled={claims.isFetchingNextPage}
>
{claims.isFetchingNextPage ? 'loading…' : 'show more'}
</button>
</div>
threshold={300}
>
<ClaimList
key={claims.data.pages[0]?.items[0]?.id || 'empty-list'}
bountyId={bountyId}
isMultiplayer={bounty?.isMultiplayer || false}
votingClaim={
votingClaim
? {
...votingClaim,
accepted: votingClaim.is_accepted || false,
id: votingClaim.id.toString(),
bountyId: votingClaim.bounty_id.toString(),
issuer: votingClaim.issuer,
}
: null
}
claims={claims.data.pages.flatMap((page) => {
return page.items.map((item) => ({
...item,
accepted: item.is_accepted || false,
id: item.id.toString(),
issuer: item.issuer,
bountyId: item.bounty_id.toString(),
}));
})}
/>
</InfiniteScroll>
)}
</div>
);
Expand Down
8 changes: 4 additions & 4 deletions src/components/bounty/BountyInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ export default function BountyInfo({ bountyId }: { bountyId: string }) {
<p className='mt-5 normal-case break-words'>
{bounty.data.description}
</p>
<p className='flex flex-row mt-5 normal-case break-all flex-wrap'>
<div className='flex flex-row mt-5 normal-case break-all flex-wrap'>
bounty issuer:&nbsp;
<span className='flex flex-row items-center justify-end overflow-hidden'>
<div className='flex flex-row items-center justify-end overflow-hidden'>
<DisplayAddress chain={chain} address={bounty.data.issuer} />
<div className='ml-2'>
<CopyAddressButton address={bounty.data.issuer} />
</div>
</span>
</p>
</div>
</div>
{isAdmin.data && (
<button
onClick={() => {
Expand Down
6 changes: 3 additions & 3 deletions src/components/bounty/BountyMultiplayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ export default function BountyMultiplayer({
<div className='flex flex-col px-0'>
{participants.isSuccess ? (
participants.data.map((participant) => (
<p
<div
key={participant.user_address}
className='flex items-center justify-between w-full'
>
<div className='flex flex-row items-center '>
<div className='flex flex-row items-center'>
<div className='mr-1'>
<CopyAddressButton
address={participant.user_address}
Expand All @@ -88,7 +88,7 @@ export default function BountyMultiplayer({
{`${formatEther(BigInt(participant.amount))} ${
chain.currency
}`}
</p>
</div>
))
) : (
<p>Loading addresses…</p>
Expand Down
9 changes: 5 additions & 4 deletions src/components/bounty/PastBountyCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Link from 'next/link';
import React, { useEffect, useState } from 'react';
import { ChainId, Claim } from '@/utils/types';
import { formatEther } from 'viem';
Expand Down Expand Up @@ -32,9 +31,11 @@ export default function PastBountyCard({
return (
<>
{claim && (
<Link
<div
className='lg:col-span-4 p-3 bg-whiteblue border-1 rounded-xl cursor-pointer'
href={`/${chain?.slug}/bounty/${claim.bountyId}`}
onClick={() => {
window.location.href = `/${chain?.slug}/bounty/${claim.bountyId}`;
}}
>
<div className='p-[2px] text-white relative bg-poidhRed border-poidhRed border-2 rounded-xl'>
<div>
Expand Down Expand Up @@ -77,7 +78,7 @@ export default function PastBountyCard({
{formatEther(BigInt(bountyAmount))} {chain?.currency}
</span>
</div>
</Link>
</div>
)}
</>
);
Expand Down
56 changes: 29 additions & 27 deletions src/components/layout/ContentHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { trpc } from '@/trpc/client';
import BountyList from '@/components/ui/BountyList';
import { cn } from '@/utils';
import { FormControl, MenuItem, Select } from '@mui/material';
import InfiniteScroll from 'react-infinite-scroller';
import { SortIcon } from '@/components/global/Icons';

type DisplayType = 'open' | 'progress' | 'past';
Expand All @@ -30,7 +31,7 @@ export default function ContentHome() {
);

return (
<>
<div>
<div className='z-1 flex flex-wrap container mx-auto border-b border-white hover:border-white py-6 md:py-12 sm:py-8 w-full items-center px-8'>
<div className='hidden md:flex flex-1'></div>
<div className='w-full md:w-auto flex justify-center'>
Expand Down Expand Up @@ -117,33 +118,34 @@ export default function ContentHome() {

<div className='pb-20 z-1'>
{bounties.data && (
<BountyList
bounties={bounties.data.pages.flatMap((page) =>
page.items.map((bounty) => ({
id: bounty.id.toString(),
title: bounty.title,
description: bounty.description,
amount: bounty.amount,
isMultiplayer: bounty.is_multiplayer || false,
inProgress: bounty.in_progress || false,
hasClaims: bounty.claims.length > 0,
network: chain.slug,
}))
)}
/>
<InfiniteScroll
loadMore={async () => await bounties.fetchNextPage()}
hasMore={bounties.hasNextPage && !bounties.isFetchingNextPage}
loader={
<div key='loader' className='animate-pulse text-center'>
Loading more...
</div>
}
threshold={300}
>
<BountyList
key={bounties.data.pages[0]?.items[0]?.id || 'empty-list'}
bounties={bounties.data.pages.flatMap((page) =>
page.items.map((bounty) => ({
id: bounty.id.toString(),
title: bounty.title,
description: bounty.description,
amount: bounty.amount,
isMultiplayer: bounty.is_multiplayer || false,
inProgress: bounty.in_progress || false,
hasClaims: bounty.claims.length > 0,
network: chain.slug,
}))
)}
/>
</InfiniteScroll>
)}
</div>
{bounties.hasNextPage && (
<div className='flex justify-center items-center pb-96'>
<button
className='border border-white rounded-full px-5 backdrop-blur-sm bg-[#D1ECFF]/20 py-2'
onClick={() => bounties.fetchNextPage()}
disabled={bounties.isFetchingNextPage}
>
{bounties.isFetchingNextPage ? 'loading...' : 'show more'}
</button>
</div>
)}
</>
</div>
);
}
1 change: 0 additions & 1 deletion src/components/ui/BountyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export default function BountyList({ bounties }: { bounties: Bounty[] }) {
scale: 1,
transition: {
delayChildren: 0.3,
staggerChildren: 0.2,
},
},
}}
Expand Down

0 comments on commit aa42e24

Please sign in to comment.