Skip to content

Commit

Permalink
Question rating
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyEye-FAST committed Jul 23, 2024
1 parent 55444be commit 9ae30d2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
28 changes: 27 additions & 1 deletion static/js/quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ $(document).ready(() => {
const $sourceText = $("#sourceText");
const $keyText = $("#keyText");
const $questionRatingNum = $("#questionRatingNum");
const $questionRating = $("#questionRating");
const $inputBox = $("#inputBox");
const $boxes = $("#boxes");
const $buttons = $("#buttons");
Expand Down Expand Up @@ -99,6 +100,28 @@ $(document).ready(() => {
});
};

const updateRatingStars = (rating) => {
$questionRating.empty()
const fullStars = Math.floor(rating);
const hasHalfStar = rating % 1 > 0;

for (let i = 0; i < fullStars; i++) {
$questionRating.append(
$('<span class="material-symbols-outlined b">').text("star")
);
}

if (hasHalfStar) {
$questionRating.append(
$('<span class="material-symbols-outlined b">').text(
"star_half"
)
);
}

$("#questionRatingNum").text(rating);
};

const initializeQuestion = async () => {
const currentKey = questionKeys[currentQuestionIndex];
questionScore = 10;
Expand All @@ -114,7 +137,10 @@ $(document).ready(() => {

$sourceText.text(source);
$keyText.text(currentKey);
if (rating !== undefined) $questionRatingNum.text(rating);
if (rating !== undefined) {
$questionRatingNum.text(rating);
updateRatingStars(rating);
}
$inputBox.val("");
createBoxes(translationSegments.length);

Expand Down
4 changes: 2 additions & 2 deletions templates/quiz_sub.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
<div class="info">
<div id="sourceText" class="source"></div>
<div id="keyText" class="key"></div>
<div id="questionRating" class="key">
<span class="material-symbols-outlined b">star</span>
<div class="key">
<span id="questionRating"></span>
<span id="questionRatingNum"></span>
</div>
</div>
Expand Down

0 comments on commit 9ae30d2

Please sign in to comment.