Repository: freeCodeCamp/freeCodeCamp
File: client/src/templates/Introduction/super-block-intro.tsx (TypeScript)

Code before:

  const allChallenges = useMemo(
    () => nodes.map(({ challenge }) => challenge),
    [nodes]
  );
  const challenges = useMemo(
    () => allChallenges.filter(c => c.superBlock === superBlock),
    [allChallenges, superBlock]
  );
  const blocks = uniq(challenges.map(({ block }) => block));

  const completedChallenges = useMemo(
    () =>
      allCompletedChallenges.filter(completedChallenge =>
        challenges.some(c => c.id === completedChallenge.id)
      ),
    [challenges, allCompletedChallenges]
  );

  const i18nTitle = getSuperBlockTitleForMap(superBlock);

  const superblockWithoutCert = [
    SuperBlocks.RespWebDesign,
    SuperBlocks.CodingInterviewPrep,
    SuperBlocks.TheOdinProject,
    SuperBlocks.ProjectEuler,
    SuperBlocks.A2English,
    SuperBlocks.RosettaCode,
    SuperBlocks.PythonForEverybody
  ];

  const superBlockWithAccordionView = [SuperBlocks.FullStackDeveloper];

  const getChosenBlock = (): string => {
    // if coming from breadcrumb click
    if (
      location.state &&
      typeof location.state === 'object' &&
      Object.prototype.hasOwnProperty.call(
        location.state,
        'breadcrumbBlockClick'
      )
    ) {
      return location.state.breadcrumbBlockClick;
    }

    // if the URL includes a hash
    if (location.hash) {
      const dashedBlock = location.hash.replace('#', '').replace('/', '');
      return dashedBlock;
    }

Review comment (suggestion):
With `firstChallenge` being:

```ts
const firstChallenge = nodes[0]?.challenge;
```

and `nodes[0]` is step 1 of Cat Photo App, `firstChallenge?.block` would always be the Cat Photo App block, which is only applicable to the RWD super block.

I changed this to `blocks[0]` instead, with `blocks` is the blocks of the target super block.

Code after:
  } = props;

  const allChallenges = useMemo(
    () => nodes.map(({ challenge }) => challenge),
    [nodes]
  );
  const superBlockChallenges = useMemo(
    () => allChallenges.filter(c => c.superBlock === superBlock),
    [allChallenges, superBlock]
  );
  const blocks = uniq(superBlockChallenges.map(({ block }) => block));

  const completedChallenges = useMemo(
    () =>
      allCompletedChallenges.filter(completedChallenge =>
        superBlockChallenges.some(c => c.id === completedChallenge.id)
      ),
    [superBlockChallenges, allCompletedChallenges]
  );

  const i18nTitle = getSuperBlockTitleForMap(superBlock);

  const showCertification = liveCerts.some(
    cert => superBlockToCertMap[superBlock] === cert.certSlug
  );

  const superBlockWithAccordionView = [SuperBlocks.FullStackDeveloper];

  const getChosenBlock = (): string => {
    // if coming from breadcrumb click
    if (
      location.state &&
      typeof location.state === 'object' &&
      Object.prototype.hasOwnProperty.call(
        location.state,
        'breadcrumbBlockClick'
      )
    ) {
      return location.state.breadcrumbBlockClick;
    }

    // if the URL includes a hash
    if (location.hash) {
      const dashedBlock = location.hash.replace('#', '').replace('/', '');
      return dashedBlock;
    }

    if (isSignedIn) {
      // see if currentChallenge is in this superBlock
      const currentChallenge = superBlockChallenges.find(
        challenge => challenge.id === currentChallengeId