MCPcopy
hub / github.com/CaliCastle/cali.so / Root

Function Root

components/Commentable.tsx:56–313  ·  view source on GitHub ↗
({ className, blockId }: CommentableProps)

Source from the content-addressed store, hash-verified

54}
55
56function Root({ className, blockId }: CommentableProps) {
57 const pathname = usePathname()
58 const { postId, comments, currentBlockId } = useSnapshot(blogPostState)
59 const { user: me } = useUser()
60 const [isCommenting, setIsCommenting] = React.useState(false)
61 const currentComments = React.useMemo(
62 () => comments.filter((c) => c.body.blockId === blockId),
63 [comments, blockId]
64 )
65 const top3Users = React.useMemo(() => {
66 if (currentComments.length === 0) {
67 return []
68 }
69
70 const users = new Set<PostIDLessCommentDto['userId']>()
71 const top3: PostIDLessCommentDto['userInfo'][] = []
72 for (const comment of currentComments) {
73 if (users.has(comment.userId)) {
74 continue
75 }
76
77 if (comment.userInfo.imageUrl) {
78 top3.push(comment.userInfo)
79 users.add(comment.userId)
80 }
81
82 if (top3.length >= 3) {
83 break
84 }
85 }
86
87 return top3
88 }, [currentComments])
89
90 const formRef = React.useRef<HTMLFormElement>(null)
91 const commentsRef = React.useRef<HTMLUListElement>(null)
92 const scrollToComment = React.useCallback((id: string) => {
93 setTimeout(() => {
94 if (commentsRef.current) {
95 commentsRef.current
96 .querySelector(`[data-commentid="${id}"]`)
97 ?.scrollIntoView({
98 behavior: 'smooth',
99 })
100 }
101 }, 300)
102 }, [])
103
104 const { mutate: createComment, isLoading } = useMutation(
105 ['comment', postId],
106 async (comment: string) => {
107 const res = await fetch(`/api/comments/${postId}`, {
108 method: 'POST',
109 headers: {
110 'Content-Type': 'application/json',
111 },
112 body: JSON.stringify({
113 body: {

Callers

nothing calls this directly

Calls 5

addCommentFunction · 0.90
clearReplyFunction · 0.90
clearBlockFocusFunction · 0.90
focusBlockFunction · 0.90
urlFunction · 0.90

Tested by

no test coverage detected