feat: simplify client logic (#46870)

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
Ilenia
2022-07-14 10:41:20 +02:00
committed by GitHub
parent 709018571b
commit 0a2d0733a2
5 changed files with 26 additions and 26 deletions
@@ -40,7 +40,10 @@ import {
} from '../../../redux/prop-types';
import { editorToneOptions } from '../../../utils/tone/editor-config';
import { editorNotes } from '../../../utils/tone/editor-notes';
import { challengeTypes, isProject } from '../../../../utils/challenge-types';
import {
challengeTypes,
isFinalProject
} from '../../../../utils/challenge-types';
import {
canFocusEditorSelector,
challengeMetaSelector,
@@ -430,7 +433,7 @@ const Editor = (props: EditorProps): JSX.Element => {
/* eslint-disable no-bitwise */
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter],
run: () => {
if (props.usesMultifileEditor && !isProject(props.challengeType)) {
if (props.usesMultifileEditor && !isFinalProject(props.challengeType)) {
if (challengeIsComplete()) {
tryToSubmitChallenge();
} else {
@@ -15,7 +15,7 @@ import {
openModal
} from '../redux';
import './hotkeys.css';
import { isProject } from '../../../../utils/challenge-types';
import { isFinalProject } from '../../../../utils/challenge-types';
const mapStateToProps = createSelector(
canFocusEditorSelector,
@@ -102,7 +102,7 @@ function Hotkeys({
if (
usesMultifileEditor &&
typeof challengeType == 'number' &&
!isProject(challengeType)
!isFinalProject(challengeType)
) {
if (testsArePassing) {
submitChallenge();
@@ -10,7 +10,7 @@ import { Dispatch } from 'redux';
import { createSelector } from 'reselect';
import { dasherize } from '../../../../../utils/slugs';
import { isProject } from '../../../../utils/challenge-types';
import { isFinalProject } from '../../../../utils/challenge-types';
import Login from '../../../components/Header/components/Login';
import {
isSignedInSelector,
@@ -284,7 +284,7 @@ export class CompletionModalInner extends Component<
}
interface Options {
isCertificationBlock: boolean;
isFinalProjectBlock: boolean;
}
interface CertificateNode {
@@ -348,9 +348,7 @@ const useCurrentBlockIds = (
.filter(edge => edge.node.challenge.block === block)
.map(edge => edge.node.challenge.id);
return options?.isCertificationBlock
? currentCertificateIds
: currentBlockIds;
return options?.isFinalProjectBlock ? currentCertificateIds : currentBlockIds;
};
const CompletionModal = (props: CompletionModalsProps) => {
@@ -358,7 +356,7 @@ const CompletionModal = (props: CompletionModalsProps) => {
props.block || '',
props.certification || '',
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
{ isCertificationBlock: isProject(props.challengeType) }
{ isFinalProjectBlock: isFinalProject(props.challengeType) }
);
return <CompletionModalInner currentBlockIds={currentBlockIds} {...props} />;
};
@@ -18,6 +18,10 @@ import { ChallengeNode, CompletedChallenge } from '../../../redux/prop-types';
import { playTone } from '../../../utils/tone';
import { makeExpandedBlockSelector, toggleBlock } from '../redux';
import { isNewJsCert, isNewRespCert } from '../../../utils/is-a-cert';
import {
isCodeAllyPractice,
isFinalProject
} from '../../../../utils/challenge-types';
import Challenges from './challenges';
import '../intro.css';
@@ -120,24 +124,12 @@ export class Block extends Component<BlockProps> {
});
const isProjectBlock = challenges.some(({ challenge }) => {
const isJsProject =
[3, 6, 10, 14, 17].includes(challenge.order) &&
challenge.challengeType === 5 &&
blockDashedName !== 'rosetta-code';
const isOtherProject =
challenge.challengeType === 3 ||
challenge.challengeType === 4 ||
challenge.challengeType === 10 ||
challenge.challengeType === 12 ||
challenge.challengeType === 13 ||
challenge.challengeType === 14;
const isTakeHomeProject = blockDashedName === 'take-home-projects';
return (
(isJsProject && !isTakeHomeProject) ||
(isOtherProject && !isTakeHomeProject)
isFinalProject(challenge.challengeType) &&
!isTakeHomeProject &&
isCodeAllyPractice(challenge.challengeType)
);
});
+8 -1
View File
@@ -41,18 +41,25 @@ exports.challengeTypes = {
multifileCertProject
};
exports.isProject = challengeType => {
exports.isFinalProject = challengeType => {
if (typeof challengeType !== 'number')
throw Error('challengeType must be a number');
return (
challengeType === frontEndProject ||
challengeType === backEndProject ||
challengeType === jsProject ||
challengeType === pythonProject ||
challengeType === codeAllyCert ||
challengeType === multifileCertProject
);
};
exports.isCodeAllyPractice = challengeType => {
if (typeof challengeType !== 'number')
throw Error('challengeType must be a number');
return challengeType === codeAllyPractice;
};
// turn challengeType to file ext
exports.pathsMap = {
[html]: 'html',