Repository: freeCodeCamp/freeCodeCamp
File: client/src/components/Progress/progress.tsx (TypeScript)

Code before:
  if (getIsDailyCodingChallenge(challengeType)) {
    const dateParam =
      new URLSearchParams(window.location.search).get('date') || '';

    if (isValidDateString(dateParam)) {
      blockTitle += `: ${formatDisplayDate(dateParam)}`;
    }
  }

  const { challengeNodes, certificateNodes, superBlockStructureNodes } =
    useGetAllChallengeData();

  useEffect(() => {
    updateAllChallengesInfo({ challengeNodes, certificateNodes });

    const structuresMap: Record<string, SuperBlockStructure> = {};
    superBlockStructureNodes.forEach((node: SuperBlockStructure) => {
      structuresMap[node.superBlock] = node;
    });

    // The super block structures are pretty static, so we only want to
    // update them if we don't already have them in the store.
    if (Object.keys(superBlockStructuresFromStore).length === 0) {
      updateSuperBlockStructures(structuresMap);
    }
  }, [
    challengeNodes,
    certificateNodes,
    superBlockStructureNodes,
    updateAllChallengesInfo,
    updateSuperBlockStructures,
    superBlockStructuresFromStore
  ]);

  const totalChallengesInBlock = currentBlockIds?.length ?? 0;
  const meta =
    isCertificationProject && totalChallengesInBlock > 0
      ? t('learn.project-complete', {
          completedChallengesInBlock,
          totalChallengesInBlock
        })
      : t('learn.percent-complete', {
          percent: completedPercent
        });
  return (
    <div
      className='progress-bar-container'
      data-playwright-test-label='progress-bar-container'
    >
      <ProgressInner
        title={blockTitle}

Review comment (suggestion):
It's pretty minor, but you can skip evaluating the `forEach` loop if `superBlockStructuresFromStore` is empty.

Code after:
  if (getIsDailyCodingChallenge(challengeType)) {
    const dateParam =
      new URLSearchParams(window.location.search).get('date') || '';

    if (isValidDateString(dateParam)) {
      blockTitle += `: ${formatDisplayDate(dateParam)}`;
    }
  }

  const { challengeNodes, certificateNodes, superBlockStructureNodes } =
    useGetAllChallengeData();

  useEffect(() => {
    updateAllChallengesInfo({ challengeNodes, certificateNodes });

    const structuresMap: Record<string, SuperBlockStructure> = {};

    // The super block structures are pretty static, so we only want to
    // update them if we don't already have them in the store.
    if (Object.keys(superBlockStructuresFromStore).length === 0) {
      superBlockStructureNodes.forEach((node: SuperBlockStructure) => {
        structuresMap[node.superBlock] = node;
      });

      updateSuperBlockStructures(structuresMap);
    }
  }, [
    challengeNodes,
    certificateNodes,
    superBlockStructureNodes,
    updateAllChallengesInfo,
    updateSuperBlockStructures,
    superBlockStructuresFromStore
  ]);

  const totalChallengesInBlock = currentBlockIds?.length ?? 0;
  const meta =
    isCertificationProject && totalChallengesInBlock > 0
      ? t('learn.project-complete', {
          completedChallengesInBlock,
          totalChallengesInBlock
        })
      : t('learn.percent-complete', {
          percent: completedPercent
        });
  return (
    <div
      className='progress-bar-container'
      data-playwright-test-label='progress-bar-container'
    >
      <ProgressInner