2022-02-27 21:37:04 +00:00
|
|
|
import React, { useState } from 'react'
|
2022-01-23 00:16:23 +00:00
|
|
|
import Router from 'next/router'
|
2022-02-27 21:37:04 +00:00
|
|
|
import { SparklesIcon, GlobeAltIcon } from '@heroicons/react/solid'
|
|
|
|
import clsx from 'clsx'
|
|
|
|
import _ from 'lodash'
|
2022-01-23 00:16:23 +00:00
|
|
|
|
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-03-05 00:06:11 +00:00
|
|
|
import { ActivityFeed, SummaryActivityFeed } from '../components/activity-feed'
|
2022-02-20 00:02:40 +00:00
|
|
|
import { Comment } from '../lib/firebase/comments'
|
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'
|
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-27 21:37:04 +00:00
|
|
|
useExploreContracts,
|
|
|
|
useFilterYourContracts,
|
2022-02-25 08:11:10 +00:00
|
|
|
useFindActiveContracts,
|
2022-02-27 21:37:04 +00:00
|
|
|
} from '../hooks/use-find-active-contracts'
|
2022-03-09 02:43:30 +00:00
|
|
|
import { fromPropz, usePropz } from '../hooks/use-propz'
|
2022-03-05 00:06:11 +00:00
|
|
|
import { useGetRecentBets, 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-03-09 02:43:30 +00:00
|
|
|
import { IS_PRIVATE_MANIFOLD } from '../../common/envs/constants'
|
2022-01-23 00:16:23 +00:00
|
|
|
|
2022-03-09 02:43:30 +00:00
|
|
|
export const getStaticProps = fromPropz(getStaticPropz)
|
|
|
|
export async function getStaticPropz() {
|
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
|
|
|
recentComments: Comment[]
|
2022-02-05 02:09:34 +00:00
|
|
|
}) => {
|
2022-03-09 02:43:30 +00:00
|
|
|
props = usePropz(props, getStaticPropz) ?? {
|
|
|
|
contracts: [],
|
|
|
|
folds: [],
|
|
|
|
recentComments: [],
|
|
|
|
}
|
2022-03-05 00:06:11 +00:00
|
|
|
const { folds } = props
|
2022-01-23 00:16:23 +00:00
|
|
|
const user = useUser()
|
|
|
|
|
2022-02-27 21:37:04 +00:00
|
|
|
const contracts = useActiveContracts() ?? props.contracts
|
|
|
|
const { yourContracts, initialFollowedFoldSlugs } = useFilterYourContracts(
|
|
|
|
user,
|
|
|
|
folds,
|
|
|
|
contracts
|
|
|
|
)
|
|
|
|
|
2022-03-05 00:06:11 +00:00
|
|
|
const initialRecentBets = useGetRecentBets()
|
|
|
|
const recentBets = useRecentBets() ?? initialRecentBets
|
|
|
|
const recentComments = useRecentComments() ?? props.recentComments
|
|
|
|
|
|
|
|
const { activeContracts } = useFindActiveContracts({
|
|
|
|
contracts: yourContracts,
|
|
|
|
recentBets: initialRecentBets ?? [],
|
|
|
|
recentComments: props.recentComments,
|
|
|
|
})
|
2022-02-25 07:59:53 +00:00
|
|
|
|
2022-02-27 21:37:04 +00:00
|
|
|
const exploreContracts = useExploreContracts()
|
|
|
|
|
|
|
|
const [feedMode, setFeedMode] = useState<'activity' | 'explore'>('activity')
|
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-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-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 &&
|
2022-03-09 02:43:30 +00:00
|
|
|
initialFollowedFoldSlugs.length === 0 &&
|
|
|
|
!IS_PRIVATE_MANIFOLD && (
|
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-27 21:37:04 +00:00
|
|
|
<Spacer h={5} />
|
|
|
|
|
2022-03-03 09:07:21 +00:00
|
|
|
<Col className="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-27 21:37:04 +00:00
|
|
|
<div className="tabs">
|
|
|
|
<div
|
|
|
|
className={clsx(
|
2022-02-28 23:21:49 +00:00
|
|
|
'tab gap-2',
|
2022-02-27 21:37:04 +00:00
|
|
|
feedMode === 'activity' && 'tab-active'
|
|
|
|
)}
|
|
|
|
onClick={() => setFeedMode('activity')}
|
|
|
|
>
|
|
|
|
<SparklesIcon className="inline h-5 w-5" aria-hidden="true" />
|
|
|
|
Recent activity
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
className={clsx(
|
2022-02-28 23:21:49 +00:00
|
|
|
'tab gap-2',
|
2022-02-27 21:37:04 +00:00
|
|
|
feedMode === 'explore' && 'tab-active'
|
|
|
|
)}
|
|
|
|
onClick={() => setFeedMode('explore')}
|
|
|
|
>
|
|
|
|
<GlobeAltIcon className="inline h-5 w-5" aria-hidden="true" />
|
|
|
|
Explore
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-02-08 04:06:58 +00:00
|
|
|
</Row>
|
|
|
|
</Col>
|
2022-02-07 00:03:36 +00:00
|
|
|
|
2022-02-27 21:37:04 +00:00
|
|
|
{feedMode === 'activity' &&
|
|
|
|
(recentBets ? (
|
|
|
|
<ActivityFeed
|
|
|
|
contracts={activeContracts}
|
2022-03-05 00:06:11 +00:00
|
|
|
recentBets={recentBets}
|
|
|
|
recentComments={recentComments}
|
2022-02-27 21:37:04 +00:00
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<LoadingIndicator className="mt-4" />
|
|
|
|
))}
|
|
|
|
|
|
|
|
{feedMode === 'explore' &&
|
|
|
|
(exploreContracts ? (
|
|
|
|
<SummaryActivityFeed contracts={exploreContracts} />
|
|
|
|
) : (
|
|
|
|
<LoadingIndicator className="mt-4" />
|
|
|
|
))}
|
2022-01-23 00:16:23 +00:00
|
|
|
</Col>
|
|
|
|
</Col>
|
|
|
|
</Page>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Home
|