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

Function removeCachedComment

packages/shared/src/hooks/usePostById.ts:59–87  ·  view source on GitHub ↗
(data: PostCommentsData)

Source from the content-addressed store, hash-verified

57): void => {
58 const keys = getAllCommentsQuery(post.id);
59 const removeCachedComment = (data: PostCommentsData) => {
60 if (!data) {
61 return data;
62 }
63 const copy = { ...data };
64
65 if (commentId !== parentId) {
66 const parent = copy.postComments.edges.find(
67 ({ node }) => node.id === parentId,
68 );
69 parent.node.children.edges = parent.node.children.edges.filter(
70 ({ node }) => node.id !== commentId,
71 );
72 updatePostCache(client, post.id, { numComments: post.numComments - 1 });
73 return copy;
74 }
75
76 const parent = copy.postComments.edges.find(
77 ({ node }) => node.id === commentId,
78 );
79 const count = parent.node.children.edges.length + 1;
80 const numComments = post.numComments - count;
81 updatePostCache(client, post.id, { numComments });
82 copy.postComments.edges = data.postComments.edges.filter(
83 ({ node }) => node.id !== commentId,
84 );
85
86 return data;
87 };
88
89 keys.forEach((key) => {
90 client.setQueryData(key, removeCachedComment);

Callers

nothing calls this directly

Calls 1

updatePostCacheFunction · 0.90

Tested by

no test coverage detected