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

Function NewCommentComponent

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

Source from the content-addressed store, hash-verified

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

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