Skip to content

Commit 8c0b459

Browse files
refactor(client): replace Map's static query with page queries (freeCodeCamp#55792)
1 parent 7345989 commit 8c0b459

File tree

8 files changed

+152
-146
lines changed

8 files changed

+152
-146
lines changed

client/src/components/Map/index.tsx

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { Fragment } from 'react';
2-
import { graphql, useStaticQuery } from 'gatsby';
32
import { useTranslation } from 'react-i18next';
43
import { connect } from 'react-redux';
54
import { createSelector } from 'reselect';
@@ -27,11 +26,7 @@ import {
2726

2827
import { RibbonIcon } from '../../assets/icons/completion-ribbon';
2928

30-
import {
31-
CurrentCert,
32-
ClaimedCertifications,
33-
AllChallengeNode
34-
} from '../../redux/prop-types';
29+
import { CurrentCert, ClaimedCertifications } from '../../redux/prop-types';
3530
import {
3631
certSlugTypeMap,
3732
superBlockCertTypeMap
@@ -44,6 +39,10 @@ interface MapProps {
4439
currentCerts: CurrentCert[];
4540
claimedCertifications?: ClaimedCertifications;
4641
completedChallengeIds: string[];
42+
allChallenges: {
43+
id: string;
44+
superBlock: SuperBlocks;
45+
}[];
4746
}
4847

4948
const linkSpacingStyle = {
@@ -131,29 +130,9 @@ function Map({
131130
forLanding = false,
132131
isSignedIn,
133132
currentCerts,
134-
completedChallengeIds
133+
completedChallengeIds,
134+
allChallenges
135135
}: MapProps): React.ReactElement {
136-
const {
137-
allChallengeNode: { edges }
138-
}: {
139-
allChallengeNode: AllChallengeNode;
140-
} = useStaticQuery(graphql`
141-
query allChallenges {
142-
allChallengeNode {
143-
edges {
144-
node {
145-
challenge {
146-
id
147-
superBlock
148-
}
149-
}
150-
}
151-
}
152-
}
153-
`);
154-
155-
const allChallenges = edges.map(edge => edge.node.challenge);
156-
157136
const { t } = useTranslation();
158137

159138
const allSuperblockChallengesCompleted = (superblock: SuperBlocks) => {

client/src/components/landing/components/certifications.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@ import { Col } from '@freecodecamp/ui';
33

44
import Map from '../../Map/index';
55
import { Spacer } from '../../helpers';
6+
import { type SuperBlocks } from '../../../../../shared/config/curriculum';
67
import BigCallToAction from './big-call-to-action';
78

8-
const Certifications = (): JSX.Element => {
9+
const Certifications = ({
10+
allChallenges
11+
}: {
12+
allChallenges: {
13+
id: string;
14+
superBlock: SuperBlocks;
15+
}[];
16+
}): JSX.Element => {
917
return (
1018
<Col
1119
className='certification-section'
@@ -15,7 +23,7 @@ const Certifications = (): JSX.Element => {
1523
smOffset={1}
1624
xs={12}
1725
>
18-
<Map forLanding={true} />
26+
<Map allChallenges={allChallenges} forLanding={true} />
1927
<Spacer size='medium' />
2028
<BigCallToAction />
2129
<Spacer size='medium' />

client/src/components/landing/index.tsx

Lines changed: 0 additions & 59 deletions
This file was deleted.

client/src/components/landing/landing.test.tsx

Lines changed: 0 additions & 30 deletions
This file was deleted.

client/src/pages/index.tsx

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,103 @@
11
import React from 'react';
2+
import { graphql } from 'gatsby';
3+
import { useTranslation } from 'react-i18next';
4+
import { useGrowthBook } from '@growthbook/growthbook-react';
25

3-
import Landing from '../components/landing';
6+
import { SuperBlocks } from '../../../shared/config/curriculum';
7+
import SEO from '../components/seo';
8+
import { Loader } from '../components/helpers';
9+
import LandingTop from '../components/landing/components/landing-top';
10+
import LandingTopB from '../components/landing/components/landing-top-b';
11+
import AsSeenIn from '../components/landing/components/as-seen-in';
12+
import Testimonials from '../components/landing/components/testimonials';
13+
import Certifications from '../components/landing/components/certifications';
14+
import Faq from '../components/landing/components/faq';
15+
import '../components/landing/landing.css';
416

5-
function IndexPage(): JSX.Element {
6-
return <Landing />;
17+
type Challenge = {
18+
id: string;
19+
superBlock: SuperBlocks;
20+
};
21+
22+
type Props = {
23+
data: {
24+
allChallengeNode: {
25+
nodes: {
26+
challenge: Challenge;
27+
}[];
28+
};
29+
};
30+
};
31+
32+
type LandingProps = {
33+
allChallenges: Challenge[];
34+
};
35+
36+
const LandingA = ({ allChallenges }: LandingProps) => (
37+
<main className='landing-page'>
38+
<LandingTop />
39+
<AsSeenIn />
40+
<Testimonials />
41+
<Certifications allChallenges={allChallenges} />
42+
<Faq />
43+
</main>
44+
);
45+
46+
const LandingB = ({ allChallenges }: LandingProps) => (
47+
<main className='landing-page landing-page-b'>
48+
<LandingTopB />
49+
<Testimonials />
50+
<Certifications allChallenges={allChallenges} />
51+
<Faq />
52+
</main>
53+
);
54+
55+
function IndexPage({
56+
data: {
57+
allChallengeNode: { nodes: challengeNodes }
58+
}
59+
}: Props): JSX.Element {
60+
const { t } = useTranslation();
61+
const growthbook = useGrowthBook();
62+
const allChallenges = challengeNodes.map(node => node.challenge);
63+
if (growthbook && growthbook.ready) {
64+
const showLandingPageRedesign = growthbook.getFeatureValue(
65+
'landing-page-redesign',
66+
false
67+
);
68+
return (
69+
<>
70+
<SEO title={t('metaTags:title')} />
71+
{showLandingPageRedesign === true ? (
72+
<LandingB allChallenges={allChallenges} />
73+
) : (
74+
<LandingA allChallenges={allChallenges} />
75+
)}
76+
</>
77+
);
78+
} else {
79+
return (
80+
<>
81+
<SEO title={t('metaTags:title')} />
82+
<Loader fullScreen={true} />
83+
</>
84+
);
85+
}
786
}
887

988
IndexPage.displayName = 'IndexPage';
1089

1190
export default IndexPage;
91+
92+
export const query = graphql`
93+
query AllChallengeNode {
94+
allChallengeNode {
95+
nodes {
96+
challenge {
97+
id
98+
superBlock
99+
}
100+
}
101+
}
102+
}
103+
`;

client/src/pages/learn.tsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
} from '../redux/selectors';
1818

1919
import callGA from '../analytics/call-ga';
20+
import { SuperBlocks } from '../../../shared/config/curriculum';
2021

2122
interface FetchState {
2223
pending: boolean;
@@ -57,6 +58,14 @@ interface LearnPageProps {
5758
fields: Slug;
5859
};
5960
};
61+
allChallengeNode: {
62+
nodes: {
63+
challenge: {
64+
id: string;
65+
superBlock: SuperBlocks;
66+
};
67+
}[];
68+
};
6069
};
6170
}
6271

@@ -69,7 +78,8 @@ function LearnPage({
6978
challenge: {
7079
fields: { slug }
7180
}
72-
}
81+
},
82+
allChallengeNode: { nodes: challengeNodes }
7383
}
7484
}: LearnPageProps) {
7585
const { t } = useTranslation();
@@ -96,7 +106,7 @@ function LearnPage({
96106
onLearnDonationAlertClick={onLearnDonationAlertClick}
97107
isDonating={isDonating}
98108
/>
99-
<Map />
109+
<Map allChallenges={challengeNodes.map(node => node.challenge)} />
100110
<Spacer size='large' />
101111
</Col>
102112
</Row>
@@ -110,7 +120,7 @@ LearnPage.displayName = 'LearnPage';
110120
export default connect(mapStateToProps)(LearnPage);
111121

112122
export const query = graphql`
113-
query FirstChallenge {
123+
query LearnPageQuery {
114124
challengeNode(
115125
challenge: {
116126
superOrder: { eq: 0 }
@@ -124,5 +134,13 @@ export const query = graphql`
124134
}
125135
}
126136
}
137+
allChallengeNode {
138+
nodes {
139+
challenge {
140+
id
141+
superBlock
142+
}
143+
}
144+
}
127145
}
128146
`;

0 commit comments

Comments
 (0)