This commit is contained in:
Pico2x 2022-09-07 22:58:36 +01:00
parent 93a85e2286
commit 187c32def9
4 changed files with 32 additions and 24 deletions

View File

@ -20,7 +20,7 @@ export type Comment<T extends AnyCommentType = AnyCommentType> = {
userAvatarUrl?: string userAvatarUrl?: string
} & T } & T
type OnContract = { export type OnContract = {
commentType: 'contract' commentType: 'contract'
contractId: string contractId: string
answerOutcome?: string answerOutcome?: string
@ -35,12 +35,12 @@ type OnContract = {
betOutcome?: string betOutcome?: string
} }
type OnGroup = { export type OnGroup = {
commentType: 'group' commentType: 'group'
groupId: string groupId: string
} }
type OnPost = { export type OnPost = {
commentType: 'post' commentType: 'post'
postId: string postId: string
} }

View File

@ -18,6 +18,9 @@ import {
Comment, Comment,
ContractComment, ContractComment,
GroupComment, GroupComment,
OnContract,
OnGroup,
OnPost,
PostComment, PostComment,
} from 'common/comment' } from 'common/comment'
import { removeUndefinedProps } from 'common/util/object' import { removeUndefinedProps } from 'common/util/object'
@ -39,14 +42,19 @@ export async function createCommentOnContract(
const ref = betId const ref = betId
? doc(getCommentsCollection(contractId), betId) ? doc(getCommentsCollection(contractId), betId)
: doc(getCommentsCollection(contractId)) : doc(getCommentsCollection(contractId))
const onContract = {
commentType: 'contract',
contractId,
betId,
answerOutcome,
} as OnContract
return await createComment( return await createComment(
contractId, contractId,
'contract', onContract,
content, content,
user, user,
ref, ref,
replyToCommentId, replyToCommentId
{ answerOutcome: answerOutcome, betId: betId }
) )
} }
export async function createCommentOnGroup( export async function createCommentOnGroup(
@ -56,9 +64,10 @@ export async function createCommentOnGroup(
replyToCommentId?: string replyToCommentId?: string
) { ) {
const ref = doc(getCommentsOnGroupCollection(groupId)) const ref = doc(getCommentsOnGroupCollection(groupId))
const onGroup = { commentType: 'group', groupId: groupId } as OnGroup
return await createComment( return await createComment(
groupId, groupId,
'group', onGroup,
content, content,
user, user,
ref, ref,
@ -73,10 +82,10 @@ export async function createCommentOnPost(
replyToCommentId?: string replyToCommentId?: string
) { ) {
const ref = doc(getCommentsOnPostCollection(postId)) const ref = doc(getCommentsOnPostCollection(postId))
const onPost = { postId: postId, commentType: 'post' } as OnPost
return await createComment( return await createComment(
postId, postId,
'post', onPost,
content, content,
user, user,
ref, ref,
@ -86,12 +95,11 @@ export async function createCommentOnPost(
async function createComment( async function createComment(
surfaceId: string, surfaceId: string,
surfaceType: 'contract' | 'group' | 'post', extraFields: OnContract | OnGroup | OnPost,
content: JSONContent, content: JSONContent,
user: User, user: User,
ref: DocumentReference<DocumentData>, ref: DocumentReference<DocumentData>,
replyToCommentId?: string, replyToCommentId?: string
extraFields: { [key: string]: any } = {}
) { ) {
const comment = removeUndefinedProps({ const comment = removeUndefinedProps({
id: ref.id, id: ref.id,
@ -105,7 +113,7 @@ async function createComment(
...extraFields, ...extraFields,
}) })
track(`${surfaceType} message`, { track(`${extraFields.commentType} message`, {
user, user,
commentId: ref.id, commentId: ref.id,
surfaceId, surfaceId,

View File

@ -51,13 +51,14 @@ export default function PostPage(props: {
comments: PostComment[] comments: PostComment[]
}) { }) {
const [isShareOpen, setShareOpen] = useState(false) const [isShareOpen, setShareOpen] = useState(false)
const { post, creator } = props
const tips = useTipTxns({ postId: props.post.id }) const tips = useTipTxns({ postId: post.id })
const shareUrl = `https://${ENV_CONFIG.domain}${postPath(props?.post.slug)}` const shareUrl = `https://${ENV_CONFIG.domain}${postPath(post.slug)}`
const updatedComments = useCommentsOnPost(props.post.id) const updatedComments = useCommentsOnPost(post.id)
const comments = updatedComments ?? props.comments const comments = updatedComments ?? props.comments
if (props.post == null) { if (post == null) {
return <Custom404 /> return <Custom404 />
} }
@ -65,15 +66,15 @@ export default function PostPage(props: {
<Page> <Page>
<div className="mx-auto w-full max-w-3xl "> <div className="mx-auto w-full max-w-3xl ">
<Spacer h={1} /> <Spacer h={1} />
<Title className="!mt-0" text={props.post.title} /> <Title className="!mt-0" text={post.title} />
<Row> <Row>
<Col className="flex-1"> <Col className="flex-1">
<div className={'inline-flex'}> <div className={'inline-flex'}>
<div className="mr-1 text-gray-500">Created by</div> <div className="mr-1 text-gray-500">Created by</div>
<UserLink <UserLink
className="text-neutral" className="text-neutral"
name={props.creator.name} name={creator.name}
username={props.creator.username} username={creator.username}
/> />
</div> </div>
</Col> </Col>
@ -103,17 +104,17 @@ export default function PostPage(props: {
<Spacer h={2} /> <Spacer h={2} />
<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">
<div className="form-control w-full py-2"> <div className="form-control w-full py-2">
<Content content={props.post.content} /> <Content content={post.content} />
</div> </div>
</div> </div>
<Spacer h={2} /> <Spacer h={2} />
<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={props.post} post={post}
comments={comments} comments={comments}
tips={tips} tips={tips}
user={props.creator} user={creator}
/> />
</div> </div>
</div> </div>

View File

@ -39,7 +39,6 @@ export function PostCommentThread(props: {
return ( return (
<Col className="relative w-full items-stretch gap-3 pb-4"> <Col className="relative w-full items-stretch gap-3 pb-4">
sdafasdfadsf
<span <span
className="absolute top-5 left-4 -ml-px h-[calc(100%-2rem)] w-0.5 bg-gray-200" className="absolute top-5 left-4 -ml-px h-[calc(100%-2rem)] w-0.5 bg-gray-200"
aria-hidden="true" aria-hidden="true"