2020-12-28 20:52:41 -06:00
|
|
|
import React from 'react';
|
2019-09-21 19:09:48 +05:30
|
|
|
import { Row, Col } from '@freecodecamp/react-bootstrap';
|
|
|
|
import PropTypes from 'prop-types';
|
2020-12-28 20:52:41 -06:00
|
|
|
import { graphql, useStaticQuery } from 'gatsby';
|
2021-01-13 07:09:45 -06:00
|
|
|
import i18next from 'i18next';
|
2019-09-21 19:09:48 +05:30
|
|
|
|
2021-01-13 07:09:45 -06:00
|
|
|
import { ImageLoader, Link } from '../helpers';
|
2020-12-28 20:52:41 -06:00
|
|
|
import LinkButton from '../../assets/icons/LinkButton';
|
2019-10-04 18:32:35 +03:00
|
|
|
import { dasherize } from '../../../../utils/slugs';
|
2020-12-28 20:52:41 -06:00
|
|
|
import './map.css';
|
2019-09-21 19:09:48 +05:30
|
|
|
|
|
|
|
const propTypes = {
|
2021-01-13 07:09:45 -06:00
|
|
|
currentSuperBlock: PropTypes.string,
|
2020-12-28 20:52:41 -06:00
|
|
|
forLanding: PropTypes.bool
|
2019-09-21 19:09:48 +05:30
|
|
|
};
|
|
|
|
|
2020-12-28 20:52:41 -06:00
|
|
|
const codingPrepRE = new RegExp('Interview Prep');
|
2019-09-21 19:09:48 +05:30
|
|
|
|
2020-12-28 20:52:41 -06:00
|
|
|
function createSuperBlockTitle(str) {
|
2021-01-13 07:09:45 -06:00
|
|
|
const superBlockTitle = i18next.t(`intro:${dasherize(str)}.title`);
|
2020-12-28 20:52:41 -06:00
|
|
|
return codingPrepRE.test(str)
|
2021-01-13 07:09:45 -06:00
|
|
|
? `${superBlockTitle} ${i18next.t('learn.cert-map-estimates.coding-prep')}`
|
|
|
|
: `${superBlockTitle} ${i18next.t('learn.cert-map-estimates.certs')}`;
|
2019-09-21 19:09:48 +05:30
|
|
|
}
|
|
|
|
|
2021-01-13 07:09:45 -06:00
|
|
|
const iconStyle = {
|
|
|
|
width: '55px',
|
|
|
|
height: '55px',
|
|
|
|
marginRight: '20px'
|
|
|
|
};
|
|
|
|
|
|
|
|
const linkSpacingStyle = {
|
|
|
|
display: 'flex',
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
alignItems: 'center'
|
|
|
|
};
|
|
|
|
|
2020-12-28 20:52:41 -06:00
|
|
|
function renderLandingMap(nodes) {
|
2021-01-13 07:09:45 -06:00
|
|
|
nodes = nodes.filter(node => node.superBlock !== 'Coding Interview Prep');
|
2020-12-28 20:52:41 -06:00
|
|
|
return (
|
|
|
|
<ul data-test-label='certifications'>
|
|
|
|
{nodes.map((node, i) => (
|
|
|
|
<li key={i}>
|
|
|
|
<Link
|
|
|
|
className='btn link-btn btn-lg'
|
|
|
|
to={`/learn/${dasherize(node.superBlock)}/`}
|
|
|
|
>
|
2021-01-13 07:09:45 -06:00
|
|
|
<div style={linkSpacingStyle}>
|
|
|
|
<ImageLoader
|
|
|
|
alt='building a website'
|
|
|
|
offsetVertical={500}
|
|
|
|
src={i18next.t(`intro:${dasherize(node.superBlock)}.icon`)}
|
|
|
|
style={iconStyle}
|
|
|
|
/>
|
|
|
|
{i18next.t(`intro:${dasherize(node.superBlock)}.title`)}
|
|
|
|
</div>
|
2020-12-28 20:52:41 -06:00
|
|
|
<LinkButton />
|
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
);
|
|
|
|
}
|
2019-10-04 18:32:35 +03:00
|
|
|
|
2021-01-13 07:09:45 -06:00
|
|
|
function renderLearnMap(nodes, currentSuperBlock = '') {
|
|
|
|
nodes = nodes.filter(node => node.superBlock !== currentSuperBlock);
|
2020-12-28 20:52:41 -06:00
|
|
|
return (
|
|
|
|
<Row>
|
|
|
|
<Col sm={10} smOffset={1} xs={12}>
|
|
|
|
<ul data-test-label='learn-curriculum-map'>
|
|
|
|
{nodes.map((node, i) => (
|
|
|
|
<li key={i}>
|
|
|
|
<Link
|
|
|
|
className='btn link-btn btn-lg'
|
|
|
|
to={`/learn/${dasherize(node.superBlock)}/`}
|
|
|
|
>
|
2021-01-13 07:09:45 -06:00
|
|
|
<div style={linkSpacingStyle}>
|
|
|
|
<ImageLoader
|
|
|
|
alt='building a website'
|
|
|
|
offsetVertical={500}
|
|
|
|
src={i18next.t(`intro:${dasherize(node.superBlock)}.icon`)}
|
|
|
|
style={iconStyle}
|
|
|
|
/>
|
|
|
|
{createSuperBlockTitle(node.superBlock)}
|
|
|
|
</div>
|
2020-12-28 20:52:41 -06:00
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
);
|
|
|
|
}
|
2019-10-04 18:32:35 +03:00
|
|
|
|
2021-01-13 07:09:45 -06:00
|
|
|
export function Map({ forLanding = false, currentSuperBlock = '' }) {
|
2020-12-28 20:52:41 -06:00
|
|
|
/*
|
|
|
|
* this query gets the first challenge from each block and the second block
|
|
|
|
* from each superblock, leaving you with one challenge from each
|
|
|
|
* superblock
|
|
|
|
*/
|
|
|
|
const data = useStaticQuery(graphql`
|
|
|
|
query SuperBlockNodes {
|
|
|
|
allChallengeNode(
|
|
|
|
sort: { fields: [superOrder] }
|
|
|
|
filter: { order: { eq: 2 }, challengeOrder: { eq: 1 } }
|
|
|
|
) {
|
|
|
|
nodes {
|
|
|
|
superBlock
|
|
|
|
dashedName
|
|
|
|
}
|
2019-10-22 13:38:19 +03:00
|
|
|
}
|
2019-10-04 18:32:35 +03:00
|
|
|
}
|
2020-12-28 20:52:41 -06:00
|
|
|
`);
|
2019-10-04 18:32:35 +03:00
|
|
|
|
2020-12-28 20:52:41 -06:00
|
|
|
let nodes = data.allChallengeNode.nodes;
|
2019-10-04 18:32:35 +03:00
|
|
|
|
2020-12-28 20:52:41 -06:00
|
|
|
return (
|
|
|
|
<div className='map-ui' data-test-label='learn-curriculum-map'>
|
2021-01-13 07:09:45 -06:00
|
|
|
{forLanding
|
|
|
|
? renderLandingMap(nodes)
|
|
|
|
: renderLearnMap(nodes, currentSuperBlock)}
|
2020-12-28 20:52:41 -06:00
|
|
|
</div>
|
|
|
|
);
|
2019-09-21 19:09:48 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
Map.displayName = 'Map';
|
|
|
|
Map.propTypes = propTypes;
|
|
|
|
|
2020-12-28 20:52:41 -06:00
|
|
|
export default Map;
|