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/LinkButton';
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 (
);
}
function renderLearnMap(nodes, currentSuperBlock = '') {
nodes = nodes.filter(node => node.superBlock !== currentSuperBlock);
return curriculumLocale === 'english' ? (
) : (
{nodes
.filter(node => isAuditedCert(curriculumLocale, node.superBlock))
.map((node, i) => (
{generateIconComponent(node.superBlock, 'map-icon')}
{createSuperBlockTitle(node.superBlock)}
))}
{i18next.t('learn.help-translate')}
{i18next.t('learn.help-translate-link')}
{nodes
.filter(node => !isAuditedCert(curriculumLocale, node.superBlock))
.map((node, i) => (
{generateIconComponent(node.superBlock, 'map-icon')}
{createSuperBlockTitle(node.superBlock)}
))}
);
}
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 (
{forLanding
? renderLandingMap(nodes)
: renderLearnMap(nodes, currentSuperBlock)}
);
}
Map.displayName = 'Map';
Map.propTypes = propTypes;
export default Map;