MCPcopy Create free account
hub / github.com/dailydotdev/apps / NewCommentComponent

Function NewCommentComponent

packages/shared/src/components/post/NewComment.tsx:71–223  ·  view source on GitHub ↗
(
  {
    className,
    size = ProfileImageSize.Large,
    onCommented,
    post,
    shouldHandleCommentQuery = false,
    CommentInput,
    onComposerOpenChange,
    renderTrigger,
    ...props
  }: NewCommentProps,
  ref: ForwardedRef<NewCommentRef>,
)

Source from the content-addressed store, hash-verified

69}
70
71function NewCommentComponent(
72 {
73 className,
74 size = ProfileImageSize.Large,
75 onCommented,
76 post,
77 shouldHandleCommentQuery = false,
78 CommentInput,
79 onComposerOpenChange,
80 renderTrigger,
81 ...props
82 }: NewCommentProps,
83 ref: ForwardedRef<NewCommentRef>,
84): ReactElement {
85 const router = useRouter();
86 const { logEvent } = useLogContext();
87 const { logOpts } = useActiveFeedContext();
88 const { user, showLogin } = useAuthContext();
89 const inputId = `comment-input-${useId()}`;
90 const [inputContent, setInputContent] = useState<string | undefined>(
91 undefined,
92 );
93
94 const onSuccess: typeof onCommented = (comment, isNew) => {
95 setInputContent(undefined);
96 onCommented?.(comment, isNew);
97 };
98
99 const onShowComment = useCallback(
100 (origin: Origin, content = '') => {
101 logEvent(
102 postLogEvent(LogEvent.OpenComment, post, {
103 extra: { origin },
104 ...(logOpts && logOpts),
105 }),
106 );
107
108 setInputContent(content);
109 },
110 [post, logEvent, setInputContent, logOpts],
111 );
112
113 const hasCommentQuery = typeof router.query.comment === 'string';
114 const isComposerOpen = typeof inputContent !== 'undefined';
115
116 useEffect(() => {
117 onComposerOpenChange?.(isComposerOpen);
118 }, [isComposerOpen, onComposerOpenChange]);
119
120 useEffect(() => {
121 if (
122 !shouldHandleCommentQuery ||
123 !hasCommentQuery ||
124 (post.type !== PostType.Welcome && post.type !== PostType.Poll)
125 ) {
126 return;
127 }
128

Callers

nothing calls this directly

Calls 9

useLogContextFunction · 0.90
useActiveFeedContextFunction · 0.90
useAuthContextFunction · 0.90
postLogEventFunction · 0.90
getProfilePictureClassesFunction · 0.90
logEventFunction · 0.85
replaceMethod · 0.80
onCommentClickFunction · 0.70
useRouterFunction · 0.50

Tested by

no test coverage detected