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

Function findIndexOfPostInData

packages/shared/src/lib/query.ts:611–636  ·  view source on GitHub ↗
(
  data: InfiniteData<AnyFeedData>,
  id: string,
  findBySharedPost = false,
)

Source from the content-addressed store, hash-verified

609};
610
611export const findIndexOfPostInData = (
612 data: InfiniteData<AnyFeedData>,
613 id: string,
614 findBySharedPost = false,
615): { pageIndex: number; index: number } => {
616 for (let pageIndex = 0; pageIndex < data.pages.length; pageIndex += 1) {
617 const page = data.pages[pageIndex];
618 for (let index = 0; index < page.page.edges.length; index += 1) {
619 const item = page.page.edges[index];
620 const post = getFeedApiItemPost(item.node);
621
622 if (post?.id === id) {
623 return { pageIndex, index };
624 }
625 if (
626 post &&
627 findBySharedPost &&
628 post.type === PostType.Share &&
629 post.sharedPost?.id === id
630 ) {
631 return { pageIndex, index };
632 }
633 }
634 }
635 return { pageIndex: -1, index: -1 };
636};
637
638export const updatePostCache = (
639 client: QueryClient,

Callers 6

BookmarkFeedLayoutFunction · 0.90
findPostFunction · 0.90
usePollFunction · 0.90
useFeedFunction · 0.90
useTranslationFunction · 0.90
updateFeedAndAdsCacheFunction · 0.85

Calls 1

getFeedApiItemPostFunction · 0.90

Tested by

no test coverage detected