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

Function NewCommentComponent

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

Source from the content-addressed store, hash-verified

63}
64
65function NewCommentComponent(
66 {
67 className,
68 size = ProfileImageSize.Large,
69 onCommented,
70 post,
71 shouldHandleCommentQuery = false,
72 CommentInput,
73 onComposerOpenChange,
74 ...props
75 }: NewCommentProps,
76 ref: ForwardedRef<NewCommentRef>,
77): ReactElement {
78 const router = useRouter();
79 const { logEvent } = useLogContext();
80 const { logOpts } = useActiveFeedContext();
81 const { user, showLogin } = useAuthContext();
82 const inputId = `comment-input-${useId()}`;
83 const [inputContent, setInputContent] = useState<string | undefined>(
84 undefined,
85 );
86 // NewComment stays mounted on client-side navigation between posts, so close
87 // the composer when the post changes instead of carrying it over.
88 const [composerPostId, setComposerPostId] = useState(post.id);
89 if (composerPostId !== post.id) {
90 setComposerPostId(post.id);
91 setInputContent(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 const draft = useStoredCommentDraft(post?.id, !!user && !isComposerOpen);
116
117 useEffect(() => {
118 onComposerOpenChange?.(isComposerOpen);
119 }, [isComposerOpen, onComposerOpenChange]);
120
121 useEffect(() => {
122 if (

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected