2022-02-05 02:09:34 +00:00
|
|
|
import React from 'react'
|
2022-01-23 00:16:23 +00:00
|
|
|
import Router from 'next/router'
|
|
|
|
|
2022-02-20 00:02:40 +00:00
|
|
|
import { Contract } from '../lib/firebase/contracts'
|
2022-01-23 00:16:23 +00:00
|
|
|
import { Page } from '../components/page'
|
2022-02-20 00:02:40 +00:00
|
|
|
import { ActivityFeed } from './activity'
|
|
|
|
import { Comment } from '../lib/firebase/comments'
|
|
|
|
import { Bet } from '../lib/firebase/bets'
|
2022-01-23 00:16:23 +00:00
|
|
|
import FeedCreate from '../components/feed-create'
|
|
|
|
import { Spacer } from '../components/layout/spacer'
|
|
|
|
import { Col } from '../components/layout/col'
|
|
|
|
import { useUser } from '../hooks/use-user'
|
2022-02-03 22:54:08 +00:00
|
|
|
import { Fold } from '../../common/fold'
|
2022-02-03 23:12:09 +00:00
|
|
|
import { LoadingIndicator } from '../components/loading-indicator'
|
2022-02-04 18:30:13 +00:00
|
|
|
import { Row } from '../components/layout/row'
|
|
|
|
import { SparklesIcon } from '@heroicons/react/solid'
|
2022-02-19 23:17:36 +00:00
|
|
|
import { FastFoldFollowing } from '../components/fast-fold-following'
|
2022-02-20 00:02:40 +00:00
|
|
|
import {
|
|
|
|
getAllContractInfo,
|
2022-02-25 08:11:10 +00:00
|
|
|
useFindActiveContracts,
|
2022-02-20 00:02:40 +00:00
|
|
|
} from '../hooks/use-active-contracts'
|
2022-02-25 07:59:53 +00:00
|
|
|
import { useGetRecentBets } from '../hooks/use-bets'
|
2022-01-23 00:16:23 +00:00
|
|
|
|
|
|
|
export async function getStaticProps() {
|
2022-02-20 00:02:40 +00:00
|
|
|
const contractInfo = await getAllContractInfo()
|
2022-02-05 02:09:34 +00:00
|
|
|
|
2022-01-23 00:16:23 +00:00
|
|
|
return {
|
2022-02-20 00:02:40 +00:00
|
|
|
props: contractInfo,
|
2022-01-23 00:16:23 +00:00
|
|
|
revalidate: 60, // regenerate after a minute
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-05 02:09:34 +00:00
|
|
|
const Home = (props: {
|
|
|
|
contracts: Contract[]
|
|
|
|
folds: Fold[]
|
2022-02-18 18:43:13 +00:00
|
|
|
recentBets: Bet[]
|
|
|
|
recentComments: Comment[]
|
2022-02-05 02:09:34 +00:00
|
|
|
}) => {
|
2022-02-25 07:59:53 +00:00
|
|
|
const { contracts, folds, recentComments } = props
|
2022-01-23 00:16:23 +00:00
|
|
|
const user = useUser()
|
|
|
|
|
2022-02-25 07:59:53 +00:00
|
|
|
const recentBets = useGetRecentBets()
|
|
|
|
|
2022-02-21 05:12:35 +00:00
|
|
|
const {
|
|
|
|
activeContracts,
|
|
|
|
activeBets,
|
|
|
|
activeComments,
|
|
|
|
initialFollowedFoldSlugs,
|
2022-02-25 08:11:10 +00:00
|
|
|
} = useFindActiveContracts(
|
2022-02-25 07:59:53 +00:00
|
|
|
{ contracts, folds, recentBets: recentBets ?? [], recentComments },
|
|
|
|
user
|
|
|
|
)
|
2022-02-03 22:54:08 +00:00
|
|
|
|
2022-01-23 00:16:23 +00:00
|
|
|
if (user === null) {
|
|
|
|
Router.replace('/')
|
|
|
|
return <></>
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2022-01-27 23:06:31 +00:00
|
|
|
<Page assertUser="signed-in">
|
2022-01-23 00:16:23 +00:00
|
|
|
<Col className="items-center">
|
2022-02-11 18:40:22 +00:00
|
|
|
<Col className="w-full max-w-3xl">
|
2022-01-27 22:37:43 +00:00
|
|
|
<FeedCreate user={user ?? undefined} />
|
2022-02-03 23:40:37 +00:00
|
|
|
<Spacer h={6} />
|
2022-02-19 23:17:36 +00:00
|
|
|
|
2022-02-21 05:12:35 +00:00
|
|
|
{initialFollowedFoldSlugs !== undefined &&
|
|
|
|
initialFollowedFoldSlugs.length === 0 && (
|
2022-02-20 00:02:40 +00:00
|
|
|
<FastFoldFollowing
|
|
|
|
user={user}
|
2022-02-21 05:12:35 +00:00
|
|
|
followedFoldSlugs={initialFollowedFoldSlugs}
|
2022-02-20 00:02:40 +00:00
|
|
|
/>
|
|
|
|
)}
|
2022-02-19 23:17:36 +00:00
|
|
|
|
2022-02-11 18:40:22 +00:00
|
|
|
<Col className="mx-3 mb-3 gap-2 text-sm text-gray-800 sm:flex-row">
|
2022-02-08 04:06:58 +00:00
|
|
|
<Row className="gap-2">
|
2022-02-11 18:40:22 +00:00
|
|
|
<SparklesIcon className="inline h-5 w-5" aria-hidden="true" />
|
2022-02-08 04:06:58 +00:00
|
|
|
<span className="whitespace-nowrap">Recent activity</span>
|
|
|
|
</Row>
|
|
|
|
</Col>
|
2022-02-07 00:03:36 +00:00
|
|
|
|
2022-02-25 07:59:53 +00:00
|
|
|
{activeContracts && recentBets ? (
|
2022-02-03 22:54:08 +00:00
|
|
|
<ActivityFeed
|
|
|
|
contracts={activeContracts}
|
2022-02-05 02:09:34 +00:00
|
|
|
contractBets={activeBets}
|
|
|
|
contractComments={activeComments}
|
2022-02-03 22:54:08 +00:00
|
|
|
/>
|
2022-02-03 23:12:09 +00:00
|
|
|
) : (
|
|
|
|
<LoadingIndicator className="mt-4" />
|
|
|
|
)}
|
2022-01-23 00:16:23 +00:00
|
|
|
</Col>
|
|
|
|
</Col>
|
|
|
|
</Page>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Home
|