Skip to content

Commit d43b463

Browse files
committed
Fix LGTM errors
1 parent 66dc40e commit d43b463

File tree

1 file changed

+33
-41
lines changed

1 file changed

+33
-41
lines changed

src/app/components/elements/FastTrackProgress.tsx

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,11 @@ interface ConceptLevelQuestions {
3232
lowerLevelQuestions: GameboardItem[];
3333
}
3434

35-
function categoriseConceptQuestions(conceptQuestions: GameboardItem[]): ConceptLevelQuestions | null {
36-
let result = null;
37-
if (conceptQuestions !== null) {
38-
result = {
39-
upperLevelQuestions: conceptQuestions.filter(question => getFastTrackLevel(question.tags) === 'ft_upper'),
40-
lowerLevelQuestions: conceptQuestions.filter(question => getFastTrackLevel(question.tags) === 'ft_lower'),
41-
};
42-
}
43-
return result;
35+
function categoriseConceptQuestions(conceptQuestions: GameboardItem[]): ConceptLevelQuestions {
36+
return {
37+
upperLevelQuestions: conceptQuestions.filter(question => getFastTrackLevel(question.tags) === 'ft_upper'),
38+
lowerLevelQuestions: conceptQuestions.filter(question => getFastTrackLevel(question.tags) === 'ft_lower'),
39+
};
4440
}
4541

4642
interface AugmentedQuestion {
@@ -100,8 +96,8 @@ function generateHexagonPoints(halfWidth: number, quarterHeight: number) {
10096
}
10197

10298

103-
export function FastTrackProgress({doc, search}: { doc: IsaacFastTrackQuestionPageDTO; search: string }) {
104-
const {questionHistory: qhs}: { questionHistory?: string } = queryString.parse(search);
99+
export function FastTrackProgress({doc, search}: {doc: IsaacFastTrackQuestionPageDTO; search: string}) {
100+
const {questionHistory: qhs}: {questionHistory?: string} = queryString.parse(search);
105101
const questionHistory = qhs ? qhs.split(",") : [];
106102

107103
const dispatch = useDispatch();
@@ -118,9 +114,10 @@ export function FastTrackProgress({doc, search}: { doc: IsaacFastTrackQuestionPa
118114
const hexagonQuarterHeight = hexagonUnitLength / Math.sqrt(3);
119115
const progressBarPadding = deviceSize !== 'xs' ? 5 : 1;
120116

121-
const conceptQuestions = gameboardMaybeNull && fasttrackConcepts && fasttrackConcepts.gameboardId === gameboardMaybeNull.id && fasttrackConcepts.concept === doc.title ?
122-
fasttrackConcepts.items
123-
: null;
117+
const conceptQuestions =
118+
gameboardMaybeNull && fasttrackConcepts && fasttrackConcepts.gameboardId === gameboardMaybeNull.id && fasttrackConcepts.concept === doc.title ?
119+
fasttrackConcepts.items
120+
: null;
124121

125122
useEffect(() => {
126123
if (conceptQuestions === null && gameboardMaybeNull) {
@@ -245,9 +242,6 @@ export function FastTrackProgress({doc, search}: { doc: IsaacFastTrackQuestionPa
245242
}
246243

247244
function orderConceptQuestionsById(unorderedConceptQuestions: ConceptLevelQuestions) {
248-
if (unorderedConceptQuestions === null) {
249-
throw new Error("No unoderedConceptQuestions");
250-
}
251245
let result: ConceptLevelQuestions = {upperLevelQuestions: [], lowerLevelQuestions: []};
252246
for (let conceptLevelName of conceptLevels) {
253247
result[conceptLevelName] = unorderedConceptQuestions[conceptLevelName].slice().sort((a: { id?: string }, b: { id?: string }) => a.id === b.id ? 0 : (a.id === undefined || (b.id !== undefined && a.id > b.id)) ? 1 : -1);
@@ -393,7 +387,7 @@ export function FastTrackProgress({doc, search}: { doc: IsaacFastTrackQuestionPa
393387
}
394388
result += line(sourceHexagonX + hexagon.x.center, hexagon.y.center);
395389

396-
// Horrizontal connection
390+
// Horizontal connection
397391
if (Math.abs(sourceIndex - targetIndex) > 1) {
398392
result += line(targetHexagonX + hexagon.x.center, hexagon.y.center);
399393
}
@@ -409,16 +403,18 @@ export function FastTrackProgress({doc, search}: { doc: IsaacFastTrackQuestionPa
409403
}
410404

411405
function createQuestionHexagon(question: AugmentedQuestion) {
412-
let fillColour = 'none';
413-
if (question.isCompleted) {
414-
fillColour = question.isCurrentQuestion ? hexagon.base.fill.completedColour : hexagon.base.fill.deselectedCompletedColour;
415-
} else {
416-
fillColour = question.isCurrentQuestion ? hexagon.base.fill.selectedColour : hexagon.base.fill.deselectedColour;
417-
}
406+
const fillColour = (question.isCompleted) ?
407+
question.isCurrentQuestion ? hexagon.base.fill.completedColour : hexagon.base.fill.deselectedCompletedColour :
408+
question.isCurrentQuestion ? hexagon.base.fill.selectedColour : hexagon.base.fill.deselectedColour;
418409

419410
return <Link to={question.href}>
420411
<title>{question.title + (question.isCurrentQuestion ? ' (Current)' : '')}</title>
421-
{generateHexagon([true], allVisible => allVisible === true, hexagon.base, fillColour, true)}
412+
{generateHexagon(
413+
[true],
414+
allVisible => allVisible,
415+
hexagon.base,
416+
fillColour,
417+
true)}
422418

423419
{generateHexagon(
424420
question.questionPartStates,
@@ -427,8 +423,9 @@ export function FastTrackProgress({doc, search}: { doc: IsaacFastTrackQuestionPa
427423
'none',
428424
false)}
429425

430-
{question.isCompleted ? generateCompletionTick(question.isCurrentQuestion)
431-
: generateHexagonTitle(question.hexagonTitle, question.isCurrentQuestion)}
426+
{question.isCompleted ?
427+
generateCompletionTick(question.isCurrentQuestion) :
428+
generateHexagonTitle(question.hexagonTitle, question.isCurrentQuestion)}
432429
</Link>;
433430
}
434431

@@ -480,22 +477,17 @@ export function FastTrackProgress({doc, search}: { doc: IsaacFastTrackQuestionPa
480477
<svg id="ft-progress" width="100%" height={progressBarHeight}>
481478
<g id="progress-bar-padding" transform={`translate(${progressBarPadding}, ${progressBarPadding})`}>
482479
<g id="concept-connections">
483-
{progress.connections.topTenToUpper.length > 0 &&
484-
createConceptConnectionRow(progress.connections.topTenToUpper, 'top-ten-to-upper', 0)
485-
}
486-
{progress.connections.upperToLower.length > 0 &&
487-
createConceptConnectionRow(progress.connections.upperToLower, 'upper-to-lower', 1)
488-
}
489-
480+
{progress.connections.topTenToUpper.length &&
481+
createConceptConnectionRow(progress.connections.topTenToUpper, 'top-ten-to-upper', 0)}
482+
{progress.connections.upperToLower.length &&
483+
createConceptConnectionRow(progress.connections.upperToLower, 'upper-to-lower', 1)}
490484
</g>
491485
<g id="question-hexagons">
492486
{createQuestionRow(progress.questions.topTen, 'top_ten', 0)}
493-
{progress.questions.upper.length > 0 &&
494-
createQuestionRow(progress.questions.upper, 'upper', 1)
495-
}
496-
{progress.questions.lower.length > 0 &&
497-
createQuestionRow(progress.questions.lower, 'lower', 2)
498-
}
487+
{progress.questions.upper.length &&
488+
createQuestionRow(progress.questions.upper, 'upper', 1)}
489+
{progress.questions.lower.length &&
490+
createQuestionRow(progress.questions.lower, 'lower', 2)}
499491
</g>
500492
</g>
501493
</svg>
@@ -512,4 +504,4 @@ export function FastTrackProgress({doc, search}: { doc: IsaacFastTrackQuestionPa
512504
if (!categorisedConceptQuestions) return null;
513505
const progress = evaluateProgress(categorisedConceptQuestions, questionHistory);
514506
return renderProgress(progress);
515-
}
507+
}

0 commit comments

Comments
 (0)