2021-06-15 10:37:13 -05:00
|
|
|
/* eslint-disable max-len */
|
|
|
|
|
|
|
|
// Package Utilities
|
2021-08-02 15:39:40 +02:00
|
|
|
import { graphql } from 'gatsby';
|
2021-06-15 10:37:13 -05:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import Helmet from 'react-helmet';
|
2021-08-02 15:39:40 +02:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { bindActionCreators } from 'redux';
|
2021-06-25 09:59:33 -05:00
|
|
|
import type { Dispatch } from 'redux';
|
2021-11-17 08:19:24 -06:00
|
|
|
import { createSelector } from 'reselect';
|
2021-06-15 10:37:13 -05:00
|
|
|
|
|
|
|
// Local Utilities
|
2021-06-29 19:31:22 +05:30
|
|
|
import LearnLayout from '../../../components/layouts/learn';
|
2021-11-17 08:19:24 -06:00
|
|
|
import { webhookTokenSelector } from '../../../redux';
|
2021-11-09 19:51:46 +05:30
|
|
|
import { ChallengeNode, ChallengeMeta } from '../../../redux/prop-types';
|
2021-06-15 10:37:13 -05:00
|
|
|
import { updateChallengeMeta, challengeMounted } from '../redux';
|
|
|
|
// Redux
|
2021-11-17 08:19:24 -06:00
|
|
|
|
|
|
|
const mapStateToProps = createSelector(
|
|
|
|
webhookTokenSelector,
|
|
|
|
(webhookToken: string | null) => ({
|
|
|
|
webhookToken
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2021-06-25 09:59:33 -05:00
|
|
|
const mapDispatchToProps = (dispatch: Dispatch) =>
|
2021-06-15 10:37:13 -05:00
|
|
|
bindActionCreators(
|
|
|
|
{
|
|
|
|
updateChallengeMeta,
|
|
|
|
challengeMounted
|
|
|
|
},
|
|
|
|
dispatch
|
|
|
|
);
|
|
|
|
|
2021-06-25 09:59:33 -05:00
|
|
|
// Types
|
|
|
|
interface ShowCodeAllyProps {
|
2021-11-09 19:51:46 +05:30
|
|
|
data: { challengeNode: ChallengeNode };
|
2021-06-25 09:59:33 -05:00
|
|
|
pageContext: {
|
2021-11-09 19:51:46 +05:30
|
|
|
challengeMeta: ChallengeMeta;
|
2021-06-25 09:59:33 -05:00
|
|
|
};
|
2021-11-09 19:51:46 +05:30
|
|
|
updateChallengeMeta: (arg0: ChallengeMeta) => void;
|
2021-11-17 08:19:24 -06:00
|
|
|
webhookToken: string | null;
|
2021-06-25 09:59:33 -05:00
|
|
|
}
|
2021-06-15 10:37:13 -05:00
|
|
|
|
|
|
|
// Component
|
2021-06-25 09:59:33 -05:00
|
|
|
class ShowCodeAlly extends Component<ShowCodeAllyProps> {
|
|
|
|
static displayName: string;
|
|
|
|
componentDidMount(): void {
|
2021-06-15 10:37:13 -05:00
|
|
|
const {
|
|
|
|
updateChallengeMeta,
|
|
|
|
data: {
|
2021-12-14 19:11:20 +01:00
|
|
|
challengeNode: {
|
|
|
|
challenge: { challengeType, title }
|
|
|
|
}
|
2021-06-15 10:37:13 -05:00
|
|
|
},
|
|
|
|
pageContext: { challengeMeta }
|
|
|
|
} = this.props;
|
|
|
|
updateChallengeMeta({ ...challengeMeta, title, challengeType });
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
2021-11-17 08:19:24 -06:00
|
|
|
data: {
|
|
|
|
challengeNode: {
|
2021-12-14 19:11:20 +01:00
|
|
|
challenge: {
|
|
|
|
title,
|
|
|
|
fields: { blockName },
|
|
|
|
url
|
|
|
|
}
|
2021-11-17 08:19:24 -06:00
|
|
|
}
|
|
|
|
},
|
|
|
|
webhookToken = null
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const envVariables = webhookToken
|
|
|
|
? `&envVariables=CODEROAD_WEBHOOK_TOKEN=${webhookToken}`
|
|
|
|
: '';
|
2021-06-15 10:37:13 -05:00
|
|
|
|
|
|
|
return (
|
|
|
|
<LearnLayout>
|
|
|
|
<Helmet title={`${blockName}: ${title} | freeCodeCamp.org`} />
|
|
|
|
<iframe
|
2021-09-23 17:31:56 +02:00
|
|
|
className='codeally-frame'
|
2021-06-25 09:59:33 -05:00
|
|
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
2021-09-23 17:31:56 +02:00
|
|
|
sandbox='allow-modals allow-forms allow-popups allow-scripts allow-same-origin'
|
2021-11-17 08:19:24 -06:00
|
|
|
src={`https://codeally.io/embed/?repoUrl=${url}${envVariables}`}
|
2021-06-15 10:37:13 -05:00
|
|
|
title='Editor'
|
|
|
|
/>
|
|
|
|
</LearnLayout>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ShowCodeAlly.displayName = 'ShowCodeAlly';
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(ShowCodeAlly);
|
|
|
|
|
|
|
|
// GraphQL
|
|
|
|
export const query = graphql`
|
|
|
|
query CodeAllyChallenge($slug: String!) {
|
2021-12-14 19:11:20 +01:00
|
|
|
challengeNode(challenge: { fields: { slug: { eq: $slug } } }) {
|
|
|
|
challenge {
|
|
|
|
title
|
|
|
|
challengeType
|
|
|
|
url
|
|
|
|
fields {
|
|
|
|
blockName
|
|
|
|
}
|
2021-06-15 10:37:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|