Repository: freeCodeCamp/freeCodeCamp
File: client/src/redux/selectors.js (JavaScript)

Code before:
import { createSelector } from 'reselect';

import { chapterBasedSuperBlocks } from '../../../shared-dist/config/curriculum';
import { randomBetween } from '../utils/random-between';
import { getSessionChallengeData } from '../utils/session-storage';
import { superBlockStructuresSelector } from '../templates/Introduction/redux';
import { ns as MainApp } from './action-types';

export const savedChallengesSelector = state =>
  userSelector(state)?.savedChallenges || [];
export const completedChallengesSelector = state =>
  userSelector(state)?.completedChallenges || [];
export const completedDailyCodingChallengesSelector = state =>
  userSelector(state)?.completedDailyCodingChallenges || [];
export const userIdSelector = state => userSelector(state)?.id;
export const partiallyCompletedChallengesSelector = state =>
  userSelector(state)?.partiallyCompletedChallenges || [];
export const currentChallengeIdSelector = state =>
  state[MainApp].currentChallengeId;
export const isRandomCompletionThresholdSelector = state =>
  state[MainApp].isRandomCompletionThreshold;
export const isDonatingSelector = state => userSelector(state)?.isDonating;
export const isOnlineSelector = state => state[MainApp].isOnline;
export const isServerOnlineSelector = state => state[MainApp].isServerOnline;
export const isSignedInSelector = state => !!userSelector(state);
export const isDonationModalOpenSelector = state =>
  state[MainApp].showDonationModal;
export const isSignoutModalOpenSelector = state =>

Review comment (suggestion):
Just FYI, I'm currently trying to get rid of `chapterBasedSuperBlocks` as a variable. The motivation is similar to this PR: there already is a source of truth. If the superblock structure has a chapter in it, it's a chapter based superblock.

Don't worry about it for this PR, but if you can try to avoid using `chapterBasedSuperBlocks`, that would help me out. That said, I get that it's often necessary.

Code after:
import { createSelector } from 'reselect';

import { randomBetween } from '../utils/random-between';
import { getSessionChallengeData } from '../utils/session-storage';
import { superBlockStructuresSelector } from '../templates/Introduction/redux';
import { ns as MainApp } from './action-types';

export const savedChallengesSelector = state =>
  userSelector(state)?.savedChallenges || [];
export const completedChallengesSelector = state =>
  userSelector(state)?.completedChallenges || [];
export const completedDailyCodingChallengesSelector = state =>
  userSelector(state)?.completedDailyCodingChallenges || [];
export const userIdSelector = state => userSelector(state)?.id;
export const partiallyCompletedChallengesSelector = state =>
  userSelector(state)?.partiallyCompletedChallenges || [];
export const currentChallengeIdSelector = state =>
  state[MainApp].currentChallengeId;
export const isRandomCompletionThresholdSelector = state =>
  state[MainApp].isRandomCompletionThreshold;
export const isDonatingSelector = state => userSelector(state)?.isDonating;
export const isOnlineSelector = state => state[MainApp].isOnline;
export const isServerOnlineSelector = state => state[MainApp].isServerOnline;
export const isSignedInSelector = state => !!userSelector(state);
export const isDonationModalOpenSelector = state =>
  state[MainApp].showDonationModal;
export const isSignoutModalOpenSelector = state =>
  state[MainApp].showSignoutModal;