2022-04-19 07:40:12 +00:00
|
|
|
import _ from 'lodash'
|
|
|
|
import { useState, useMemo } from 'react'
|
2022-04-25 20:31:04 +00:00
|
|
|
import { charities as charityList } from '../../../common/charity'
|
2022-04-25 20:51:01 +00:00
|
|
|
import { CharityCard } from '../../components/charity/charity-card'
|
2022-04-19 07:40:12 +00:00
|
|
|
import { Col } from '../../components/layout/col'
|
|
|
|
import { Page } from '../../components/page'
|
|
|
|
import { Title } from '../../components/title'
|
|
|
|
|
2022-04-25 20:31:04 +00:00
|
|
|
// TODO: Fetch amount raised.
|
|
|
|
const charities = charityList.map((charity) => ({
|
|
|
|
...charity,
|
2022-04-19 07:40:12 +00:00
|
|
|
raised: 4001,
|
|
|
|
}))
|
|
|
|
|
|
|
|
export default function Charity() {
|
|
|
|
const [query, setQuery] = useState('')
|
|
|
|
const debouncedQuery = _.debounce(setQuery, 50)
|
|
|
|
|
|
|
|
const filterCharities = useMemo(
|
|
|
|
() => charities.filter((charity) => charity.name.includes(query)),
|
|
|
|
[query]
|
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Page>
|
2022-04-25 20:06:07 +00:00
|
|
|
<Col className="w-full rounded bg-white px-4 py-6 sm:px-8">
|
2022-04-19 07:40:12 +00:00
|
|
|
<Col className="max-w-xl">
|
2022-04-25 20:06:07 +00:00
|
|
|
<Title className="!mt-0" text="Donate to a charity" />
|
2022-04-19 07:40:12 +00:00
|
|
|
<div className="mb-6 text-gray-500">
|
2022-04-25 20:06:07 +00:00
|
|
|
Exchange your M$ for real dollars in the form of charity donations!
|
2022-04-19 07:40:12 +00:00
|
|
|
</div>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
onChange={(e) => debouncedQuery(e.target.value)}
|
|
|
|
placeholder="Search charities"
|
2022-04-25 20:06:07 +00:00
|
|
|
className="input input-bordered mb-6 w-full"
|
2022-04-19 07:40:12 +00:00
|
|
|
/>
|
|
|
|
</Col>
|
|
|
|
<div className="grid max-w-xl grid-flow-row grid-cols-1 gap-3 lg:max-w-full lg:grid-cols-2 xl:grid-cols-3">
|
|
|
|
{filterCharities.map((charity) => (
|
|
|
|
<div key={charity.name}>
|
2022-04-25 20:51:01 +00:00
|
|
|
<CharityCard charity={charity} />
|
2022-04-19 07:40:12 +00:00
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
{filterCharities.length === 0 && (
|
|
|
|
<div className="text-center text-gray-500">
|
|
|
|
No charities match your search :(
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</Col>
|
|
|
|
</Page>
|
|
|
|
)
|
|
|
|
}
|