Skip to content

Commit 232cfe9

Browse files
committed
fix: map GitHub response to Tracker fields + cache endCursor
1 parent 14bfce2 commit 232cfe9

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/hooks/useGitHubData.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,24 @@ export const useGitHubData = (getOctokit: () => any) => {
5656
after: page > 1 ? (cursorsRef.current?.[type]?.[page - 1] ?? null) : null,
5757
});
5858

59-
if (!cursorsRef.current[type]) {
60-
cursorsRef.current[type] = {};
61-
}
62-
cursorsRef.current[type][page] = response.search.pageInfo.endCursor;
59+
const items = response.search.edges.map((edge: any) => {
60+
const n = edge.node;
61+
const base = {
62+
id: n.databaseId,
63+
title: n.title,
64+
html_url: n.url,
65+
created_at: n.createdAt,
66+
state: n.state,
67+
repository_url: n.repository.url,
68+
};
69+
return n.mergedAt ? { ...base, pull_request: { merged_at: n.mergedAt } } : base;
70+
});
71+
72+
// cache cursor for pagination
73+
if (!cursorsRef.current[type]) cursorsRef.current[type] = {};
74+
cursorsRef.current[type][page] = response.search.pageInfo.endCursor ?? null;
6375

64-
return {
65-
items: response.search.edges.map((edge: any) => edge.node),
66-
total: response.search.issueCount,
67-
};
76+
return { items, total: response.search.issueCount };
6877
};
6978

7079
const fetchData = useCallback(

0 commit comments

Comments
 (0)