2022-01-21 23:21:46 +00:00
|
|
|
import _ from 'lodash'
|
2022-01-26 18:44:16 +00:00
|
|
|
import Link from 'next/link'
|
2022-01-24 05:47:20 +00:00
|
|
|
import { useEffect, useState } from 'react'
|
2022-01-21 23:21:46 +00:00
|
|
|
import { Fold } from '../../common/fold'
|
2022-01-25 23:02:02 +00:00
|
|
|
import { CreateFoldButton } from '../components/create-fold-button'
|
2022-01-26 20:03:32 +00:00
|
|
|
import { FollowFoldButton } from '../components/follow-fold-button'
|
2022-01-21 23:21:46 +00:00
|
|
|
import { Col } from '../components/layout/col'
|
|
|
|
import { Row } from '../components/layout/row'
|
|
|
|
import { Page } from '../components/page'
|
|
|
|
import { SiteLink } from '../components/site-link'
|
|
|
|
import { Title } from '../components/title'
|
|
|
|
import { UserLink } from '../components/user-page'
|
2022-01-24 05:47:20 +00:00
|
|
|
import { useFolds } from '../hooks/use-fold'
|
2022-01-21 23:21:46 +00:00
|
|
|
import { useUser } from '../hooks/use-user'
|
|
|
|
import { foldPath, listAllFolds } from '../lib/firebase/folds'
|
|
|
|
import { getUser, User } from '../lib/firebase/users'
|
|
|
|
|
|
|
|
export async function getStaticProps() {
|
|
|
|
const folds = await listAllFolds().catch((_) => [])
|
|
|
|
|
|
|
|
const curators = await Promise.all(
|
|
|
|
folds.map((fold) => getUser(fold.curatorId))
|
|
|
|
)
|
2022-01-24 05:47:20 +00:00
|
|
|
const curatorsDict = _.fromPairs(
|
|
|
|
curators.map((curator) => [curator.id, curator])
|
|
|
|
)
|
2022-01-21 23:21:46 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
folds,
|
2022-01-24 05:47:20 +00:00
|
|
|
curatorsDict,
|
2022-01-21 23:21:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
revalidate: 60, // regenerate after a minute
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-24 05:47:20 +00:00
|
|
|
export default function Folds(props: {
|
|
|
|
folds: Fold[]
|
|
|
|
curatorsDict: _.Dictionary<User>
|
|
|
|
}) {
|
|
|
|
const [curatorsDict, setCuratorsDict] = useState(props.curatorsDict)
|
2022-01-21 23:21:46 +00:00
|
|
|
|
2022-01-26 20:27:13 +00:00
|
|
|
let folds = useFolds() ?? props.folds
|
|
|
|
folds = _.sortBy(folds, (fold) => -1 * fold.followCount)
|
2022-01-21 23:21:46 +00:00
|
|
|
const user = useUser()
|
|
|
|
|
2022-01-24 05:47:20 +00:00
|
|
|
useEffect(() => {
|
|
|
|
// Load User object for curator of new Folds.
|
|
|
|
const newFolds = folds.filter(({ curatorId }) => !curatorsDict[curatorId])
|
|
|
|
if (newFolds.length > 0) {
|
|
|
|
Promise.all(newFolds.map(({ curatorId }) => getUser(curatorId))).then(
|
|
|
|
(newUsers) => {
|
|
|
|
const newUsersDict = _.fromPairs(
|
|
|
|
newUsers.map((user) => [user.id, user])
|
|
|
|
)
|
|
|
|
setCuratorsDict({ ...curatorsDict, ...newUsersDict })
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-01-21 23:21:46 +00:00
|
|
|
return (
|
|
|
|
<Page>
|
|
|
|
<Col className="items-center">
|
2022-01-26 18:44:16 +00:00
|
|
|
<Col className="max-w-lg w-full px-2 sm:px-0">
|
2022-01-21 23:21:46 +00:00
|
|
|
<Row className="justify-between items-center">
|
2022-01-27 07:10:28 +00:00
|
|
|
<Title text="Explore folds" />
|
2022-01-21 23:21:46 +00:00
|
|
|
{user && <CreateFoldButton />}
|
|
|
|
</Row>
|
|
|
|
|
2022-01-24 22:58:51 +00:00
|
|
|
<div className="text-gray-500 mb-6">
|
2022-01-27 07:10:28 +00:00
|
|
|
Folds are communities on Manifold centered around a collection of
|
|
|
|
markets.
|
2022-01-24 22:58:51 +00:00
|
|
|
</div>
|
|
|
|
|
2022-01-26 18:44:16 +00:00
|
|
|
<Col className="gap-2">
|
2022-01-24 05:47:20 +00:00
|
|
|
{folds.map((fold) => (
|
2022-01-26 20:27:13 +00:00
|
|
|
<FoldCard
|
2022-01-26 18:44:16 +00:00
|
|
|
key={fold.id}
|
2022-01-26 20:27:13 +00:00
|
|
|
fold={fold}
|
|
|
|
curator={curatorsDict[fold.curatorId]}
|
|
|
|
/>
|
2022-01-21 23:21:46 +00:00
|
|
|
))}
|
|
|
|
</Col>
|
|
|
|
</Col>
|
|
|
|
</Col>
|
|
|
|
</Page>
|
|
|
|
)
|
|
|
|
}
|
2022-01-26 20:27:13 +00:00
|
|
|
|
|
|
|
function FoldCard(props: { fold: Fold; curator: User | undefined }) {
|
|
|
|
const { fold, curator } = props
|
|
|
|
return (
|
|
|
|
<Col
|
|
|
|
key={fold.id}
|
2022-01-27 06:38:22 +00:00
|
|
|
className="bg-white hover:bg-gray-100 p-4 rounded-xl gap-1 shadow-md relative"
|
2022-01-26 20:27:13 +00:00
|
|
|
>
|
|
|
|
<Link href={foldPath(fold)}>
|
|
|
|
<a className="absolute left-0 right-0 top-0 bottom-0" />
|
|
|
|
</Link>
|
|
|
|
<Row className="justify-between items-center gap-2">
|
|
|
|
<SiteLink href={foldPath(fold)}>{fold.name}</SiteLink>
|
|
|
|
<FollowFoldButton className="z-10 mb-1" fold={fold} />
|
|
|
|
</Row>
|
|
|
|
<Row className="items-center gap-2 text-gray-500 text-sm">
|
|
|
|
<div>{fold.followCount} followers</div>
|
|
|
|
<div>•</div>
|
|
|
|
<Row>
|
|
|
|
<div className="mr-1">Curated by</div>
|
|
|
|
<UserLink
|
|
|
|
className="text-neutral"
|
|
|
|
name={curator?.name ?? ''}
|
|
|
|
username={curator?.username ?? ''}
|
|
|
|
/>
|
|
|
|
</Row>
|
|
|
|
</Row>
|
|
|
|
<div className="text-gray-500 text-sm">{fold.about}</div>
|
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
}
|