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

Function findIndexOfPostInData

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

Source from the content-addressed store, hash-verified

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