Try to fix charity error 2
This commit is contained in:
parent
b24035f0a8
commit
bd5d3d2afc
|
@ -1,39 +1,48 @@
|
||||||
import { mapValues, groupBy, sumBy, sum, debounce, uniqBy } from 'lodash'
|
import {
|
||||||
|
mapValues,
|
||||||
|
groupBy,
|
||||||
|
sumBy,
|
||||||
|
sum,
|
||||||
|
sortBy,
|
||||||
|
debounce,
|
||||||
|
uniqBy,
|
||||||
|
} from 'lodash'
|
||||||
import { useState, useMemo } from 'react'
|
import { useState, useMemo } from 'react'
|
||||||
import { Charity as CharityType } from 'common/charity'
|
import { charities, Charity as CharityType } from 'common/charity'
|
||||||
import { CharityCard } from 'web/components/charity/charity-card'
|
import { CharityCard } from 'web/components/charity/charity-card'
|
||||||
import { Col } from 'web/components/layout/col'
|
import { Col } from 'web/components/layout/col'
|
||||||
import { Spacer } from 'web/components/layout/spacer'
|
import { Spacer } from 'web/components/layout/spacer'
|
||||||
import { Page } from 'web/components/page'
|
import { Page } from 'web/components/page'
|
||||||
import { Title } from 'web/components/title'
|
import { Title } from 'web/components/title'
|
||||||
|
import { getAllCharityTxns } from 'web/lib/firebase/txns'
|
||||||
import { manaToUSD } from 'common/util/format'
|
import { manaToUSD } from 'common/util/format'
|
||||||
import { quadraticMatches } from 'common/quadratic-funding'
|
import { quadraticMatches } from 'common/quadratic-funding'
|
||||||
import { DonationTxn, Txn } from 'common/txn'
|
import { Txn } from 'common/txn'
|
||||||
import { useTracking } from 'web/hooks/use-tracking'
|
import { useTracking } from 'web/hooks/use-tracking'
|
||||||
import { searchInAny } from 'common/util/parse'
|
import { searchInAny } from 'common/util/parse'
|
||||||
import { getUser } from 'web/lib/firebase/users'
|
|
||||||
import { SiteLink } from 'web/components/site-link'
|
import { SiteLink } from 'web/components/site-link'
|
||||||
import { User } from 'common/user'
|
|
||||||
import { SEO } from 'web/components/SEO'
|
import { SEO } from 'web/components/SEO'
|
||||||
|
|
||||||
export async function getStaticProps() {
|
export async function getStaticProps() {
|
||||||
const txns: DonationTxn[] = []
|
const txns = await getAllCharityTxns()
|
||||||
const totals = mapValues(groupBy(txns, 'toId'), (txns) =>
|
const totals = mapValues(groupBy(txns, 'toId'), (txns) =>
|
||||||
sumBy(txns, (txn) => txn.amount)
|
sumBy(txns, (txn) => txn.amount)
|
||||||
)
|
)
|
||||||
const totalRaised = sum(Object.values(totals))
|
const totalRaised = sum(Object.values(totals))
|
||||||
|
const sortedCharities = sortBy(charities, [
|
||||||
|
(charity) => (charity.tags?.includes('Featured') ? 0 : 1),
|
||||||
|
(charity) => -totals[charity.id],
|
||||||
|
])
|
||||||
const matches = quadraticMatches(txns, totalRaised)
|
const matches = quadraticMatches(txns, totalRaised)
|
||||||
const numDonors = uniqBy(txns, (txn) => txn.fromId).length
|
const numDonors = uniqBy(txns, (txn) => txn.fromId).length
|
||||||
const mostRecentDonor = await getUser(txns[txns.length - 1].fromId)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
totalRaised,
|
totalRaised,
|
||||||
charities: [],
|
charities: sortedCharities,
|
||||||
matches,
|
matches,
|
||||||
txns,
|
txns,
|
||||||
numDonors,
|
numDonors,
|
||||||
mostRecentDonor,
|
|
||||||
},
|
},
|
||||||
revalidate: 60,
|
revalidate: 60,
|
||||||
}
|
}
|
||||||
|
@ -77,9 +86,8 @@ export default function Charity(props: {
|
||||||
matches: { [charityId: string]: number }
|
matches: { [charityId: string]: number }
|
||||||
txns: Txn[]
|
txns: Txn[]
|
||||||
numDonors: number
|
numDonors: number
|
||||||
mostRecentDonor: User
|
|
||||||
}) {
|
}) {
|
||||||
const { totalRaised, charities, matches, numDonors, mostRecentDonor } = props
|
const { totalRaised, charities, matches, numDonors } = props
|
||||||
|
|
||||||
const [query, setQuery] = useState('')
|
const [query, setQuery] = useState('')
|
||||||
const debouncedQuery = debounce(setQuery, 50)
|
const debouncedQuery = debounce(setQuery, 50)
|
||||||
|
@ -136,8 +144,8 @@ export default function Charity(props: {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Most recent donor',
|
name: 'Most recent donor',
|
||||||
stat: mostRecentDonor.name ?? 'Nobody',
|
stat: 'Nobody',
|
||||||
url: `/${mostRecentDonor.username}`,
|
url: `/`,
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user