manifold/web/pages/home.tsx

90 lines
2.4 KiB
TypeScript
Raw Normal View History

import React from 'react'
2022-01-23 00:16:23 +00:00
import Router from 'next/router'
import { Contract } from '../lib/firebase/contracts'
2022-01-23 00:16:23 +00:00
import { Page } from '../components/page'
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'
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'
import { FastFoldFollowing } from '../components/fast-fold-following'
import {
getAllContractInfo,
useActiveContracts,
} from '../hooks/use-active-contracts'
2022-01-23 00:16:23 +00:00
export async function getStaticProps() {
const contractInfo = await getAllContractInfo()
2022-01-23 00:16:23 +00:00
return {
props: contractInfo,
2022-01-23 00:16:23 +00:00
revalidate: 60, // regenerate after a minute
}
}
const Home = (props: {
contracts: Contract[]
folds: Fold[]
recentBets: Bet[]
recentComments: Comment[]
}) => {
2022-01-23 00:16:23 +00:00
const user = useUser()
const {
activeContracts,
activeBets,
activeComments,
initialFollowedFoldSlugs,
} = useActiveContracts(props, user)
2022-01-23 00:16:23 +00:00
if (user === null) {
Router.replace('/')
return <></>
}
return (
<Page assertUser="signed-in">
2022-01-23 00:16:23 +00:00
<Col className="items-center">
<Col className="w-full max-w-3xl">
<FeedCreate user={user ?? undefined} />
2022-02-03 23:40:37 +00:00
<Spacer h={6} />
{initialFollowedFoldSlugs !== undefined &&
initialFollowedFoldSlugs.length === 0 && (
<FastFoldFollowing
user={user}
followedFoldSlugs={initialFollowedFoldSlugs}
/>
)}
<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">
<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>
{activeContracts ? (
<ActivityFeed
contracts={activeContracts}
contractBets={activeBets}
contractComments={activeComments}
/>
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