-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQuestionMetadata.tsx
53 lines (52 loc) · 1.34 KB
/
QuestionMetadata.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { EXIT_TILE_ID, HINT_TILE_ID } from "../constants";
import * as styles from "./QuestionMetadata.module.scss";
export const QuestionMetadata = ({
category,
difficulty,
hints,
seenQuestions,
selectedTileId,
solved,
}: {
category: string;
difficulty: number;
hints: number;
seenQuestions: number[];
selectedTileId: any;
solved: boolean;
}) => {
const h = Math.floor(hints);
const hintsMessage = `You have ${h} ${h === 1 ? "hint" : "hints"} left.`;
let children;
if (solved) {
children = `Question #${seenQuestions.length} solved! ${hintsMessage}`;
} else {
switch (selectedTileId) {
case EXIT_TILE_ID: {
children =
"Thanks for playing! " +
`Question #${seenQuestions.length} will be saved.`;
break;
}
case HINT_TILE_ID: {
children = h ? `${hintsMessage} Use one?` : "You have no hints left!";
break;
}
default: {
children = [
<span key={0} className={styles.bold}>
{category}
</span>,
<span key={1} className={styles.for}>
for
</span>,
<span key={2} className={styles.bold}>
${difficulty}
</span>,
];
break;
}
}
}
return <p className={styles["question-metadata"]}>{children}</p>;
};