diff --git a/src/main.rs b/src/main.rs index 307a6a6..0c07c60 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, wrong_questions: Signal, ) -> 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" + } } } } diff --git a/src/models.rs b/src/models.rs index 5bec4aa..246774d 100644 --- a/src/models.rs +++ b/src/models.rs @@ -17,6 +17,9 @@ pub struct Questions { #[serde(default, skip)] pub wrong_questions: Vec, + + #[serde(default, skip)] + pub count: usize, } impl AddAssign for Questions {