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
} & 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
}

View File

@ -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<DocumentData>,
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,

View File

@ -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 <Custom404 />
}
@ -65,15 +66,15 @@ export default function PostPage(props: {
<Page>
<div className="mx-auto w-full max-w-3xl ">
<Spacer h={1} />
<Title className="!mt-0" text={props.post.title} />
<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>

View File

@ -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"