MCPcopy Create free account
hub / github.com/campsite/campsite / updatePageQueryData

Function updatePageQueryData

apps/web/hooks/useCreateCommentCallbacks.ts:56–83  ·  view source on GitHub ↗
(newComment: Comment)

Source from the content-addressed store, hash-verified

54const getProjectsPosts = apiClient.organizations.getProjectsPosts()
55
56const updatePageQueryData = (newComment: Comment) => (old: InfiniteData<CommentPage> | undefined) => {
57 if (!old) {
58 // if there was no page, insert a new one so comment lists update immediately
59 return {
60 pageParams: [],
61 pages: [
62 {
63 data: [newComment],
64 total_count: 1
65 }
66 ]
67 }
68 } else {
69 // insert the new comment at the top of the first page
70 const [firstPage, ...rest] = old.pages
71
72 return {
73 ...old,
74 pages: [
75 {
76 ...firstPage,
77 data: [newComment, ...firstPage.data]
78 },
79 ...rest
80 ]
81 }
82 }
83}
84
85function replaceOptimisticComments(optimisticId: string, comments: Comment[], serverComment: Comment): Comment[] {
86 return comments.map((comment) => {

Callers 1

optimisticUpdateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected