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

Function findIndexOfPostInData

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

Source from the content-addressed store, hash-verified

647};
648
649export const findIndexOfPostInData = (
650 data: InfiniteData<AnyFeedData>,
651 id: string,
652 findBySharedPost = false,
653): { pageIndex: number; index: number } => {
654 for (let pageIndex = 0; pageIndex < data.pages.length; pageIndex += 1) {
655 const page = data.pages[pageIndex];
656 for (let index = 0; index < page.page.edges.length; index += 1) {
657 const item = page.page.edges[index];
658 const post = getFeedApiItemPost(item.node);
659
660 if (post?.id === id) {
661 return { pageIndex, index };
662 }
663 if (
664 post &&
665 findBySharedPost &&
666 post.type === PostType.Share &&
667 post.sharedPost?.id === id
668 ) {
669 return { pageIndex, index };
670 }
671 }
672 }
673 return { pageIndex: -1, index: -1 };
674};
675
676export const updatePostCache = (
677 client: QueryClient,

Callers 5

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