2022-03-31 06:24:35 +00:00
|
|
|
import React from 'react'
|
2022-01-23 00:16:23 +00:00
|
|
|
import Router from 'next/router'
|
2022-02-27 21:37:04 +00:00
|
|
|
import _ from 'lodash'
|
2022-01-23 00:16:23 +00:00
|
|
|
|
|
|
|
import { Page } from '../components/page'
|
2022-04-04 05:27:25 +00:00
|
|
|
import { ActivityFeed } from '../components/feed/activity-feed'
|
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 23:12:09 +00:00
|
|
|
import { LoadingIndicator } from '../components/loading-indicator'
|
2022-04-09 23:10:58 +00:00
|
|
|
import { useRecentBets } from '../hooks/use-bets'
|
2022-02-27 21:37:04 +00:00
|
|
|
import { useActiveContracts } from '../hooks/use-contracts'
|
2022-03-05 00:06:11 +00:00
|
|
|
import { useRecentComments } from '../hooks/use-comments'
|
2022-04-09 23:10:58 +00:00
|
|
|
import { useAlgoFeed } from '../hooks/use-algo-feed'
|
2022-01-23 00:16:23 +00:00
|
|
|
|
2022-04-09 23:10:58 +00:00
|
|
|
const Home = () => {
|
2022-01-23 00:16:23 +00:00
|
|
|
const user = useUser()
|
|
|
|
|
2022-04-09 23:10:58 +00:00
|
|
|
const contracts = useActiveContracts()
|
|
|
|
const contractsDict = _.keyBy(contracts, 'id')
|
2022-02-27 21:37:04 +00:00
|
|
|
|
2022-04-09 23:10:58 +00:00
|
|
|
const recentBets = useRecentBets()
|
|
|
|
const recentComments = useRecentComments()
|
2022-03-05 00:06:11 +00:00
|
|
|
|
2022-04-09 23:10:58 +00:00
|
|
|
const feedContracts = useAlgoFeed(user, contracts, recentBets, recentComments)
|
|
|
|
|
|
|
|
const updatedContracts = feedContracts.map(
|
|
|
|
(contract) => contractsDict[contract.id] ?? contract
|
|
|
|
)
|
2022-02-25 07:59:53 +00:00
|
|
|
|
2022-01-23 00:16:23 +00:00
|
|
|
if (user === null) {
|
|
|
|
Router.replace('/')
|
|
|
|
return <></>
|
|
|
|
}
|
|
|
|
|
2022-04-09 23:10:58 +00:00
|
|
|
const activityContent =
|
|
|
|
contracts && recentBets && recentComments ? (
|
|
|
|
<ActivityFeed
|
|
|
|
contracts={updatedContracts}
|
|
|
|
recentBets={recentBets}
|
|
|
|
recentComments={recentComments}
|
|
|
|
mode="only-recent"
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<LoadingIndicator className="mt-4" />
|
|
|
|
)
|
2022-03-31 06:24:35 +00:00
|
|
|
|
2022-01-23 00:16:23 +00:00
|
|
|
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-03-05 00:06:11 +00:00
|
|
|
<Col className="w-full max-w-[700px]">
|
2022-01-27 22:37:43 +00:00
|
|
|
<FeedCreate user={user ?? undefined} />
|
2022-04-09 23:10:58 +00:00
|
|
|
<Spacer h={10} />
|
2022-04-04 05:27:25 +00:00
|
|
|
{activityContent}
|
2022-01-23 00:16:23 +00:00
|
|
|
</Col>
|
|
|
|
</Col>
|
|
|
|
</Page>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Home
|