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

Function prependNewPost

apps/web/hooks/useCreatePost.ts:10–27  ·  view source on GitHub ↗
(post: Post)

Source from the content-addressed store, hash-verified

8import { apiClient, setTypedInfiniteQueriesData } from '@/utils/queryClient'
9
10export function prependNewPost<Page extends { data: Post[] }>(post: Post) {
11 return (old: InfiniteData<Page> | undefined): InfiniteData<Page> | undefined => {
12 if (!old) return old
13
14 const [firstPage, ...pages] = old.pages
15
16 return {
17 ...old,
18 pages: [
19 {
20 ...firstPage,
21 data: [post, ...firstPage.data]
22 },
23 ...pages
24 ]
25 }
26 }
27}
28
29export function bumpPostToTop<Page extends { data: Post[] }>(post: Post) {
30 return (old: InfiniteData<Page> | undefined): InfiniteData<Page> | undefined => {

Callers 3

bumpPostToTopFunction · 0.85
publishPostToQueryCacheFunction · 0.85
useCreatePostFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected