-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creating shared component for displaying number of hints used per str…
…ategy
- Loading branch information
1 parent
1aafd50
commit c0443c2
Showing
3 changed files
with
55 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import Statistic from "./Statistics/Statistic"; | ||
import { formatOneLessonName } from "../Functions/learnedLessons"; | ||
import React from "react"; | ||
import { SudokuStrategy } from "sudokuru"; | ||
|
||
interface NumHintsUsedPerStrategyProps { | ||
numHintsUsedPerStrategy: { | ||
hintStrategy: SudokuStrategy; | ||
numHintsUsed: number; | ||
}[]; | ||
} | ||
|
||
/** | ||
* Renders a list of JSX Statistic components displaying the number of hints used per strategy. | ||
* | ||
* @param numHintsUsedPerStrategy - Array of objects detailing hints used for each strategy, | ||
* sorted by most hints used. | ||
* @returns An array of JSX elements representing the number of hints used per strategy. | ||
*/ | ||
export const NumHintsUsedPerStrategy = ( | ||
props: NumHintsUsedPerStrategyProps | ||
) => { | ||
// sort by most number of hints | ||
const numHintsUsedPerStrategyClone = [...props.numHintsUsedPerStrategy].sort( | ||
(a, b) => { | ||
return b.numHintsUsed - a.numHintsUsed; | ||
} | ||
); | ||
|
||
// Generates the JSX elements for the number of hints used per strategy | ||
const strategyHints: React.JSX.Element[] = []; | ||
for (const strategyHint of numHintsUsedPerStrategyClone) { | ||
strategyHints.push( | ||
<Statistic | ||
statisticName={ | ||
" " + formatOneLessonName(strategyHint.hintStrategy) + ": " | ||
} | ||
statisticValue={strategyHint.numHintsUsed} | ||
testID={"hintsUsed" + strategyHint.hintStrategy} | ||
key={strategyHint.hintStrategy} | ||
/> | ||
); | ||
} | ||
|
||
return strategyHints; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters