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

Code before:
  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 = challenges.find(
        challenge => challenge.id === currentChallengeId
      );

      if (currentChallenge) return currentChallenge.block;

      // If the current challenge isn't in the super block
      // Find the most recently completed challenge of the super block,
      // which is the last item of the `completedChallenges` array.
      if (!isEmpty(completedChallenges)) {
        const lastCompletedChallengeId = last(completedChallenges)?.id;

        const lastCompletedChallenge = nodes.find(
          node => node.challenge.id === lastCompletedChallengeId
        )?.challenge;

        if (lastCompletedChallenge) return lastCompletedChallenge.block;
      }

      return blocks[0];
    }

    return blocks[0];
  };

  const initializeExpandedState = () => {
    const { resetExpansion, toggleBlock } = props;


Review comment (performance):
Just a minor performance improvement here.

Instead of finding the `currentChallengeId` in all challenges (`nodes`), I changed it to just all challenges of the target super block (`challenges`).

Code after:
      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
      );

      if (currentChallenge) return currentChallenge.block;

      // If the current challenge isn't in the super block
      // Find the most recently completed challenge of the super block,
      // which is the last item of the `completedChallenges` array.
      if (!isEmpty(completedChallenges)) {
        const lastCompletedChallengeId = last(completedChallenges)?.id;

        const lastCompletedChallenge = allChallenges.find(
          ({ id }) => id === lastCompletedChallengeId
        );

        if (lastCompletedChallenge) return lastCompletedChallenge.block;
      }
    }

    return blocks[0];
  };

  const initializeExpandedState = () => {
    const { resetExpansion, toggleBlock } = props;

    resetExpansion();
    return toggleBlock(getChosenBlock());
  };

  const chosenBlock = getChosenBlock();

  const onCertificationDonationAlertClick = () => {