Files
freeCodeCamp/client/src/pages/learn.js

157 lines
3.6 KiB
JavaScript
Raw Normal View History

2018-03-26 13:01:24 +01:00
import React from 'react';
2018-04-06 14:51:52 +01:00
import PropTypes from 'prop-types';
import { createSelector } from 'reselect';
2019-02-21 20:55:36 +05:30
import { graphql } from 'gatsby';
2018-04-06 14:51:52 +01:00
import Helmet from 'react-helmet';
import { connect } from 'react-redux';
import { Row, Col } from '@freecodecamp/react-bootstrap';
2018-03-26 13:01:24 +01:00
import { userFetchStateSelector, isSignedInSelector } from '../redux';
import LearnLayout from '../components/layouts/Learn';
import Login from '../components/Header/components/Login';
import { Link, Spacer, Loader } from '../components/helpers';
import Map from '../components/Map';
2018-04-06 14:51:52 +01:00
import './learn.css';
2018-04-06 14:51:52 +01:00
import {
ChallengeNode,
AllChallengeNode,
AllMarkdownRemark
} from '../redux/propTypes';
const mapStateToProps = createSelector(
userFetchStateSelector,
isSignedInSelector,
(fetchState, isSignedIn) => ({
fetchState,
isSignedIn
})
);
2018-04-06 14:51:52 +01:00
const propTypes = {
data: PropTypes.shape({
challengeNode: ChallengeNode,
allChallengeNode: AllChallengeNode,
allMarkdownRemark: AllMarkdownRemark
}),
fetchState: PropTypes.shape({
pending: PropTypes.bool,
complete: PropTypes.bool,
errored: PropTypes.bool
}),
isSignedIn: PropTypes.bool
};
const BigCallToAction = isSignedIn => {
if (!isSignedIn) {
return (
<>
<Spacer size={2} />
<Row>
<Col sm={8} smOffset={2} xs={12}>
<Login className={'text-center'}>Sign in to save progress.</Login>
</Col>
</Row>
</>
);
}
return '';
2018-04-06 14:51:52 +01:00
};
const IndexPage = ({
fetchState: { pending, complete },
isSignedIn,
data: {
challengeNode: {
fields: { slug }
},
allChallengeNode: { edges },
allMarkdownRemark: { edges: mdEdges }
}
}) => {
if (pending && !complete) {
return <Loader fullScreen={true} />;
}
return (
<LearnLayout>
<div className='learn-page-wrapper'>
<Helmet title='Learn | freeCodeCamp.org' />
{BigCallToAction(isSignedIn)}
<Spacer size={2} />
<h1 className='text-center'>Welcome to the freeCodeCamp curriculum</h1>
<p>
We have thousands of coding lessons to help you improve your skills.
</p>
<p>
You can earn each certification by completing its 5 final projects.
</p>
<p>
And yes - all of this is 100% free, thanks to the thousands of campers
who{' '}
<Link external={true} to='/donate'>
donate
</Link>{' '}
to our nonprofit.
</p>
<p>
If you are new to coding, we recommend you{' '}
<Link to={slug}>start at the beginning</Link>.
</p>
<Map
introNodes={mdEdges.map(({ node }) => node)}
nodes={edges
.map(({ node }) => node)
.filter(({ isPrivate }) => !isPrivate)}
/>
</div>
</LearnLayout>
);
};
2018-03-26 13:01:24 +01:00
2018-04-06 14:51:52 +01:00
IndexPage.displayName = 'IndexPage';
IndexPage.propTypes = propTypes;
export default connect(mapStateToProps)(IndexPage);
2018-04-06 14:51:52 +01:00
export const query = graphql`
query FirstChallenge {
challengeNode(order: { eq: 0 }, challengeOrder: { eq: 0 }) {
2018-04-06 14:51:52 +01:00
fields {
slug
}
}
allChallengeNode(sort: { fields: [superOrder, order, challengeOrder] }) {
edges {
node {
fields {
slug
blockName
}
id
block
title
isRequired
superBlock
dashedName
}
}
}
allMarkdownRemark(filter: { frontmatter: { block: { ne: null } } }) {
edges {
node {
frontmatter {
title
block
}
fields {
slug
}
}
2018-04-06 14:51:52 +01:00
}
}
}
`;