({
requestQuery: { queryKey, query, params, options = {} },
...props
}: RepostsModalProps)
| 18 | } |
| 19 | |
| 20 | export function RepostsModal({ |
| 21 | requestQuery: { queryKey, query, params, options = {} }, |
| 22 | ...props |
| 23 | }: RepostsModalProps): ReactElement { |
| 24 | const container = useRef<HTMLElement>(null); |
| 25 | const modalRef = useRef<HTMLElement | null>(null); |
| 26 | const { requestMethod } = useRequestProtocol(); |
| 27 | |
| 28 | if (!requestMethod) { |
| 29 | throw new Error('Request method is required in RepostsModal'); |
| 30 | } |
| 31 | |
| 32 | const queryResult = useInfiniteQuery({ |
| 33 | queryKey, |
| 34 | queryFn: ({ pageParam }) => |
| 35 | requestMethod( |
| 36 | query, |
| 37 | { ...params, after: pageParam }, |
| 38 | { requestKey: JSON.stringify(queryKey) }, |
| 39 | ), |
| 40 | initialPageParam: '', |
| 41 | ...options, |
| 42 | getNextPageParam: ({ postReposts }) => |
| 43 | getNextPageParam(postReposts?.pageInfo), |
| 44 | }); |
| 45 | |
| 46 | const reposts: Post[] = |
| 47 | queryResult.data?.pages.flatMap((page) => |
| 48 | page.postReposts.edges.map(({ node }) => node), |
| 49 | ) ?? []; |
| 50 | |
| 51 | return ( |
| 52 | <Modal |
| 53 | {...props} |
| 54 | contentRef={(element) => { |
| 55 | modalRef.current = element; |
| 56 | }} |
| 57 | kind={Modal.Kind.FlexibleCenter} |
| 58 | size={Modal.Size.Medium} |
| 59 | > |
| 60 | <Modal.Header title="Reposts" /> |
| 61 | <Modal.Body |
| 62 | className="!p-0 [&_a:hover]:!no-underline [&_a]:!no-underline" |
| 63 | ref={container} |
| 64 | > |
| 65 | <InfiniteScrolling |
| 66 | canFetchMore={checkFetchMore(queryResult)} |
| 67 | isFetchingNextPage={queryResult.isFetchingNextPage} |
| 68 | fetchNextPage={queryResult.fetchNextPage} |
| 69 | > |
| 70 | {reposts.map((post) => ( |
| 71 | <RepostListItem |
| 72 | key={post.id} |
| 73 | post={post} |
| 74 | scrollingContainer={container.current} |
| 75 | appendTooltipTo={modalRef.current} |
| 76 | /> |
| 77 | ))} |
nothing calls this directly
no test coverage detected