1- import { useState , useCallback , useRef } from 'react' ;
1+ import { useState , useRef , useCallback } from 'react' ;
22
33export const useGitHubData = ( getOctokit : ( ) => any ) => {
4+ type SearchType = 'issue' | 'pr' ;
45 const [ issues , setIssues ] = useState ( [ ] ) ;
56 const [ prs , setPrs ] = useState ( [ ] ) ;
67 const [ loading , setLoading ] = useState ( false ) ;
@@ -9,12 +10,12 @@ export const useGitHubData = (getOctokit: () => any) => {
910 const [ totalPrs , setTotalPrs ] = useState ( 0 ) ;
1011 const [ rateLimited , setRateLimited ] = useState ( false ) ;
1112
12- const cursorsRef = useRef < { issue : Record < number , string | null > , pr : Record < number , string | null > } > ( {
13+ const cursorsRef = useRef < Record < SearchType , Record < number , string | null > > > ( {
1314 issue : { } ,
1415 pr : { } ,
1516 } ) ;
1617
17- const fetchPaginated = async ( octokit : any , username : string , type : string , page = 1 , per_page = 10 ) => {
18+ const fetchPaginated = async ( octokit : any , username : string , type : SearchType , page = 1 , per_page = 10 ) => {
1819 const query = `
1920 query ($queryString: String!, $first: Int!, $after: String) {
2021 search(query: $queryString, type: ISSUE, first: $first, after: $after) {
@@ -53,7 +54,7 @@ export const useGitHubData = (getOctokit: () => any) => {
5354 const response = await octokit . graphql ( query , {
5455 queryString,
5556 first : Math . min ( 100 , per_page ) ,
56- after : page > 1 ? ( cursorsRef . current ?. [ type ] ?. [ page - 1 ] ?? null ) : null ,
57+ after : page > 1 ? ( cursorsRef . current [ type ] ?. [ page - 1 ] ?? null ) : null ,
5758 } ) ;
5859
5960 const items = response . search . edges . map ( ( edge : any ) => {
0 commit comments