Hiding the restart with wrongs button when there are no wrongs and made the info element react to the actual number of questions
parent
92983da8fa
commit
7a847905d7
|
@ -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,6 +433,7 @@ pub fn Report(
|
|||
},
|
||||
"Restart"
|
||||
},
|
||||
if wrong_questions > 0 {
|
||||
button {
|
||||
onclick: move |_| {
|
||||
phase.set(Phase::RestartWrongs);
|
||||
|
@ -440,3 +444,4 @@ pub fn Report(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue