From 61c13d171aa39fbca104d919d5c14e2abfc60dba Mon Sep 17 00:00:00 2001 From: Marshall Polaris Date: Mon, 15 Aug 2022 01:26:12 -0700 Subject: [PATCH] Update user profile UI to use new denormalized fields --- web/components/comments-list.tsx | 41 +++++++++++++------------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/web/components/comments-list.tsx b/web/components/comments-list.tsx index 90542d4b..aa23a48b 100644 --- a/web/components/comments-list.tsx +++ b/web/components/comments-list.tsx @@ -1,12 +1,8 @@ import { useEffect, useState } from 'react' -import { Dictionary, keyBy, uniq } from 'lodash' import { Comment } from 'common/comment' -import { Contract } from 'common/contract' -import { filterDefined, groupConsecutive } from 'common/util/array' -import { contractPath } from 'web/lib/firebase/contracts' +import { groupConsecutive } from 'common/util/array' import { getUsersComments } from 'web/lib/firebase/comments' -import { getContractFromId } from 'web/lib/firebase/contracts' import { SiteLink } from './site-link' import { Row } from './layout/row' import { Avatar } from './avatar' @@ -20,12 +16,20 @@ import { LoadingIndicator } from './loading-indicator' const COMMENTS_PER_PAGE = 50 -type ContractComment = Comment & { contractId: string } +type ContractComment = Comment & { + contractId: string + contractSlug: string + contractQuestion: string +} + +function contractPath(slug: string) { + // in honor of austin, who insists that contract URLs are prefixed with a username + return `/Austin/${slug}` +} export function UserCommentsList(props: { user: User }) { const { user } = props const [comments, setComments] = useState() - const [contracts, setContracts] = useState | undefined>() const [page, setPage] = useState(0) const start = page * COMMENTS_PER_PAGE const end = start + COMMENTS_PER_PAGE @@ -37,34 +41,23 @@ export function UserCommentsList(props: { user: User }) { }) }, [user.id]) - useEffect(() => { - if (comments) { - const contractIds = uniq(comments.map((c) => c.contractId)) - Promise.all(contractIds.map(getContractFromId)).then((contracts) => { - setContracts(keyBy(filterDefined(contracts), 'id')) - }) - } - }, [comments]) - - if (comments == null || contracts == null) { + if (comments == null) { return } - const pageComments = groupConsecutive( - comments.slice(start, end), - (c) => c.contractId - ) + const pageComments = groupConsecutive(comments.slice(start, end), (c) => { + return { question: c.contractQuestion, slug: c.contractSlug } + }) return ( {pageComments.map(({ key, items }, i) => { - const contract = contracts[key] return (
- {contract.question} + {key.question} {items.map((comment) => (