diff --git a/web/pages/grants/GranteeCard.tsx b/web/pages/grants/GranteeCard.tsx
index 4a31543c..4a3a69ab 100644
--- a/web/pages/grants/GranteeCard.tsx
+++ b/web/pages/grants/GranteeCard.tsx
@@ -3,15 +3,11 @@ import Image from 'next/image'
import { Grantee } from '.'
import { Row } from 'web/components/layout/row'
-import { sumBy } from 'lodash'
-import { formatLargeNumber, formatMoney } from 'common/util/format'
+import { formatLargeNumber } from 'common/util/format'
export default function GranteeCard(props: { grantee: Grantee }) {
const { grantee } = props
- const { slug, photo, preview } = grantee
-
- // sumBy grantee.grantsReceived amount
- const raised = sumBy(grantee.grantsReceived, (grant) => grant.amount)
+ const { slug, photo, preview, totalReceived } = grantee
return (
@@ -31,11 +27,11 @@ export default function GranteeCard(props: { grantee: Grantee }) {
{preview}
- {raised > 0 && (
+ {totalReceived > 0 && (
- {formatUsd(raised)}
+ {formatUsd(totalReceived)}
raised
diff --git a/web/pages/grants/index.tsx b/web/pages/grants/index.tsx
index febd5c44..6d540c55 100644
--- a/web/pages/grants/index.tsx
+++ b/web/pages/grants/index.tsx
@@ -1,5 +1,5 @@
import { searchInAny } from 'common/util/parse'
-import { debounce } from 'lodash'
+import { debounce, sortBy } from 'lodash'
import { useMemo, useState } from 'react'
import { Col } from 'web/components/layout/col'
import { Page } from 'web/components/page'
@@ -16,6 +16,7 @@ export type Grantee = {
preview: string
description: string
grantsReceived: Grant[]
+ totalReceived: number
}
export type Grant = {
@@ -59,10 +60,12 @@ function grantsToGrantees(grantsList: Grant[]) {
preview: grant.description,
description: grant.description,
grantsReceived: [],
+ totalReceived: 0,
}
grantees.push(grantee)
}
grantee.grantsReceived.push(grant)
+ grantee.totalReceived += grant.amount
}
console.log(grantees)
return grantees
@@ -72,13 +75,12 @@ export default function Grants() {
const [query, setQuery] = useState('')
const debouncedQuery = debounce(setQuery, 50)
- const filteredGrantees = useMemo(
- () =>
- grantees.filter((grantee) =>
- searchInAny(query, grantee.name, grantee.description)
- ),
- [query]
- )
+ const filteredGrantees = useMemo(() => {
+ const g = grantees.filter((grantee) =>
+ searchInAny(query, grantee.name, grantee.description)
+ )
+ return sortBy(g, 'totalReceived').reverse()
+ }, [query])
return (