|
1 | | -import React, { useState, useEffect } from "react" |
| 1 | +import React, { useState, useEffect, useMemo } from "react" |
2 | 2 | import { |
3 | 3 | IssueOpenedIcon, |
4 | 4 | IssueClosedIcon, |
@@ -85,17 +85,33 @@ const Home: React.FC = () => { |
85 | 85 | const [startDate, setStartDate] = useState(""); |
86 | 86 | const [endDate, setEndDate] = useState(""); |
87 | 87 |
|
88 | | - // Fetch data when username, tab, or page changes |
| 88 | + // Fetch data when username, filters, tab, or page changes |
89 | 89 | useEffect(() => { |
90 | 90 | if (username) { |
91 | | - fetchData(username, page + 1, ROWS_PER_PAGE); |
| 91 | + const filters = { |
| 92 | + search: searchTitle, |
| 93 | + repo: selectedRepo, |
| 94 | + startDate: startDate, |
| 95 | + endDate: endDate, |
| 96 | + state: tab === 0 ? issueFilter : prFilter, |
| 97 | + }; |
| 98 | + const activeTab = tab === 0 ? 'issue' : 'pr'; |
| 99 | + fetchData(username, page + 1, ROWS_PER_PAGE, activeTab, filters); |
92 | 100 | } |
93 | | - }, [tab, page]); |
| 101 | + }, [username, tab, page, issueFilter, prFilter, searchTitle, selectedRepo, startDate, endDate, fetchData]); |
94 | 102 |
|
95 | 103 | const handleSubmit = (e: React.FormEvent<HTMLFormElement>): void => { |
96 | 104 | e.preventDefault(); |
97 | 105 | setPage(0); |
98 | | - fetchData(username, 1, ROWS_PER_PAGE); |
| 106 | + const filters = { |
| 107 | + search: searchTitle, |
| 108 | + repo: selectedRepo, |
| 109 | + startDate: startDate, |
| 110 | + endDate: endDate, |
| 111 | + state: tab === 0 ? issueFilter : prFilter, |
| 112 | + }; |
| 113 | + const activeTab = tab === 0 ? 'issue' : 'pr'; |
| 114 | + fetchData(username, 1, ROWS_PER_PAGE, activeTab, filters); |
99 | 115 | }; |
100 | 116 |
|
101 | 117 | const handlePageChange = (_: unknown, newPage: number) => { |
@@ -164,9 +180,11 @@ const Home: React.FC = () => { |
164 | 180 | }; |
165 | 181 |
|
166 | 182 |
|
167 | | - // Current data and filtered data according to tab and filters |
| 183 | + // Memoized filtered data to avoid recomputing on every render |
168 | 184 | const currentRawData = tab === 0 ? issues : prs; |
169 | | - const currentFilteredData = filterData(currentRawData, tab === 0 ? issueFilter : prFilter); |
| 185 | + const currentFilteredData = useMemo(() => { |
| 186 | + return filterData(currentRawData, tab === 0 ? issueFilter : prFilter); |
| 187 | + }, [currentRawData, tab, issueFilter, prFilter, searchTitle, selectedRepo, startDate, endDate]); |
170 | 188 | const totalCount = tab === 0 ? totalIssues : totalPrs; |
171 | 189 |
|
172 | 190 | // Helper function to get status badge color |
@@ -236,7 +254,6 @@ const Home: React.FC = () => { |
236 | 254 | value={token} |
237 | 255 | onChange={(e) => setToken(e.target.value)} |
238 | 256 | type="password" |
239 | | - required |
240 | 257 | placeholder="Paste your token here" |
241 | 258 | variant="outlined" |
242 | 259 | size="medium" |
@@ -529,7 +546,7 @@ const Home: React.FC = () => { |
529 | 546 | </TableCell> |
530 | 547 | <TableCell align="center" sx={{ py: 2 }}> |
531 | 548 | <Chip |
532 | | - label={item.repository_url.split("/").slice(-1)[0]} |
| 549 | + label={item.repository_url.split("/").slice(-2).join("/")} |
533 | 550 | size="small" |
534 | 551 | variant="outlined" |
535 | 552 | /> |
|
0 commit comments