Add comments and back nav

This commit is contained in:
James Grugett 2022-09-27 18:17:01 -04:00
parent cf36719951
commit 9826253230
3 changed files with 38 additions and 26 deletions

View File

@ -1,5 +1,5 @@
import { getDateDoc } from 'web/lib/firebase/posts' import { getDateDoc } from 'web/lib/firebase/posts'
import { LinkIcon } from '@heroicons/react/outline' import { ArrowLeftIcon, LinkIcon } from '@heroicons/react/outline'
import { Page } from 'web/components/page' import { Page } from 'web/components/page'
import dayjs from 'dayjs' import dayjs from 'dayjs'
@ -18,19 +18,21 @@ import { track } from '@amplitude/analytics-browser'
import toast from 'react-hot-toast' import toast from 'react-hot-toast'
import { copyToClipboard } from 'web/lib/util/copy' import { copyToClipboard } from 'web/lib/util/copy'
import { useUser } from 'web/hooks/use-user' import { useUser } from 'web/hooks/use-user'
import { RichEditPost } from '../post/[...slugs]' import { PostCommentsActivity, RichEditPost } from '../post/[...slugs]'
import { usePost } from 'web/hooks/use-post' import { usePost } from 'web/hooks/use-post'
import { useTipTxns } from 'web/hooks/use-tip-txns'
import { useCommentsOnPost } from 'web/hooks/use-comments'
export async function getStaticProps(props: { params: { username: string } }) { export async function getStaticProps(props: { params: { username: string } }) {
const { username } = props.params const { username } = props.params
const { user, post } = (await getDateDoc(username)) ?? { const { user: creator, post } = (await getDateDoc(username)) ?? {
user: null, creator: null,
post: null, post: null,
} }
return { return {
props: { props: {
user, creator,
post, post,
}, },
revalidate: 5, // regenerate after five seconds revalidate: 5, // regenerate after five seconds
@ -41,19 +43,38 @@ export async function getStaticPaths() {
return { paths: [], fallback: 'blocking' } return { paths: [], fallback: 'blocking' }
} }
export default function DateDocPage(props: { export default function DateDocPageHelper(props: {
user: User | null creator: User | null
post: DateDoc | null post: DateDoc | null
}) { }) {
const { user, post } = props const { creator, post } = props
if (!user || !post) return <Custom404 /> if (!creator || !post) return <Custom404 />
return <DateDocPage creator={creator} post={post} />
}
function DateDocPage(props: { creator: User; post: DateDoc }) {
const { creator, post } = props
const tips = useTipTxns({ postId: post.id })
const comments = useCommentsOnPost(post.id) ?? []
return ( return (
<Page> <Page>
<div className="mx-auto w-full max-w-xl"> <Col className="mx-auto w-full max-w-xl gap-6 sm:mb-6">
<DateDocPost dateDoc={post} creator={user} /> <SiteLink href="/date-docs">
</div> <Row className="items-center gap-2">
<ArrowLeftIcon className="h-5 w-5" aria-hidden="true" />
<div>Date docs</div>
</Row>
</SiteLink>
<DateDocPost dateDoc={post} creator={creator} />
<Col className="gap-4 rounded-lg bg-white px-6 py-4">
<div className="">Add your endorsement of {creator.name}!</div>
<PostCommentsActivity post={post} comments={comments} tips={tips} />
</Col>
</Col>
</Page> </Page>
) )
} }

View File

@ -34,9 +34,9 @@ export async function getStaticProps(props: { params: { slugs: string[] } }) {
return { return {
props: { props: {
post: post, post,
creator: creator, creator,
comments: comments, comments,
}, },
revalidate: 60, // regenerate after a minute revalidate: 60, // regenerate after a minute
@ -117,12 +117,7 @@ export default function PostPage(props: {
<Spacer h={4} /> <Spacer h={4} />
<div className="rounded-lg bg-white px-6 py-4 sm:py-0"> <div className="rounded-lg bg-white px-6 py-4 sm:py-0">
<PostCommentsActivity <PostCommentsActivity post={post} comments={comments} tips={tips} />
post={post}
comments={comments}
tips={tips}
user={creator}
/>
</div> </div>
</div> </div>
</Page> </Page>
@ -133,9 +128,8 @@ export function PostCommentsActivity(props: {
post: Post post: Post
comments: PostComment[] comments: PostComment[]
tips: CommentTipMap tips: CommentTipMap
user: User | null | undefined
}) { }) {
const { post, comments, user, tips } = props const { post, comments, tips } = props
const commentsByUserId = groupBy(comments, (c) => c.userId) const commentsByUserId = groupBy(comments, (c) => c.userId)
const commentsByParentId = groupBy(comments, (c) => c.replyToCommentId ?? '_') const commentsByParentId = groupBy(comments, (c) => c.replyToCommentId ?? '_')
const topLevelComments = sortBy( const topLevelComments = sortBy(
@ -149,7 +143,6 @@ export function PostCommentsActivity(props: {
{topLevelComments.map((parent) => ( {topLevelComments.map((parent) => (
<PostCommentThread <PostCommentThread
key={parent.id} key={parent.id}
user={user}
post={post} post={post}
parentComment={parent} parentComment={parent}
threadComments={sortBy( threadComments={sortBy(

View File

@ -3,7 +3,6 @@ import { Editor } from '@tiptap/core'
import clsx from 'clsx' import clsx from 'clsx'
import { PostComment } from 'common/comment' import { PostComment } from 'common/comment'
import { Post } from 'common/post' import { Post } from 'common/post'
import { User } from 'common/user'
import { Dictionary } from 'lodash' import { Dictionary } from 'lodash'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
@ -21,7 +20,6 @@ import { createCommentOnPost } from 'web/lib/firebase/comments'
import { firebaseLogin } from 'web/lib/firebase/users' import { firebaseLogin } from 'web/lib/firebase/users'
export function PostCommentThread(props: { export function PostCommentThread(props: {
user: User | null | undefined
post: Post post: Post
threadComments: PostComment[] threadComments: PostComment[]
tips: CommentTipMap tips: CommentTipMap