Hiding the restart with wrongs button when there are no wrongs and made the info element react to the actual number of questions

master
Wynd 2025-06-18 16:18:55 +03:00
parent 92983da8fa
commit 7a847905d7
2 changed files with 14 additions and 6 deletions

View File

@ -88,6 +88,8 @@ fn get_rand_questions() -> Questions {
// Randomize the questions list
questions.shuffle(&mut rng);
questions.count = questions.questions.len();
questions
}
@ -145,6 +147,7 @@ fn App() -> Element {
let wrongs = questions_lock.wrong_questions.to_vec();
questions_lock.count = wrongs.len();
questions_lock.questions = wrongs;
questions_lock.wrong_questions.clear();
@ -379,7 +382,7 @@ pub fn Info(
correct_questions: Signal<i32>,
wrong_questions: Signal<i32>,
) -> Element {
let total_questions = get_questions().len();
let total_questions = questions().count;
let current_question = use_memo(move || questions().len());
let left_questions = use_memo(move || total_questions - current_question());
@ -430,11 +433,13 @@ pub fn Report(
},
"Restart"
},
button {
onclick: move |_| {
phase.set(Phase::RestartWrongs);
},
"Restart with only wrong questions"
if wrong_questions > 0 {
button {
onclick: move |_| {
phase.set(Phase::RestartWrongs);
},
"Restart with only wrong questions"
}
}
}
}

View File

@ -17,6 +17,9 @@ pub struct Questions {
#[serde(default, skip)]
pub wrong_questions: Vec<Question>,
#[serde(default, skip)]
pub count: usize,
}
impl AddAssign for Questions {