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

Function findIndexOfPostInData

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

Source from the content-addressed store, hash-verified

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