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

Function findIndexOfPostInData

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

Source from the content-addressed store, hash-verified

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