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

Function onSuccess

packages/shared/src/hooks/post/useMutateComment.ts:95–177  ·  view source on GitHub ↗
(comment: Comment)

Source from the content-addressed store, hash-verified

93 );
94
95 const onSuccess = (comment: Comment) => {
96 if (!comment) {
97 return;
98 }
99
100 const updateQueryData = (data: PostCommentsData) => {
101 if (!data) {
102 return data;
103 }
104 const copy = structuredClone(data);
105
106 if (!editCommentId) {
107 const edge = generateCommentEdge(comment);
108
109 if (!parentCommentId) {
110 copy.postComments.edges.unshift(edge);
111 return copy;
112 }
113
114 const index = copy.postComments.edges.findIndex(
115 ({ node }) => node.id === parentCommentId,
116 );
117 copy.postComments.edges[index].node.children.edges.push(edge);
118
119 return copy;
120 }
121
122 if (!parentCommentId) {
123 const index = copy.postComments.edges.findIndex(
124 ({ node }) => node.id === editCommentId,
125 );
126 copy.postComments.edges[index].node = {
127 ...comment,
128 children: copy.postComments.edges[index].node.children,
129 };
130 return copy;
131 }
132
133 const parent = copy.postComments.edges.find(
134 ({ node }) => node.id === parentCommentId,
135 );
136 const index = parent.node.children.edges.findIndex(
137 ({ node }) => node.id === editCommentId,
138 );
139 parent.node.children.edges[index].node = {
140 ...comment,
141 children: parent.node.children,
142 };
143 return copy;
144 };
145
146 const forInvalidation: QueryKey[] = [];
147
148 getAllCommentsQuery(postId).forEach((queryKey) => {
149 client.setQueryData<PostCommentsData>(queryKey, (data) => {
150 if (!data) {
151 forInvalidation.push(queryKey);
152 return null;

Callers 4

useMutateCommentFunction · 0.70
useProfileFormFunction · 0.50
useSquadCreateFunction · 0.50
useSourcePostModerationFunction · 0.50

Calls 7

getAllCommentsQueryFunction · 0.90
updatePostCacheFunction · 0.90
postLogEventFunction · 0.90
logEventFunction · 0.85
onCommentedFunction · 0.85
pushMethod · 0.80
updateQueryDataFunction · 0.70

Tested by

no test coverage detected