Skip to content

Commit ee2d88a

Browse files
committed
fixes jittery-load on first render of /teams page
1 parent 4e97f07 commit ee2d88a

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

web-server/pages/teams/index.tsx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { useRouter } from 'next/router';
2-
import { useEffect } from 'react';
1+
import { useCallback, useEffect } from 'react';
32
import ExtendedSidebarLayout from 'src/layouts/ExtendedSidebarLayout';
43

54
import { FlexBox } from '@/components/FlexBox';
@@ -9,9 +8,11 @@ import { Integration } from '@/constants/integrations';
98
import { useRedirectWithSession } from '@/constants/useRoute';
109
import { PageWrapper } from '@/content/PullRequests/PageWrapper';
1110
import { useAuth } from '@/hooks/useAuth';
11+
import { useBoolState } from '@/hooks/useEasyState';
1212
import { fetchTeams } from '@/slices/team';
1313
import { useDispatch, useSelector } from '@/store';
1414
import { PageLayout } from '@/types/resources';
15+
import { depFn } from '@/utils/fn';
1516

1617
function Page() {
1718
useRedirectWithSession();
@@ -21,18 +22,23 @@ function Page() {
2122
integrations: { github: isGithubIntegrated }
2223
} = useAuth();
2324
const teamsList = useSelector((state) => state.team.teams);
24-
const router = useRouter();
25+
const loading = useBoolState(true);
26+
27+
const fetchAllTeams = useCallback(async () => {
28+
depFn(loading.true);
29+
await dispatch(
30+
fetchTeams({
31+
org_id: orgId,
32+
provider: Integration.GITHUB
33+
})
34+
);
35+
depFn(loading.false);
36+
}, [dispatch, loading.false, loading.true, orgId]);
2537

2638
useEffect(() => {
2739
if (!orgId) return;
28-
if (!teamsList.length)
29-
dispatch(
30-
fetchTeams({
31-
org_id: orgId,
32-
provider: Integration.GITHUB
33-
})
34-
);
35-
}, [dispatch, isGithubIntegrated, orgId, router.replace, teamsList.length]);
40+
if (!teamsList.length) fetchAllTeams();
41+
}, [fetchAllTeams, orgId, teamsList.length]);
3642

3743
return (
3844
<PageWrapper
@@ -45,7 +51,7 @@ function Page() {
4551
showEvenIfNoTeamSelected
4652
hideAllSelectors
4753
>
48-
{isGithubIntegrated ? (
54+
{isGithubIntegrated && !loading.value ? (
4955
<FlexBox col gap={4}>
5056
{teamsList.length ? <TeamsList /> : <CreateEditTeams />}
5157
</FlexBox>

0 commit comments

Comments
 (0)