* feat: dispatch resetChallenge action * fix: copy challengeFiles instead of in-place sort * fix: handle null updateFile payloads in redux * refactor: reorganise region initialization * refactor: pull code into editorDidMount Then we can rely on the presence of the editor and monaco and don't have litter the code with null checks. * refactor: use better name for editable region init * refactor: remove unused decoration * refactor: rename forbidden region init functions * fix: keep all challengeFiles when resetting * refactor: remove unused decoration class * fix: reinitialize editor on reset * fix: stop adding multiple scroll listeners Since the challengeFile update on each keystroke extra (unnecessary) adding of listeners slowed the editor to a crawl. * fix: only scroll to editor on mount Rather than on any edit. * refactor: remove logs and comments * fix: rename toSortedArray and fix broken test * fix: check for null not falsy in updateFile * fix: only update project features when project * fix: only reset if editor contents have changed * feat: focus on editor after reset
18 lines
546 B
JavaScript
18 lines
546 B
JavaScript
exports.sortChallengeFiles = function sortChallengeFiles(challengeFiles) {
|
|
const xs = challengeFiles.slice();
|
|
// TODO: refactor this to use an ext array ['html', 'js', 'css'] and loop over
|
|
// that.
|
|
xs.sort((a, b) => {
|
|
if (a.ext === 'html') return -1;
|
|
if (b.ext === 'html') return 1;
|
|
if (a.ext === 'css') return -1;
|
|
if (b.ext === 'css') return 1;
|
|
if (a.ext === 'jsx') return -1;
|
|
if (b.ext === 'jsx') return 1;
|
|
if (a.ext === 'js') return -1;
|
|
if (b.ext === 'js') return 1;
|
|
return 0;
|
|
});
|
|
return xs;
|
|
};
|