From 187c32def95ffc9ce011975f2147e030dca3ab94 Mon Sep 17 00:00:00 2001 From: Pico2x Date: Wed, 7 Sep 2022 22:58:36 +0100 Subject: [PATCH] Fix nits --- common/comment.ts | 6 +++--- web/lib/firebase/comments.ts | 28 ++++++++++++++++++---------- web/pages/post/[...slugs]/index.tsx | 21 +++++++++++---------- web/posts/post-comments.tsx | 1 - 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/common/comment.ts b/common/comment.ts index 700a85db..7ecbb6d4 100644 --- a/common/comment.ts +++ b/common/comment.ts @@ -20,7 +20,7 @@ export type Comment = { userAvatarUrl?: string } & T -type OnContract = { +export type OnContract = { commentType: 'contract' contractId: string answerOutcome?: string @@ -35,12 +35,12 @@ type OnContract = { betOutcome?: string } -type OnGroup = { +export type OnGroup = { commentType: 'group' groupId: string } -type OnPost = { +export type OnPost = { commentType: 'post' postId: string } diff --git a/web/lib/firebase/comments.ts b/web/lib/firebase/comments.ts index 6cc120cf..e00d7397 100644 --- a/web/lib/firebase/comments.ts +++ b/web/lib/firebase/comments.ts @@ -18,6 +18,9 @@ import { Comment, ContractComment, GroupComment, + OnContract, + OnGroup, + OnPost, PostComment, } from 'common/comment' import { removeUndefinedProps } from 'common/util/object' @@ -39,14 +42,19 @@ export async function createCommentOnContract( const ref = betId ? doc(getCommentsCollection(contractId), betId) : doc(getCommentsCollection(contractId)) + const onContract = { + commentType: 'contract', + contractId, + betId, + answerOutcome, + } as OnContract return await createComment( contractId, - 'contract', + onContract, content, user, ref, - replyToCommentId, - { answerOutcome: answerOutcome, betId: betId } + replyToCommentId ) } export async function createCommentOnGroup( @@ -56,9 +64,10 @@ export async function createCommentOnGroup( replyToCommentId?: string ) { const ref = doc(getCommentsOnGroupCollection(groupId)) + const onGroup = { commentType: 'group', groupId: groupId } as OnGroup return await createComment( groupId, - 'group', + onGroup, content, user, ref, @@ -73,10 +82,10 @@ export async function createCommentOnPost( replyToCommentId?: string ) { const ref = doc(getCommentsOnPostCollection(postId)) - + const onPost = { postId: postId, commentType: 'post' } as OnPost return await createComment( postId, - 'post', + onPost, content, user, ref, @@ -86,12 +95,11 @@ export async function createCommentOnPost( async function createComment( surfaceId: string, - surfaceType: 'contract' | 'group' | 'post', + extraFields: OnContract | OnGroup | OnPost, content: JSONContent, user: User, ref: DocumentReference, - replyToCommentId?: string, - extraFields: { [key: string]: any } = {} + replyToCommentId?: string ) { const comment = removeUndefinedProps({ id: ref.id, @@ -105,7 +113,7 @@ async function createComment( ...extraFields, }) - track(`${surfaceType} message`, { + track(`${extraFields.commentType} message`, { user, commentId: ref.id, surfaceId, diff --git a/web/pages/post/[...slugs]/index.tsx b/web/pages/post/[...slugs]/index.tsx index a323c66f..11c37f22 100644 --- a/web/pages/post/[...slugs]/index.tsx +++ b/web/pages/post/[...slugs]/index.tsx @@ -51,13 +51,14 @@ export default function PostPage(props: { comments: PostComment[] }) { const [isShareOpen, setShareOpen] = useState(false) + const { post, creator } = props - const tips = useTipTxns({ postId: props.post.id }) - const shareUrl = `https://${ENV_CONFIG.domain}${postPath(props?.post.slug)}` - const updatedComments = useCommentsOnPost(props.post.id) + const tips = useTipTxns({ postId: post.id }) + const shareUrl = `https://${ENV_CONFIG.domain}${postPath(post.slug)}` + const updatedComments = useCommentsOnPost(post.id) const comments = updatedComments ?? props.comments - if (props.post == null) { + if (post == null) { return } @@ -65,15 +66,15 @@ export default function PostPage(props: {
- + <Title className="!mt-0" text={post.title} /> <Row> <Col className="flex-1"> <div className={'inline-flex'}> <div className="mr-1 text-gray-500">Created by</div> <UserLink className="text-neutral" - name={props.creator.name} - username={props.creator.username} + name={creator.name} + username={creator.username} /> </div> </Col> @@ -103,17 +104,17 @@ export default function PostPage(props: { <Spacer h={2} /> <div className="rounded-lg bg-white px-6 py-4 sm:py-0"> <div className="form-control w-full py-2"> - <Content content={props.post.content} /> + <Content content={post.content} /> </div> </div> <Spacer h={2} /> <div className="rounded-lg bg-white px-6 py-4 sm:py-0"> <PostCommentsActivity - post={props.post} + post={post} comments={comments} tips={tips} - user={props.creator} + user={creator} /> </div> </div> diff --git a/web/posts/post-comments.tsx b/web/posts/post-comments.tsx index a145fdb5..d129f807 100644 --- a/web/posts/post-comments.tsx +++ b/web/posts/post-comments.tsx @@ -39,7 +39,6 @@ export function PostCommentThread(props: { return ( <Col className="relative w-full items-stretch gap-3 pb-4"> - sdafasdfadsf <span className="absolute top-5 left-4 -ml-px h-[calc(100%-2rem)] w-0.5 bg-gray-200" aria-hidden="true"