Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

2.8 KB
Raw Blame
import { BindLogic, useActions, useValues } from 'kea'
import { useEffect } from 'react'

import * as phoneCall from '@posthog/brand/hoggies/png/phone-call'
import { LemonSkeleton } from '@posthog/lemon-ui'

import { pngHoggie } from 'lib/brand/hoggies'

import { CommentWithReplies } from './Comment'
import { CommentsLogicProps, commentsLogic } from './commentsLogic'
import { SendCommentToSlackModal } from './SendCommentToSlackModal'

const HedgehogPhoneCall = pngHoggie(phoneCall)

export interface CommentsListProps extends CommentsLogicProps {
    noun?: string
}

export const CommentsList = ({ noun = 'page', ...props }: CommentsListProps): JSX.Element => {
    const { key, commentsWithReplies, commentsInitialLoading } = useValues(commentsLogic(props))
    const { loadComments, setReplyingComment, clearRichContentEditor } = useActions(commentsLogic(props))

    // If the comment list focus changes we should load the comments
    useEffect(() => {
        loadComments()
    }, [key]) // oxlint-disable-line react-hooks/exhaustive-deps

    useEffect(() => {
        return () => {
            // Closing the surface ends any reply flow so reopening starts fresh everywhere (the
            // reply text survives in its thread's draft slot), and deregisters the dying editor
            // so nothing waiting for a composer grabs it
            setReplyingComment(null)
            clearRichContentEditor()
        }
    }, []) // oxlint-disable-line react-hooks/exhaustive-deps

    return (
        <BindLogic logic={commentsLogic} props={props}>
            <div className="flex flex-col">
                {commentsInitialLoading ? (
                    <div className="deprecated-space-y-2">
                        <LemonSkeleton className="h-10 w-full" />
                    </div>
                ) : !commentsWithReplies?.length ? (
                    <div className="mx-auto p-8 max-w-160 deprecated-space-y-4">
                        <div className="max-w-120 mx-auto">
                            <HedgehogPhoneCall className="w-full max-w-[200px]" />
                        </div>
                        <h2>Start the discussion!</h2>
                        <p>
                            You can add comments about this {noun} for your team members to see. Great for sharing
                            context or ideas without getting in the way of the thing you are commenting on
                        </p>
                    </div>
                ) : null}

                <div className="flex flex-col gap-4">
                    {commentsWithReplies?.map((x) => (
                        <CommentWithReplies key={x.id} commentWithReplies={x} composerLogicProps={props} />
                    ))}
                </div>
                <SendCommentToSlackModal />
            </div>
        </BindLogic>
    )
}