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

Function updateQueryData

packages/shared/src/hooks/post/useMutateComment.ts:100–144  ·  view source on GitHub ↗
(data: PostCommentsData)

Source from the content-addressed store, hash-verified

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

Callers 1

onSuccessFunction · 0.70

Calls 2

generateCommentEdgeFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected