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

Function findIndexOfPostInData

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

Source from the content-addressed store, hash-verified

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