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

Function findIndexOfPostInData

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

Source from the content-addressed store, hash-verified

608};
609
610export const findIndexOfPostInData = (
611 data: InfiniteData<AnyFeedData>,
612 id: string,
613 findBySharedPost = false,
614): { pageIndex: number; index: number } => {
615 for (let pageIndex = 0; pageIndex < data.pages.length; pageIndex += 1) {
616 const page = data.pages[pageIndex];
617 for (let index = 0; index < page.page.edges.length; index += 1) {
618 const item = page.page.edges[index];
619 const post = getFeedApiItemPost(item.node);
620
621 if (post?.id === id) {
622 return { pageIndex, index };
623 }
624 if (
625 post &&
626 findBySharedPost &&
627 post.type === PostType.Share &&
628 post.sharedPost?.id === id
629 ) {
630 return { pageIndex, index };
631 }
632 }
633 }
634 return { pageIndex: -1, index: -1 };
635};
636
637export const updatePostCache = (
638 client: QueryClient,

Callers 6

BookmarkFeedLayoutFunction · 0.90
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