feat(client): ts-migrate LearnLayout component (#42644)

* feat(client) Renamed Learn.js to learn.tsx

* feat(client) ts-migrate LearnLayout Component

* rename types for convention

* fix(client) disable ts error for DonationModal usage

- DonationModal migration required typescript to fix error hence disable ts error in LearnLayout component

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>
This commit is contained in:
ABHINAV SHARMA
2021-06-29 19:31:22 +05:30
committed by Mrugesh Mohapatra
parent 6b52d6c331
commit de261a2b58
9 changed files with 32 additions and 26 deletions

View File

@ -1,3 +1,3 @@
export { default as CertificationLayout } from './Certification'; export { default as CertificationLayout } from './Certification';
export { default as DefaultLayout } from './Default'; export { default as DefaultLayout } from './Default';
export { default as LearnLayout } from './Learn'; export { default as LearnLayout } from './learn';

View File

@ -1,5 +1,4 @@
import React, { Fragment, Component } from 'react'; import React, { Fragment, Component } from 'react';
import PropTypes from 'prop-types';
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { Helmet } from 'react-helmet'; import { Helmet } from 'react-helmet';
@ -18,11 +17,21 @@ import './prism-night.css';
import 'react-reflex/styles.css'; import 'react-reflex/styles.css';
import './learn.css'; import './learn.css';
type FetchState = {
pending: boolean;
complete: boolean;
errored: boolean;
};
type User = {
acceptedPrivacyTerms: boolean;
};
const mapStateToProps = createSelector( const mapStateToProps = createSelector(
userFetchStateSelector, userFetchStateSelector,
isSignedInSelector, isSignedInSelector,
userSelector, userSelector,
(fetchState, isSignedIn, user) => ({ (fetchState: FetchState, isSignedIn, user: User) => ({
fetchState, fetchState,
isSignedIn, isSignedIn,
user user
@ -35,7 +44,17 @@ const mapDispatchToProps = {
const RedirectEmailSignUp = createRedirect('/email-sign-up'); const RedirectEmailSignUp = createRedirect('/email-sign-up');
class LearnLayout extends Component { type LearnLayoutProps = {
isSignedIn?: boolean;
fetchState: FetchState;
user: User;
tryToShowDonationModal: () => void;
children?: React.ReactNode;
};
class LearnLayout extends Component<LearnLayoutProps> {
static displayName = 'LearnLayout';
componentDidMount() { componentDidMount() {
this.props.tryToShowDonationModal(); this.props.tryToShowDonationModal();
} }
@ -69,25 +88,12 @@ class LearnLayout extends Component {
<meta content='noindex' name='robots' /> <meta content='noindex' name='robots' />
</Helmet> </Helmet>
<main id='learn-app-wrapper'>{children}</main> <main id='learn-app-wrapper'>{children}</main>
{/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
/* @ts-ignore */}
<DonateModal /> <DonateModal />
</Fragment> </Fragment>
); );
} }
} }
LearnLayout.displayName = 'LearnLayout';
LearnLayout.propTypes = {
children: PropTypes.any,
fetchState: PropTypes.shape({
pending: PropTypes.bool,
complete: PropTypes.bool,
errored: PropTypes.bool
}),
isSignedIn: PropTypes.bool,
tryToShowDonationModal: PropTypes.func.isRequired,
user: PropTypes.shape({
acceptedPrivacyTerms: PropTypes.bool
})
};
export default connect(mapStateToProps, mapDispatchToProps)(LearnLayout); export default connect(mapStateToProps, mapDispatchToProps)(LearnLayout);

View File

@ -7,7 +7,7 @@ import { connect } from 'react-redux';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { Spacer } from '../components/helpers'; import { Spacer } from '../components/helpers';
import LearnLayout from '../components/layouts/Learn'; import LearnLayout from '../components/layouts/learn';
import Map from '../components/Map'; import Map from '../components/Map';
import Intro from '../components/Intro'; import Intro from '../components/Intro';
import { import {

View File

@ -12,7 +12,7 @@ import Media from 'react-responsive';
import { withTranslation } from 'react-i18next'; import { withTranslation } from 'react-i18next';
// Local Utilities // Local Utilities
import LearnLayout from '../../../components/layouts/Learn'; import LearnLayout from '../../../components/layouts/learn';
import MultifileEditor from './MultifileEditor'; import MultifileEditor from './MultifileEditor';
import Preview from '../components/Preview'; import Preview from '../components/Preview';
import SidePanel from '../components/Side-Panel'; import SidePanel from '../components/Side-Panel';

View File

@ -9,7 +9,7 @@ import { graphql } from 'gatsby';
import type { Dispatch } from 'redux'; import type { Dispatch } from 'redux';
// Local Utilities // Local Utilities
import LearnLayout from '../../../components/layouts/Learn'; import LearnLayout from '../../../components/layouts/learn';
import { import {
ChallengeNodeType, ChallengeNodeType,
ChallengeMetaType ChallengeMetaType

View File

@ -23,7 +23,7 @@ import {
updateSolutionFormValues updateSolutionFormValues
} from '../../redux'; } from '../../redux';
import { getGuideUrl } from '../../utils'; import { getGuideUrl } from '../../utils';
import LearnLayout from '../../../../components/layouts/Learn'; import LearnLayout from '../../../../components/layouts/learn';
import ChallengeTitle from '../../components/challenge-title'; import ChallengeTitle from '../../components/challenge-title';
import ChallengeDescription from '../../components/Challenge-Description'; import ChallengeDescription from '../../components/Challenge-Description';
import TestSuite from '../../components/Test-Suite'; import TestSuite from '../../components/Test-Suite';

View File

@ -24,7 +24,7 @@ import {
updateSolutionFormValues updateSolutionFormValues
} from '../../redux'; } from '../../redux';
import { getGuideUrl } from '../../utils'; import { getGuideUrl } from '../../utils';
import LearnLayout from '../../../../components/layouts/Learn'; import LearnLayout from '../../../../components/layouts/learn';
import ChallengeTitle from '../../components/challenge-title'; import ChallengeTitle from '../../components/challenge-title';
import ChallengeDescription from '../../components/Challenge-Description'; import ChallengeDescription from '../../components/Challenge-Description';
import Spacer from '../../../../components/helpers/spacer'; import Spacer from '../../../../components/helpers/spacer';

View File

@ -17,7 +17,7 @@ import {
ChallengeNodeType, ChallengeNodeType,
ChallengeMetaType ChallengeMetaType
} from '../../../redux/prop-types'; } from '../../../redux/prop-types';
import LearnLayout from '../../../components/layouts/Learn'; import LearnLayout from '../../../components/layouts/learn';
import ChallengeTitle from '../components/challenge-title'; import ChallengeTitle from '../components/challenge-title';
import ChallengeDescription from '../components/Challenge-Description'; import ChallengeDescription from '../components/Challenge-Description';
import Spacer from '../../../components/helpers/spacer'; import Spacer from '../../../components/helpers/spacer';

View File

@ -5,7 +5,7 @@ import Helmet from 'react-helmet';
import { Grid, ListGroup, ListGroupItem } from '@freecodecamp/react-bootstrap'; import { Grid, ListGroup, ListGroupItem } from '@freecodecamp/react-bootstrap';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import LearnLayout from '../../components/layouts/Learn'; import LearnLayout from '../../components/layouts/learn';
import FullWidthRow from '../../components/helpers/full-width-row'; import FullWidthRow from '../../components/helpers/full-width-row';
import ButtonSpacer from '../../components/helpers/button-spacer'; import ButtonSpacer from '../../components/helpers/button-spacer';
import { MarkdownRemark, AllChallengeNode } from '../../redux/prop-types'; import { MarkdownRemark, AllChallengeNode } from '../../redux/prop-types';