Working tree is now the canonical repo. Off-chain play-money + trustless on-chain (FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution, mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
107 lines
3.2 KiB
TypeScript
107 lines
3.2 KiB
TypeScript
import { useAPIGetter } from 'web/hooks/use-api-getter'
|
|
import { useUser } from 'web/hooks/use-user'
|
|
import { Page } from 'web/components/layout/page'
|
|
import { Col } from 'web/components/layout/col'
|
|
import { usePersistentInMemoryState } from 'client-common/hooks/use-persistent-in-memory-state'
|
|
import { useEffect, useState } from 'react'
|
|
import { LoadingIndicator } from 'web/components/widgets/loading-indicator'
|
|
import { VisibilityObserver } from 'web/components/widgets/visibility-observer'
|
|
import { uniqBy } from 'lodash'
|
|
import { ContractComment } from 'common/comment'
|
|
import { Contract } from 'common/contract'
|
|
import { LoadingCards } from 'web/components/contract/feed-contract-card'
|
|
import { GoodComment } from 'web/components/feed/good-comment'
|
|
|
|
const limit = 20
|
|
export default function CommentsPage() {
|
|
return (
|
|
<Page trackPageView={'comments page'}>
|
|
<Comments />
|
|
{/* <Tabs
|
|
className={'p-2'}
|
|
tabs={[
|
|
{
|
|
title: `GPT4-o's favorites`,
|
|
content: <Comments justLikes={false} key={'claude'} />,
|
|
},
|
|
{
|
|
title: `Oracle's favorites`,
|
|
content: <Comments justLikes={true} key={'likes'} />,
|
|
prerender: true,
|
|
},
|
|
]}
|
|
/> */}
|
|
</Page>
|
|
)
|
|
}
|
|
|
|
export const Comments = (props: { key?: string }) => {
|
|
const { key = 'comments' } = props
|
|
const [page, setPage] = usePersistentInMemoryState(0, `comments-offset`)
|
|
const [dataInMemory, setDataInMemory] = usePersistentInMemoryState(
|
|
{ comments: [] as ContractComment[], contracts: [] as Contract[] },
|
|
key
|
|
)
|
|
const { data } = useAPIGetter(
|
|
'get-best-comments',
|
|
{
|
|
offset: page,
|
|
limit,
|
|
ignoreContractIds: dataInMemory.contracts.map((c) => c.id),
|
|
},
|
|
['ignoreContractIds'],
|
|
key
|
|
)
|
|
const [loading, setLoading] = useState(true)
|
|
|
|
useEffect(() => {
|
|
setLoading(false)
|
|
const { comments, contracts } = data ?? {}
|
|
setDataInMemory({
|
|
comments: uniqBy([...dataInMemory.comments, ...(comments ?? [])], 'id'),
|
|
contracts: uniqBy(
|
|
[...dataInMemory.contracts, ...(contracts ?? [])],
|
|
'id'
|
|
),
|
|
})
|
|
}, [JSON.stringify(data?.comments.map((c) => c.id))])
|
|
const { comments, contracts } = dataInMemory
|
|
|
|
const user = useUser()
|
|
return (
|
|
<Col className={'gap-2 pt-1 sm:p-4'}>
|
|
{!comments.length && <LoadingCards />}
|
|
{comments.map((comment) => {
|
|
const contract = contracts.find(
|
|
(contract) => contract.id === comment.contractId
|
|
)
|
|
if (!contract) return null
|
|
|
|
return (
|
|
<GoodComment
|
|
key={comment.id}
|
|
contract={contract}
|
|
comment={comment}
|
|
trackingLocation={'comments page'}
|
|
user={user}
|
|
/>
|
|
)
|
|
})}
|
|
{comments.length > 0 && (
|
|
<div className="relative">
|
|
{loading && <LoadingIndicator />}
|
|
<VisibilityObserver
|
|
className="pointer-events-none absolute bottom-0 h-screen w-full select-none"
|
|
onVisibilityUpdated={(visible) => {
|
|
if (visible && !loading) {
|
|
setLoading(true)
|
|
setPage(page + 1)
|
|
}
|
|
}}
|
|
/>
|
|
</div>
|
|
)}
|
|
</Col>
|
|
)
|
|
}
|