mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-10-24 12:13:31 +08:00
18 lines
686 B
TypeScript
18 lines
686 B
TypeScript
import { isEmpty } from 'lodash-es';
|
|
import { sortChallengeFiles } from '../../../../utils/sort-challengefiles';
|
|
import { ChallengeFiles, FileKey } from '../../../redux/prop-types';
|
|
|
|
export function getTargetEditor(
|
|
challengeFiles: ChallengeFiles
|
|
): FileKey | null {
|
|
if (isEmpty(challengeFiles)) return null;
|
|
|
|
const targetEditor = challengeFiles?.find(
|
|
({ editableRegionBoundaries }) => !isEmpty(editableRegionBoundaries)
|
|
)?.fileKey;
|
|
|
|
// fallback for when there is no editable region.
|
|
/* eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return */
|
|
return targetEditor || sortChallengeFiles(challengeFiles)[0].fileKey;
|
|
}
|