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

View File

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