Skip to content

Commit

Permalink
Add limit prop as a number logic and use in firebase query
Browse files Browse the repository at this point in the history
  • Loading branch information
Pabl0cks committed Mar 1, 2024
1 parent 48320f5 commit 3ebcab8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
13 changes: 6 additions & 7 deletions packages/nextjs/app/_components/CompletedGrants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ const CompletedGrantCard = ({ title, description, askAmount, builder, link, comp
);
};

export const CompletedGrants = async ({ reducedView = false }) => {
const completedGrants = await getAllCompletedGrants();
const grantsToShow = reducedView ? completedGrants.slice(0, 8) : completedGrants;
export const CompletedGrants = async ({ limit }: { limit?: number }) => {
const completedGrants = await getAllCompletedGrants(limit);

return (
<div className="bg-base-100">
Expand All @@ -46,17 +45,17 @@ export const CompletedGrants = async ({ reducedView = false }) => {
</div>
<div
className={`${
reducedView ? "grant-container-rwd" : ""
limit ? "grant-container-rwd" : ""
} flex flex-col items-center justify-center md:flex-row md:flex-wrap md:items-start gap-6`}
>
{grantsToShow.map(grant => (
{completedGrants.map(grant => (
<CompletedGrantCard key={grant.id} {...grant} />
))}
</div>
{reducedView && (
{limit && (
<div className="link w-full text-center mt-8 text-lg lg:text-xl">
<a href="/completed-grants" className="">
See all completed grants ({completedGrants.length})
See all completed grants
</a>
</div>
)}
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Home = () => {
<GrantsStats />
<EcosystemGrants />
<CommunityGrant />
<CompletedGrants reducedView={true} />
<CompletedGrants limit={8} />
<ActiveGrants />
</>
);
Expand Down
13 changes: 8 additions & 5 deletions packages/nextjs/services/database/grants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,15 @@ export const getAllGrantsForReview = async () => {
}
};

export const getAllCompletedGrants = async () => {
export const getAllCompletedGrants = async (limit?: number) => {
try {
const grantsSnapshot = await grantsCollection
.where("status", "==", PROPOSAL_STATUS.COMPLETED)
.orderBy("completedAt", "desc")
.get();
let query = grantsCollection.where("status", "==", PROPOSAL_STATUS.COMPLETED).orderBy("completedAt", "desc");

if (limit) {
query = query.limit(limit);
}

const grantsSnapshot = await query.get();
const grants: GrantData[] = [];
grantsSnapshot.forEach(doc => {
grants.push({ id: doc.id, ...doc.data() } as GrantData);
Expand Down

0 comments on commit 3ebcab8

Please sign in to comment.