Files
freeCodeCamp/client/src/components/Map/index.js
Parth Parth 0a3a5e7a53 feat(client): migrate icons to TS (#42453)
* migrate files and update tests

fix: use more memory for gatsby develop (#42433)

feat(client): remove whitespace from calculated values (#42400)

* feat(client?): remove whitespace for calculated values

* feat(client): remove whitespace from styledeclaration

* do not automatically strip

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>

* fix: include all properties of CSSStyleDeclaration

* fix test for getPropVal

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>

fix: get showUpcomingChange from env.json (#42440)

fix(client): display legacy certs like current ones (#42038)

* fix: display legacy certs like the current ones

* fix: link projects in legacy certs to project pages

* fix: update tests to changed legacy cert display

* fix: update tests for removed legacy certs forms

* fix: display legacy certs like the current ones

* fix: submit projects for cert on projects pages

* fix: remove legacy certs form submitting handling

* fix: move claiming cert setup before both tests

* fix: remove legacy cert update props and actions

* fix: remove legacy cert updates from api

* fix: correct merge conflict

fix(curriculum): rework Project Euler 98 (#42423)

* fix: rework challenge to use argument in function

* fix: add solution

* fix: use MathJax to improve math notation

fix(curriculum): rework Project Euler 56 (#42364)

* fix: rework challenge to use argument in function

* fix: add solution

* fix: use MathJax to improve look of math notation

fix(curriculum): correct small english typo (#42447)

chore: group together monaco-editor and plugin (#42443)

This should get renovate to create PRs where both are modified.

fix(deps): update dependency algoliasearch to v4.9.2 (#42432)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

migrate files and update tests

Algorithm moved to TSX

first ten files renamed to tsx

first 10 migration complete

first 20 files renamed

migrate some files. rename all

test

index.tsx forced to ignore ts issues

rename and migrate all files

update tests

* remove missed propType declarations

* kebab-caseify

* fi xlinting

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
Co-authored-by: Parth Parth <thecodingaviator@users.noreply.github.com>
Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>
2021-06-30 20:50:56 +05:30

158 lines
4.5 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import { graphql, useStaticQuery } from 'gatsby';
import i18next from 'i18next';
import { generateIconComponent } from '../../assets/icons';
import { Link, Spacer } from '../helpers';
import LinkButton from '../../assets/icons/link-button';
import './map.css';
import { isAuditedCert } from '../../../../utils/is-audited';
import envData from '../../../../config/env.json';
const { curriculumLocale } = envData;
const propTypes = {
currentSuperBlock: PropTypes.string,
forLanding: PropTypes.bool
};
function createSuperBlockTitle(superBlock) {
const superBlockTitle = i18next.t(`intro:${superBlock}.title`);
return superBlock === 'coding-interview-prep'
? i18next.t('learn.cert-map-estimates.coding-prep', {
title: superBlockTitle
})
: i18next.t('learn.cert-map-estimates.certs', { title: superBlockTitle });
}
const linkSpacingStyle = {
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center'
};
function renderLandingMap(nodes) {
nodes = nodes.filter(node => node.superBlock !== 'coding-interview-prep');
return (
<ul data-test-label='certifications'>
{nodes.map((node, i) => (
<li key={i}>
<Link
className='btn link-btn btn-lg'
to={`/learn/${node.superBlock}/`}
>
<div style={linkSpacingStyle}>
{generateIconComponent(node.superBlock, 'map-icon')}
{i18next.t(`intro:${node.superBlock}.title`)}
</div>
<LinkButton />
</Link>
</li>
))}
</ul>
);
}
function renderLearnMap(nodes, currentSuperBlock = '') {
nodes = nodes.filter(node => node.superBlock !== currentSuperBlock);
return curriculumLocale === 'english' ? (
<ul data-test-label='learn-curriculum-map'>
{nodes.map((node, i) => (
<li key={i}>
<Link
className='btn link-btn btn-lg'
to={`/learn/${node.superBlock}/`}
>
<div style={linkSpacingStyle}>
{generateIconComponent(node.superBlock, 'map-icon')}
{createSuperBlockTitle(node.superBlock)}
</div>
</Link>
</li>
))}
</ul>
) : (
<ul data-test-label='learn-curriculum-map'>
{nodes
.filter(node => isAuditedCert(curriculumLocale, node.superBlock))
.map((node, i) => (
<li key={i}>
<Link
className='btn link-btn btn-lg'
to={`/learn/${node.superBlock}/`}
>
<div style={linkSpacingStyle}>
{generateIconComponent(node.superBlock, 'map-icon')}
{createSuperBlockTitle(node.superBlock)}
</div>
</Link>
</li>
))}
<hr />
<div style={{ textAlign: 'center' }}>
<p style={{ marginBottom: 0 }}>{i18next.t('learn.help-translate')} </p>
<Link
external={true}
sameTab={false}
to={i18next.t('links:help-translate-link-url')}
>
{i18next.t('learn.help-translate-link')}
</Link>
<Spacer />
</div>
{nodes
.filter(node => !isAuditedCert(curriculumLocale, node.superBlock))
.map((node, i) => (
<li key={i}>
<Link
className='btn link-btn btn-lg'
to={`/learn/${node.superBlock}/`}
>
<div style={linkSpacingStyle}>
{generateIconComponent(node.superBlock, 'map-icon')}
{createSuperBlockTitle(node.superBlock)}
</div>
</Link>
</li>
))}
</ul>
);
}
export function Map({ forLanding = false, currentSuperBlock = '' }) {
/*
* 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
}
}
}
`);
let nodes = data.allChallengeNode.nodes;
return (
<div className='map-ui' data-test-label='learn-curriculum-map'>
{forLanding
? renderLandingMap(nodes)
: renderLearnMap(nodes, currentSuperBlock)}
</div>
);
}
Map.displayName = 'Map';
Map.propTypes = propTypes;
export default Map;