import { ContractComment } from 'common/comment' import { groupConsecutive } from 'common/util/array' import { getUserCommentsQuery } from 'web/lib/firebase/comments' import { usePagination } from 'web/hooks/use-pagination' import { SiteLink } from './site-link' import { Row } from './layout/row' import { Avatar } from './avatar' import { RelativeTimestamp } from './relative-timestamp' import { User } from 'common/user' import { Col } from './layout/col' import { Content } from './editor' import { LoadingIndicator } from './loading-indicator' import { UserLink } from 'web/components/user-link' import { PaginationNextPrev } from 'web/components/pagination' type ContractKey = { contractId: string contractSlug: string contractQuestion: string } function contractPath(slug: string) { // by convention this includes the contract creator username, but we don't // have that handy, so we just put /market/ return `/market/${slug}` } export function UserCommentsList(props: { user: User }) { const { user } = props const page = usePagination({ q: getUserCommentsQuery(user.id), pageSize: 50 }) const { isStart, isEnd, getNext, getPrev, getItems, isLoading } = page const pageComments = groupConsecutive(getItems(), (c) => { return { contractId: c.contractId, contractQuestion: c.contractQuestion, contractSlug: c.contractSlug, } }) if (isLoading) { return } if (pageComments.length === 0) { if (isStart && isEnd) { return

This user hasn't made any comments yet.

} else { // this can happen if their comment count is a multiple of page size return

No more comments to display.

} } return ( {pageComments.map(({ key, items }, i) => { return })} ) } function ProfileCommentGroup(props: { groupKey: ContractKey items: ContractComment[] }) { const { groupKey, items } = props const { contractSlug, contractQuestion } = groupKey const path = contractPath(contractSlug) return (
{contractQuestion} {items.map((c) => ( ))}
) } function ProfileComment(props: { comment: ContractComment }) { const { comment } = props const { text, content, userUsername, userName, userAvatarUrl, createdTime } = comment // TODO: find and attach relevant bets by comment betId at some point return (

{' '}

) }