Skip to content

Commit c04d3a4

Browse files
Merge pull request AOSSIE-Org#76 from g-k-s-03/fix/hooks-early-return
fix: move hook calls before early returns to comply with Rules of Hooks
2 parents 63191b4 + 1edf31e commit c04d3a4

5 files changed

Lines changed: 22 additions & 20 deletions

File tree

src/pages/AnalyticsPage.jsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ export default function AnalyticsPage() {
2424
const [granularity, setGranularity] = useState('monthly')
2525
const [selectedRepo, setSelectedRepo] = useState('All')
2626

27-
if (!model) return null
28-
29-
const repoNames = ['All', ...model.allRepos.slice(0, 12).map(r => r.name)]
30-
const hasData = Object.keys(issuesData || {}).length > 0
31-
3227
const allIssues = useMemo(() => {
3328
const arr = []
3429
Object.values(issuesData || {}).forEach(issues => arr.push(...issues))
@@ -46,6 +41,10 @@ export default function AnalyticsPage() {
4641
[filteredIssues, granularity]
4742
)
4843

44+
if (!model) return null
45+
46+
const repoNames = ['All', ...model.allRepos.slice(0, 12).map(r => r.name)]
47+
const hasData = Object.keys(issuesData || {}).length > 0
4948
const hasSeries = series.length > 0
5049

5150
return (

src/pages/ContributorsPage.jsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,10 @@ export default function ContributorsPage() {
4343
document.removeEventListener('mousedown', handleClickOutside)
4444
}, [])
4545

46-
if (!model) return null
47-
const { contributors } = model
4846
const navigate = useNavigate()
47+
const contributors = model?.contributors ?? []
4948

5049
const busFactor = useMemo(() => computeBusFactor(contributors), [contributors])
51-
const topActive = contributors.slice(0, 10).filter(c => c.freshness > 50).length
52-
const freshPct = contributors.length ? Math.round(topActive / Math.min(10, contributors.length) * 100) : 0
53-
const connectors = contributors.filter(c => c.isConnector)
54-
const crossOrg = contributors.filter(c => c.isCrossOrg)
5550

5651
const filtered = useMemo(() =>
5752
contributors.filter(c => !search || c.login.toLowerCase().includes(search.toLowerCase())),
@@ -60,6 +55,13 @@ export default function ContributorsPage() {
6055
const { sorted, sortConfig, onSort } = useSortedData(filtered, 'totalContribs', 'desc')
6156
const visible = sorted.slice(0, shown)
6257

58+
if (!model) return null
59+
60+
const topActive = contributors.slice(0, 10).filter(c => c.freshness > 50).length
61+
const freshPct = contributors.length ? Math.round(topActive / Math.min(10, contributors.length) * 100) : 0
62+
const connectors = contributors.filter(c => c.isConnector)
63+
const crossOrg = contributors.filter(c => c.isCrossOrg)
64+
6365
const riskColor = r => r === 'critical' ? 'var(--red)' : r === 'high' ? 'var(--amber)' : 'var(--green)'
6466
const riskBar = r => r === 'critical' ? '90%' : r === 'high' ? '60%' : '25%'
6567

src/pages/GovernancePage.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ export default function GovernancePage() {
1414
const { model, issuesData, runAudit, govLoading } = useApp()
1515
const [tab, setTab] = useState('dead')
1616

17-
if (!model) return null
18-
19-
const hasAudit = Object.keys(issuesData || {}).length > 0
20-
const daysSince = d => Math.floor((Date.now() - new Date(d)) / 86_400_000)
21-
2217
// Flatten all issues and tag with repo/org
2318
const allIssues = useMemo(() => {
2419
const arr = []
@@ -29,6 +24,11 @@ export default function GovernancePage() {
2924
return arr
3025
}, [issuesData])
3126

27+
if (!model) return null
28+
29+
const hasAudit = Object.keys(issuesData || {}).length > 0
30+
const daysSince = d => Math.floor((Date.now() - new Date(d)) / 86_400_000)
31+
3232
// Health check 1 — Dead Issues (>90 days open, not a PR)
3333
const deadIssues = allIssues
3434
.filter(i => !i.pull_request && daysSince(i.created_at) >= 90)

src/pages/OverviewPage.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ const fmt = n => n > 999 ? (n / 1000).toFixed(1) + 'k' : String(n)
1212
export default function OverviewPage() {
1313
const { orgs, model } = useApp()
1414
const navigate = useNavigate()
15-
if (!model) return null
16-
1715
const [open, setOpen] = useState(false)
1816
const infoRef = useRef(null)
1917

@@ -29,6 +27,8 @@ export default function OverviewPage() {
2927
}
3028
}, [])
3129

30+
if (!model) return null
31+
3232
const { allRepos } = model
3333
const isMulti = orgs.length > 1
3434
const totalStars = allRepos.reduce((s, r) => s + r.stargazers_count, 0)

src/pages/RepositoriesPage.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ export default function RepositoriesPage() {
3737
}, [])
3838

3939
const navigate = useNavigate()
40-
if (!model) return null
41-
const { allRepos } = model
40+
const allRepos = model?.allRepos ?? []
4241

4342
const langs = useMemo(() =>
4443
['All', ...new Set(allRepos.map(r => r.language).filter(Boolean))].slice(0, 10),
@@ -54,6 +53,8 @@ export default function RepositoriesPage() {
5453
const { sorted, sortConfig, onSort } = useSortedData(filtered, 'healthScore', 'desc')
5554
const visible = sorted.slice(0, shown)
5655

56+
if (!model) return null
57+
5758
const TABLE_COLS = [
5859
['name', 'Repository'],
5960
['stargazers_count', 'Stars'],

0 commit comments

Comments
 (0)