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

Function findIndexOfPostInData

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

Source from the content-addressed store, hash-verified

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